Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Aug 14, 2022
1 parent 274f114 commit 517627b
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,10 @@ namespace libassert::detail {
return type;
}

// forward declaration so this can be used in some printbugging
LIBASSERT_ATTR_COLD
std::string highlight(const std::string& expression);

class analysis {
enum class token_e {
keyword,
Expand Down Expand Up @@ -1587,8 +1591,9 @@ namespace libassert::detail {
std::vector<std::string> right_strings;
for(size_t i = 0; i < m; i++) left_strings.push_back(tokens[i].str);
for(size_t i = m + 1; i < tokens.size(); i++) right_strings.push_back(tokens[i].str);
fprintf(stderr, "left: %s\n", highlight(std::string(trim(join(left_strings, "")))).c_str());
fprintf(stderr, "right: %s\n", highlight(std::string(trim(join(right_strings, "")))).c_str());
fprintf(stderr, "left: %s\n", libassert::detail::highlight(std::string(trim(join(left_strings, "")))).c_str());
fprintf(stderr, "right: %s\n", libassert::detail::highlight(std::string(trim(join(right_strings, "")))).c_str());
fprintf(stderr, "target_op: %s\n", target_op.data()); // should be null terminated
fprintf(stderr, "---\n");
}
#endif
Expand All @@ -1599,7 +1604,8 @@ namespace libassert::detail {
for(size_t i = 0; i < m; i++) {
left_strings.push_back(tokens[i].str);
}
for(size_t i = m + 1; i < tokens.size(); i++) {
// >> is decomposed and requires special handling (m will be the index of the first > token)
for(size_t i = m + 1 + (target_op == ">>" ? 1 : 0); i < tokens.size(); i++) {
right_strings.push_back(tokens[i].str);
}
return {
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/expected/clang.txt
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,20 @@ Stack trace:
at integration.cpp:402


Assertion failed at integration/integration.cpp:2116: void test_class<int>::something_else() [T = int]:
assert(a >> 1);
Where:
a => 1

Stack trace:
# 1 test_class<int>::something_else()
at integration.cpp:2116
# 2 void test_class<int>::something<N>(std::pair<N, int>)
at integration.cpp:1004
# 3 main
at integration.cpp:402


===================== [ensure values are only computed once] =====================
foo() called
bar() called
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/expected/clang_windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,20 @@ Stack trace:
at integration.cpp:403


Assertion failed at integration/integration.cpp:2116: void test_class<int>::something_else() [T = int]:
assert(a >> 1);
Where:
a => 1

Stack trace:
# 1 test_class<int>::something_else()
at integration.cpp:2116
# 2 test_class<int>::something<N>(std::pair<N, int>)
at integration.cpp:1005
# 3 main()
at integration.cpp:403


===================== [ensure values are only computed once] =====================
foo() called
bar() called
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/expected/gcc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,20 @@ Stack trace:
at integration.cpp:403


Assertion failed at integration/integration.cpp:2116: void test_class<T>::something_else() [with T = int]:
assert(a >> 1);
Where:
a => 1

Stack trace:
# 1 test_class<int>::something_else()
at integration.cpp:2116
# 2 void test_class<int>::something<N>(std::pair<N, int>)
at integration.cpp:1005
# 3 main
at integration.cpp:403


===================== [ensure values are only computed once] =====================
bar() called
foo() called
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/expected/gcc_windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,20 @@ Stack trace:
at integration.cpp:403


Assertion failed at integration/integration.cpp:2116: void test_class<T>::something_else() [with T = int]:
assert(a >> 1);
Where:
a => 1

Stack trace:
# 1 test_class<int>::something_else()
at integration.cpp:2116
# 2 void test_class<int>::something<N>(std::pair<N, int>)
at integration.cpp:1005
# 3 main
at integration.cpp:403


===================== [ensure values are only computed once] =====================
bar() called
foo() called
Expand Down
16 changes: 15 additions & 1 deletion tests/integration/expected/msvc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,21 @@ Assertion failed at integration/integration.cpp:2114: void __cdecl test_class<in

Stack trace:
# 1 test_class<int>::something_else()
at integration.cpp:2117
at integration.cpp:2115
# 2 test_class<int>::something<N>(std::pair<N, int>)
at integration.cpp:1005
# 3 main()
at integration.cpp:403


Assertion failed at integration/integration.cpp:2116: void __cdecl test_class<int>::something_else(void):
assert(a >> 1);
Where:
a => 1

Stack trace:
# 1 test_class<int>::something_else()
at integration.cpp:2119
# 2 test_class<int>::something<N>(std::pair<N, int>)
at integration.cpp:1005
# 3 main()
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ class test_class {
x = 2;
assert(x -= x -= x -= 1); // TODO: double check....
assert(true ? false : true, "pffft"); // NOLINT(readability-simplify-boolean-expr)
int a = 1; // regression test for #26
assert(a >> 1);
}
// ensure values are only computed once
SECTION("ensure values are only computed once");
Expand Down

0 comments on commit 517627b

Please sign in to comment.