Skip to content

Commit fa88cfa

Browse files
committed
Factor EXPECT_SAME_FILE into separate module
I want to use EXPECT_SAME_FILE from multiple test files. Move this macro into its own file.
1 parent 405b401 commit fa88cfa

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ quick_lint_js_add_executable(
1414
quick-lint-js/array.h
1515
quick-lint-js/characters.h
1616
quick-lint-js/error-matcher.h
17+
quick-lint-js/file-matcher.h
1718
quick-lint-js/gtest.h
1819
quick-lint-js/parse-json.h
1920
quick-lint-js/parse-support.h

test/quick-lint-js/file-matcher.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (C) 2020 Matthew Glazar
2+
// See end of file for extended copyright information.
3+
4+
#ifndef QUICK_LINT_JS_FILE_MATCHER_H
5+
#define QUICK_LINT_JS_FILE_MATCHER_H
6+
7+
#include <gtest/gtest.h>
8+
#include <quick-lint-js/file.h>
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)
23+
24+
#endif
25+
26+
// quick-lint-js finds bugs in JavaScript programs.
27+
// Copyright (C) 2020 Matthew Glazar
28+
//
29+
// This file is part of quick-lint-js.
30+
//
31+
// quick-lint-js is free software: you can redistribute it and/or modify
32+
// it under the terms of the GNU General Public License as published by
33+
// the Free Software Foundation, either version 3 of the License, or
34+
// (at your option) any later version.
35+
//
36+
// quick-lint-js is distributed in the hope that it will be useful,
37+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
38+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39+
// GNU General Public License for more details.
40+
//
41+
// You should have received a copy of the GNU General Public License
42+
// along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

test/test-configuration-loader.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <gtest/gtest.h>
99
#include <quick-lint-js/configuration-loader.h>
1010
#include <quick-lint-js/configuration.h>
11+
#include <quick-lint-js/file-matcher.h>
1112
#include <quick-lint-js/file.h>
1213
#include <quick-lint-js/options.h>
1314
#include <quick-lint-js/temporary-directory.h>
@@ -30,18 +31,6 @@ QLJS_WARNING_IGNORE_GCC("-Wmissing-field-initializers")
3031
EXPECT_FALSE((config).globals().find(u8"variableDoesNotExist"sv)); \
3132
} while (false)
3233

33-
#define EXPECT_SAME_FILE(path_a, path_b) \
34-
do { \
35-
canonical_path_result path_a_canonical_ = canonicalize_path((path_a)); \
36-
ASSERT_TRUE(path_a_canonical_.ok()) \
37-
<< std::move(path_a_canonical_).error(); \
38-
canonical_path_result path_b_canonical_ = canonicalize_path((path_b)); \
39-
ASSERT_TRUE(path_b_canonical_.ok()) \
40-
<< std::move(path_b_canonical_).error(); \
41-
EXPECT_EQ(path_a_canonical_.path(), path_b_canonical_.path()) \
42-
<< (path_a) << " should be the same file as " << (path_b); \
43-
} while (false)
44-
4534
using ::testing::AnyOf;
4635
using ::testing::HasSubstr;
4736
using namespace std::literals::string_view_literals;

0 commit comments

Comments
 (0)