Skip to content

Commit

Permalink
Begone, METTLE_EXPECT!
Browse files Browse the repository at this point in the history
  • Loading branch information
jimporter committed Aug 2, 2024
1 parent 264a0c0 commit 4b15d59
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 89 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
### Breaking changes
- Implementation updated to require C++20
- `make_matcher` helper has been removed; use `basic_matcher` directly instead
- `METTLE_EXPECT` macro has been removed; use `expect` instead

---

Expand Down
1 change: 1 addition & 0 deletions doc/about/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ in progress
### Breaking changes
- Implementation updated to require C++20
- `make_matcher` helper has been removed; use `basic_matcher` directly instead
- `METTLE_EXPECT` macro has been removed; use `expect` instead

---

Expand Down
9 changes: 0 additions & 9 deletions doc/expectations.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ expected: 666
actual: 123
```

!!! note
Currently, only GCC supports getting the filename and line number
automatically for an expectation. However, as compilers add support for
`std::experimental::source_location`, mettle will automatically switch to
showing these values. However, in the meantime you can use the
`METTLE_EXPECT` macro in place of `mettle::expect` if you need to see the
filename and line number.


## Printing objects

In the examples above, the error output shows the expected and actual values.
Expand Down
13 changes: 0 additions & 13 deletions include/mettle/matchers/expect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@
#include "result.hpp"
#include "../detail/source_location.hpp"

#ifndef METTLE_NO_MACROS
# ifdef METTLE_NO_SOURCE_LOCATION
# define METTLE_EXPECT(...) ::mettle::expect( \
__VA_ARGS__, \
::mettle::detail::source_location::current( \
__FILE__, __func__, __LINE__ \
) \
)
# else
# define METTLE_EXPECT(...) ::mettle::expect(__VA_ARGS__)
# endif
#endif

namespace mettle {

class expectation_error : public std::runtime_error {
Expand Down
67 changes: 0 additions & 67 deletions test/matchers/test_expect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,71 +52,4 @@ suite<> test_expect("expect()", [](auto &_) {
ss << "\nexpected: true\nactual: false";
expect(message, equal_to(ss.str()));
});

_.test("METTLE_EXPECT(value, matcher)", []() {
std::string message;
int line = __LINE__ + 2; // The line the expectation is on.
try {
METTLE_EXPECT(false, equal_to(true));
} catch(const expectation_error &e) {
message = e.what();
}

std::ostringstream ss;
ss << __FILE__ << ":" << line << "\nexpected: true\nactual: false";
expect(message, equal_to(ss.str()));
});

_.test("expect(value, matcher) with non-const", []() {
expect(thing(), thing_value(1));
});

_.test("expect(desc, value, matcher) with non-const", []() {
expect("description", thing(), thing_value(1));
});

_.test("METTLE_EXPECT(value, matcher)", []() {
std::string message;
int line = __LINE__ + 2; // The line the expectation is on.
try {
METTLE_EXPECT(false, equal_to(true));
} catch(const expectation_error &e) {
message = e.what();
}

std::ostringstream ss;
ss << __FILE__ << ":" << line << "\nexpected: true\nactual: false";
expect(message, equal_to(ss.str()));
});

_.test("METTLE_EXPECT(desc, value, matcher)", []() {
std::string message;
int line = __LINE__ + 2; // The line the expectation is on.
try {
METTLE_EXPECT("description", false, equal_to(true));
} catch(const expectation_error &e) {
message = e.what();
}

std::ostringstream ss;
ss << "description (" << __FILE__ << ":" << line
<< ")\nexpected: true\nactual: false";
expect(message, equal_to(ss.str()));
});

// This test ensures that we correctly resolve the call to mettle::expect,
// since one of the overloads takes a string description as the first arg.
_.test("METTLE_EXPECT(string, matcher)", []() {
std::string message;
int line = __LINE__ + 2; // The line the expectation is on.
try {
METTLE_EXPECT(std::string("foo"), equal_to(std::string("bar")));
} catch(const expectation_error &e) {
message = e.what();
}

std::ostringstream ss;
ss << __FILE__ << ":" << line << "\nexpected: \"bar\"\nactual: \"foo\"";
expect(message, equal_to(ss.str()));
});
});

0 comments on commit 4b15d59

Please sign in to comment.