|
7 | 7 | #include <gtest/gtest.h>
|
8 | 8 | #include <quick-lint-js/file.h>
|
9 | 9 |
|
10 |
| -#define EXPECT_SAME_FILE(path_a, path_b) \ |
11 |
| - do { \ |
12 |
| - ::quick_lint_js::canonical_path_result path_a_canonical_ = \ |
13 |
| - ::quick_lint_js::canonicalize_path((path_a)); \ |
14 |
| - ASSERT_TRUE(path_a_canonical_.ok()) \ |
15 |
| - << std::move(path_a_canonical_).error(); \ |
16 |
| - ::quick_lint_js::canonical_path_result path_b_canonical_ = \ |
17 |
| - ::quick_lint_js::canonicalize_path((path_b)); \ |
18 |
| - ASSERT_TRUE(path_b_canonical_.ok()) \ |
19 |
| - << std::move(path_b_canonical_).error(); \ |
20 |
| - EXPECT_EQ(path_a_canonical_.path(), path_b_canonical_.path()) \ |
21 |
| - << (path_a) << " should be the same file as " << (path_b); \ |
22 |
| - } while (false) |
| 10 | +#define EXPECT_SAME_FILE(path_a, path_b) \ |
| 11 | + EXPECT_PRED_FORMAT2(::quick_lint_js::assert_same_file, path_a, path_b) |
| 12 | + |
| 13 | +namespace quick_lint_js { |
| 14 | +template <class String> |
| 15 | +::testing::AssertionResult assert_same_file(const char *lhs_expr, |
| 16 | + const char *rhs_expr, |
| 17 | + String lhs_path, String rhs_path) { |
| 18 | + canonical_path_result lhs_canonical = canonicalize_path(lhs_path); |
| 19 | + EXPECT_TRUE(lhs_canonical.ok()) << std::move(lhs_canonical).error(); |
| 20 | + canonical_path_result rhs_canonical = canonicalize_path(rhs_path); |
| 21 | + EXPECT_TRUE(rhs_canonical.ok()) << std::move(rhs_canonical).error(); |
| 22 | + if (lhs_canonical.path() == rhs_canonical.path()) { |
| 23 | + return ::testing::AssertionSuccess(); |
| 24 | + } else { |
| 25 | + return ::testing::AssertionFailure() |
| 26 | + << lhs_expr << " (" << lhs_path << ") is not the same file as " |
| 27 | + << rhs_expr << " (" << rhs_path << ')'; |
| 28 | + } |
| 29 | +} |
| 30 | +} |
23 | 31 |
|
24 | 32 | #endif
|
25 | 33 |
|
|
0 commit comments