Can googletest stringification produce a hexadecimal format? - c++

I'm using Google Test to assert that certain error codes occur, and these are always hex constants. So this output is less than ideal:
mytest.cpp line 130 and its output:
EXPECT_EQ(0xBFFF0011, error) << "Expected second close to return an error";
[ RUN ] MyTest.CloseSessionFail
mytest.cpp(130): error: Value of: error
Actual: -1074130544
Expected: 0xBFFF0011
Which is: 3221159953
Expected second close to return an error
For EXPECT_EQ(expected, actual), is there some way to cause it to format hexadecimal output?
Ideally I'd like to see this:
Actual: 0xBFFA1190
Expected: 0xBFFF0011

Probably this message will help you:
https://github.com/google/googletest/issues/222

Related

Compilation error in nested casting inside a rule in drools

I am using the # operator, and while with one casting it works fine, having two in the same rule it does not compile. The sentence is the following
configuration#RuleSetConfiguration.configurationRule[0].configurationRuleAction#FilteringAction.filteringActionType==$mspl1.configuration#RuleSetConfiguration.configurationRule[0].configurationRuleAction#FilteringAction
And it returns the following compilation error:
[ERR 102] Line 62:87 mismatched input '#' in rule "verify_same_filtering_l4_behaviour" [Message [id=1, kieBase=rules, level=ERROR, path=/home/santiago/eclipse-workspace/DroolKieServer/target/classes/com/sample/rules/Rule.drl, line=62, column=0 text=[ERR 102] Line 62:87 mismatched input '#' in rule "verify_same_filtering_l4_behaviour"], Message [id=2, kieBase=rules, level=ERROR, path=/home/santiago/eclipse-workspace/DroolKieServer/target/classes/com/sample/rules/Rule.drl, line=0, column=0 text=Parser returned a null Package]]
I have tried to use brackets but the result is the same. Is there a limitation on the castings that can be done over a rule?
Greetings
I tried to do two castings in the rule. The expected result is to compile fine due to the use of the # operator is correct, but it returns the compilation error
`
[Message [id=1, kieBase=rules, level=ERROR, path=/home/santiago/eclipse-workspace/DroolKieServer/target/classes/com/sample/rules/Rule.drl, line=62, column=0
text=[ERR 102] Line 62:87 mismatched input '#' in rule "verify_same_filtering_l4_behaviour"], Message [id=2, kieBase=rules, level=ERROR, path=/home/santiago/eclipse-workspace/DroolKieServer/target/classes/com/sample/rules/Rule.drl, line=0, column=0
text=Parser returned a null Package]]
`
The problem was about using the # operator after a list. Instead of that, the standard Java casting have being used and it works fine:
((FilteringAction)((RuleSetConfiguration)configuration).configurationRule[0].configurationRuleAction)

awk print lines before while match INFO untill match ERROR

I want to print lines before my /ERROR/ match. The lines to be printed should be all containing INFO untill the previous ERROR is found.
So If I had a file
ERROR this is an error
INFO error found on line 2
INFO error is due to something
ERROR this is another error
I want the /ERROR/ from ERROR this is another error to print
INFO error found on line 2
INFO error is due to something
ERROR this is another error
Anyone know?
Part of my current script:
/CRITICAL/ {
print "\x1b[93;1m"
}
/ERROR/ {
print "\x1b[37m"
}
/ERROR|EMERGENCY|CRITICAL/ {
if (NR == n+1) print "";
n = NR;
print x;print
print "\x1b[0m"
};{x=$0}'
Try this one liner:
awk 'x;/ERROR/{x=1}' file
Out:
INFO error found on line 2
INFO error is due to something
ERROR this is another error
Long version:
x;/ERROR/{
x1=1;
print
}
If "ERROR" is found x=1, if x is true we've already gone through that line, then we print until we pass that line again.
Or maybe this, I don't have very clear what output you need.
awk '/ERROR/{x=1;next}/ERROR/{x=1}x'
Out
INFO error found on line 2
INFO error is due to something

Program argument with space characters is broken by Eclipse when running the debugger

