Skip to content

Commit 2723904

Browse files
committed
refactor: rename test-error -> test-diag-code
1 parent 5d58bea commit 2723904

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ quick_lint_js_add_executable(
3939
test-configuration.cpp
4040
test-crash.cpp
4141
test-diag-code-list.cpp
42+
test-diag-code.cpp
4243
test-diag-matcher.cpp
4344
test-diagnostic-formatter.cpp
4445
test-diagnostic.cpp
4546
test-document.cpp
4647
test-emacs-lisp-diag-reporter.cpp
4748
test-emacs-location.cpp
48-
test-error.cpp
4949
test-event-loop.cpp
5050
test-file-canonical.cpp
5151
test-file-path.cpp

test/test-error.cpp renamed to test/test-diag-code.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,59 @@
99

1010
namespace quick_lint_js {
1111
namespace {
12-
struct error_name_and_code {
12+
struct diag_name_and_code {
1313
const char* name;
1414
const char* code;
1515
};
16-
static constexpr error_name_and_code all_errors[] = {
17-
#define QLJS_DIAG_TYPE(error_name, error_code, severity, struct_body, format) \
18-
{.name = #error_name, .code = error_code},
16+
static constexpr diag_name_and_code all_diags[] = {
17+
#define QLJS_DIAG_TYPE(diag_name, diag_code, severity, struct_body, format) \
18+
{.name = #diag_name, .code = diag_code},
1919
QLJS_X_DIAG_TYPES
2020
#undef QLJS_DIAG_TYPE
2121
};
2222

23-
std::string next_unused_error_code() {
23+
std::string next_unused_diag_code() {
2424
for (int i = 1; i <= 9999; ++i) {
2525
char code[7];
2626
std::snprintf(code, sizeof(code), "E%04d", i);
2727
auto existing_it =
28-
std::find_if(std::begin(all_errors), std::end(all_errors),
29-
[&](const error_name_and_code& error) {
30-
return std::string_view(error.code) == code;
28+
std::find_if(std::begin(all_diags), std::end(all_diags),
29+
[&](const diag_name_and_code& diag) {
30+
return std::string_view(diag.code) == code;
3131
});
32-
if (existing_it == std::end(all_errors)) {
32+
if (existing_it == std::end(all_diags)) {
3333
return std::string(code);
3434
}
3535
}
3636
QLJS_UNIMPLEMENTED();
3737
}
3838

39-
TEST(test_error, error_codes_are_unique) {
40-
std::unordered_map<std::string, const char*> code_to_error_name;
41-
for (const error_name_and_code& error : all_errors) {
42-
auto existing_it = code_to_error_name.find(error.code);
43-
if (existing_it == code_to_error_name.end()) {
44-
code_to_error_name.emplace(error.code, error.name);
39+
TEST(test_diag_code, diag_codes_are_unique) {
40+
std::unordered_map<std::string, const char*> code_to_diag_name;
41+
for (const diag_name_and_code& diag : all_diags) {
42+
auto existing_it = code_to_diag_name.find(diag.code);
43+
if (existing_it == code_to_diag_name.end()) {
44+
code_to_diag_name.emplace(diag.code, diag.name);
4545
} else {
46-
ADD_FAILURE() << "error code " << error.code
47-
<< " used for multiple errors: " << error.name << ", "
48-
<< existing_it->second << "\ntry this unused error code: "
49-
<< next_unused_error_code();
46+
ADD_FAILURE() << "diag code " << diag.code
47+
<< " used for multiple diags: " << diag.name << ", "
48+
<< existing_it->second << "\ntry this unused diag code: "
49+
<< next_unused_diag_code();
5050
}
5151
}
5252
}
5353

54-
TEST(test_error, error_codes_are_well_formed) {
55-
for (const error_name_and_code& error : all_errors) {
54+
TEST(test_diag_code, diag_codes_are_well_formed) {
55+
for (const diag_name_and_code& diag : all_diags) {
5656
#if defined(_WIN32)
57-
constexpr const char* error_pattern = R"(^E\d\d\d\d$)";
57+
constexpr const char* code_pattern = R"(^E\d\d\d\d$)";
5858
#else
59-
constexpr const char* error_pattern = R"(^E[0-9][0-9][0-9][0-9]$)";
59+
constexpr const char* code_pattern = R"(^E[0-9][0-9][0-9][0-9]$)";
6060
#endif
6161
// Wrapping the code in std::string improves gtest diagnostics.
62-
EXPECT_THAT(std::string(error.code), ::testing::MatchesRegex(error_pattern))
63-
<< "error " << error.name << " should have a code like E1234"
64-
<< "\ntry this unused error code: " << next_unused_error_code();
62+
EXPECT_THAT(std::string(diag.code), ::testing::MatchesRegex(code_pattern))
63+
<< "diag " << diag.name << " should have a code like E1234"
64+
<< "\ntry this unused diag code: " << next_unused_diag_code();
6565
}
6666
}
6767
}

0 commit comments

Comments
 (0)