I have a program which needs seven arguments.
The problem is that the fifth argument has empty (space) characters.
So I put it in the double quotes and the program runs.
The problem:
When I try to use the debugger inside the Eclipse the system put \” instead of “ . The result is the fifth argument is broken and I cannot use the debugger...
Here is what I have in the argument list
168815 blabla/ product_group_and_eshop_global_id blaee/test/test "<unique_string>products in the</unique_string><TotalNumberUniquestring>2</TotalNumberUniquestring><currentNumberUniquestring>1</currentNumberUniquestring><div_OR_table_navigatin_instructions><divORTableForward_skip>1</divORTableForward_skip> <divForward_in>1</divForward_in></div_OR_table_navigatin_instructions><type_of_product_substring>SEARCH</type_of_product_substring><where_to_search_the_name>title</where_to_search_the_name><currency>$</currency><price_extraction_start_Key>$</price_extraction_start_Key><price_extraction_end_Key>&lt</price_extraction_end_Key>" filename_mode
/src/cpp/test-pages/FrontLoad.html
And here's what the Eclipse print in the console
/bin/bash: -c: line 0: syntax error near unexpected token `<'
/bin/bash: -c: line 0: `exec /media/Debug/gcom_au 168815 blabla/ product_group_and_eshop_global_id blaee/test/test \"<unique_string>products in the</unique_string><TotalNumberUniquestring>2</TotalNumberUniquestring><currentNumberUniquestring>1</currentNumberUniquestring><div_OR_table_navigatin_instructions><divORTableForward_skip>1</divORTableForward_skip> <divForward_in>1</divForward_in></div_OR_table_navigatin_instructions><type_of_product_substring>SEARCH</type_of_product_substring><where_to_search_the_name>title</where_to_search_the_name><currency>$</currency><price_extraction_start_Key>$</price_extraction_start_Key><price_extraction_end_Key>&lt</price_extraction_end_Key>\" filename_mode
/src/cpp/test-pages/FrontLoad.html'
I found the solution : I change the “ to '
So. the
168815 blabla/ product_group_and_eshop_global_id blaee/test/test "<unique_string>products in the</unique_string><TotalNumberUniquestring>2</TotalNumberUniquestring><currentNumberUniquestring>1</currentNumberUniquestring><div_OR_table_navigatin_instructions><divORTableForward_skip>1</divORTableForward_skip> <divForward_in>1</divForward_in></div_OR_table_navigatin_instructions><type_of_product_substring>SEARCH</type_of_product_substring><where_to_search_the_name>title</where_to_search_the_name><currency>$</currency><price_extraction_start_Key>$</price_extraction_start_Key><price_extraction_end_Key>&lt</price_extraction_end_Key>" filename_mode /src/cpp/test-pages/FrontLoad.html
becomes
168815 blabla/ product_group_and_eshop_global_id blaee/test/test '<unique_string>products in the</unique_string><TotalNumberUniquestring>2</TotalNumberUniquestring><currentNumberUniquestring>1</currentNumberUniquestring><div_OR_table_navigatin_instructions><divORTableForward_skip>1</divORTableForward_skip> <divForward_in>1</divForward_in></div_OR_table_navigatin_instructions><type_of_product_substring>SEARCH</type_of_product_substring><where_to_search_the_name>title</where_to_search_the_name><currency>$</currency><price_extraction_start_Key>$</price_extraction_start_Key><price_extraction_end_Key>&lt</price_extraction_end_Key>' filename_mode /src/cpp/test-pages/FrontLoad.html

Function in if statement: error expected expression

I want to compile following file:
https://gist.github.com/bodokaiser/5382281
which does not succeed because I get following error:
CXX(target) Release/obj.target/parser/src/parser/parser.o
In file included from ../src/parser/parser.cc:2:
../src/parser/calc_head_size.cc:67:16: error: expected expression
if (mask || isMasking(masking)) {
^
1 error generated.
make: *** [Release/obj.target/parser/src/parser/parser.o] Error 1
This does not make sense to me. Can it be that there is something else wrong?
Bodo
You seem to have a strange character in your source code that looks like a space but isn't. In this line:
if (mask || isMasking(masking)) {
// ^ here
try to delete the "space" and add a real space.

Suppressing stack trace when Rails tests error

I'm a Ruby on Rails newbie and writing tests. Some of these generate exceptions; I would like the "rake test" output to give me the exception error message but not the whole backtrace. (I'd like to write tests which exercise unimplemented functionality, which I'll then fill in.)
For example, actual output:
Started
E
Finished in 0.081054 seconds.
1) Error:
test_should_fail(VersioningTest):
ActiveRecord::StatementInvalid: PGError: ERROR: null value in column "client_ip" violates not-null constraint
: INSERT INTO "revisions" ("created_at", "id") VALUES ('2011-02-03 20:14:17', 980190962)
/Users/rpriedhorsky/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:202:in `rescue in log'
/Users/rpriedhorsky/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:194:in `log'
/Users/rpriedhorsky/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:496:in `execute'
[... etc. etc. etc. ...]
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
Desired output:
Started
E
Finished in 0.081054 seconds.
1) Error:
test_should_fail(VersioningTest):
ActiveRecord::StatementInvalid: PGError: ERROR: null value in column "client_ip" violates not-null constraint
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
I found info (e.g.) on the opposite direction, but not on suppressing stack traces.
Edit:
It would be nice to turn them on and off easily; as pointed out below, sometimes they are useful for tracking down bugs.
You could take a look at "backtrace silencers" - for me (Rails 2.3.8), this is the file config/initializers/backtrace_silencers.rb:
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but
# don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying do debug a
# problem that might steem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
Rails.backtrace_cleaner.add_silencer {|line| line =~ /gems/}
Rails.backtrace_cleaner.add_silencer {|line| line =~ /passenger/}
It looks like you should be able to put a line like
Rails.backtrace_cleaner.add_silencer {|line| true}
In your config/environments/test.rb file, and that would wipe your backtraces clean away (though it might just apply to the logger - I'm not very familiar with the method).
But ask yourself - do you really want to do away with backtraces entirely? They can be pretty useful for tracking down bugs...