From b2961f59739b31ebf1fa8770da800e3b0e274ea4 Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Wed, 6 Mar 2024 00:51:53 -0500 Subject: [PATCH] refactor(test): delete Diag_Collector-based assert matcher code This is dead code. Delete it. https://github.com/quick-lint/quick-lint-js/issues/1154 --- test/quick-lint-js/diag-matcher.cpp | 18 +- test/quick-lint-js/diag-matcher.h | 1 - test/quick-lint-js/diagnostic-assertion.cpp | 80 --------- test/quick-lint-js/diagnostic-assertion.h | 16 -- test/test-diagnostic-assertion.cpp | 187 -------------------- 5 files changed, 1 insertion(+), 301 deletions(-) diff --git a/test/quick-lint-js/diag-matcher.cpp b/test/quick-lint-js/diag-matcher.cpp index eb5f68164..216c9a6b5 100644 --- a/test/quick-lint-js/diag-matcher.cpp +++ b/test/quick-lint-js/diag-matcher.cpp @@ -75,8 +75,7 @@ Variable_Kind Diag_Matcher_Arg::get_variable_kind( template class Diag_Fields_Matcher_Impl_Base - : public testing::MatcherInterface, - public testing::MatcherInterface { + : public testing::MatcherInterface { public: explicit Diag_Fields_Matcher_Impl_Base(State s) : state_(std::move(s)) {} @@ -100,16 +99,6 @@ class Diag_Fields_Matcher_Impl_Base this->DescribeTo(out); } - bool MatchAndExplain(const Diag_Collector::Diag &error, - testing::MatchResultListener *listener) const final { - return this->MatchAndExplain( - Any_Diag_Pointer{ - .type = error.type(), - .data = error.data(), - }, - listener); - } - bool MatchAndExplain(const Any_Diag_Pointer &error, testing::MatchResultListener *listener) const final { bool type_matches = error.type == this->state_.type; @@ -268,11 +257,6 @@ class Diag_Matcher_2::Impl final } }; -Diag_Matcher_2::operator testing::Matcher() - const { - return testing::Matcher(new Impl(this->state_)); -} - Diag_Matcher_2::operator testing::Matcher() const { return testing::Matcher(new Impl(this->state_)); } diff --git a/test/quick-lint-js/diag-matcher.h b/test/quick-lint-js/diag-matcher.h index dcf225755..25b716fdf 100644 --- a/test/quick-lint-js/diag-matcher.h +++ b/test/quick-lint-js/diag-matcher.h @@ -91,7 +91,6 @@ class Diag_Matcher_2 { Diag_Matcher_2 &operator=(const Diag_Matcher_2 &) = default; Diag_Matcher_2 &operator=(Diag_Matcher_2 &&) = default; - /*implicit*/ operator testing::Matcher() const; /*implicit*/ operator testing::Matcher() const; void DescribeTo(std::ostream *out) const { diff --git a/test/quick-lint-js/diagnostic-assertion.cpp b/test/quick-lint-js/diagnostic-assertion.cpp index 1276774a9..4ad7b558f 100644 --- a/test/quick-lint-js/diagnostic-assertion.cpp +++ b/test/quick-lint-js/diagnostic-assertion.cpp @@ -501,21 +501,6 @@ Diagnostic_Assertion operator""_diag( return Diagnostic_Assertion::parse_or_exit(specification); } -void assert_diagnostics(Padded_String_View code, - const std::vector& diagnostics, - Span assertions, - Source_Location caller) { - EXPECT_THAT_AT_CALLER(diagnostics, diagnostics_matcher(code, assertions)); -} - -void assert_diagnostics(Padded_String_View code, - const std::vector& diagnostics, - std::initializer_list assertions, - Source_Location caller) { - assert_diagnostics(code, diagnostics, - Span(assertions), caller); -} - void assert_diagnostics(Padded_String_View code, const Diag_List& diagnostics, Span assertions, Source_Location caller) { @@ -529,71 +514,6 @@ void assert_diagnostics(Padded_String_View code, const Diag_List& diagnostics, Span(assertions), caller); } -// TODO(#1154): Delete in favor of diagnostics_matcher_2. -::testing::Matcher&> -diagnostics_matcher(Padded_String_View code, - Span assertions) { - std::vector error_matchers; - for (const Diagnostic_Assertion& diag : assertions) { - Diagnostic_Assertion adjusted_diag = - diag.adjusted_for_escaped_characters(code.string_view()); - - std::vector fields; - for (const Diagnostic_Assertion::Member& member : adjusted_diag.members) { - Diag_Matcher_2::Field field; - field.arg = Diag_Matcher_Arg{ - .member_name = to_string_view(member.name), - .member_offset = member.offset, - .member_type = member.type, - }; - switch (member.type) { - case Diagnostic_Arg_Type::source_code_span: - field.begin_offset = narrow_cast( - member.span_begin_offset); - field.end_offset = narrow_cast( - member.span_end_offset); - break; - case Diagnostic_Arg_Type::char8: - field.character = member.character; - break; - case Diagnostic_Arg_Type::enum_kind: - field.enum_kind = member.enum_kind; - break; - case Diagnostic_Arg_Type::string8_view: - field.string = member.string; - break; - case Diagnostic_Arg_Type::statement_kind: - field.statement_kind = member.statement_kind; - break; - case Diagnostic_Arg_Type::variable_kind: - field.variable_kind = member.variable_kind; - break; - default: - QLJS_ASSERT(false); - break; - } - fields.push_back(field); - } - - error_matchers.push_back( - Diag_Matcher_2(code, adjusted_diag.type, std::move(fields))); - } - if (error_matchers.size() <= 1) { - // ElementsAreArray produces better diagnostics than - // UnorderedElementsAreArray. - return ::testing::ElementsAreArray(std::move(error_matchers)); - } else { - return ::testing::UnorderedElementsAreArray(std::move(error_matchers)); - } -} - -::testing::Matcher&> -diagnostics_matcher(Padded_String_View code, - std::initializer_list assertions) { - return diagnostics_matcher(code, - Span(assertions)); -} - namespace { class Diag_List_Matcher_Impl : public testing::MatcherInterface { diff --git a/test/quick-lint-js/diagnostic-assertion.h b/test/quick-lint-js/diagnostic-assertion.h index 1dbff1c25..960cf3665 100644 --- a/test/quick-lint-js/diagnostic-assertion.h +++ b/test/quick-lint-js/diagnostic-assertion.h @@ -223,15 +223,6 @@ struct Diagnostic_Assertion { Diagnostic_Assertion operator""_diag(const Char8* specification, std::size_t specification_length); -void assert_diagnostics(Padded_String_View code, - const std::vector& diagnostics, - Span assertions, - Source_Location caller); -void assert_diagnostics(Padded_String_View code, - const std::vector& diagnostics, - std::initializer_list assertions, - Source_Location caller = Source_Location::current()); - void assert_diagnostics(Padded_String_View code, const Diag_List& diagnostics, Span assertions, Source_Location caller); @@ -239,13 +230,6 @@ void assert_diagnostics(Padded_String_View code, const Diag_List& diagnostics, std::initializer_list assertions, Source_Location caller = Source_Location::current()); -::testing::Matcher&> -diagnostics_matcher(Padded_String_View code, - Span assertions); -::testing::Matcher&> -diagnostics_matcher(Padded_String_View code, - std::initializer_list assertions); - ::testing::Matcher diagnostics_matcher_2( Padded_String_View code, Span assertions); ::testing::Matcher diagnostics_matcher_2( diff --git a/test/test-diagnostic-assertion.cpp b/test/test-diagnostic-assertion.cpp index 1f614025b..5bddca3f0 100644 --- a/test/test-diagnostic-assertion.cpp +++ b/test/test-diagnostic-assertion.cpp @@ -562,193 +562,6 @@ TEST(Test_Diagnostic_Assertion, } } -TEST(Test_Diagnostic_Assertion, match_error_type_with_1_field) { - Padded_String code(u8"hello"_sv); - - ::testing::Matcher continue_matcher = - diagnostics_matcher(&code, {u8"^^^^^ Diag_Invalid_Continue"_diag}); - EXPECT_TRUE(continue_matcher.Matches({ - Diag_Collector::Diag(Diag_Invalid_Continue{ - .continue_statement = Source_Code_Span(&code[0], &code[5]), - }), - })); - EXPECT_FALSE(continue_matcher.Matches({ - Diag_Collector::Diag(Diag_Invalid_Break{ - .break_statement = Source_Code_Span(&code[0], &code[5]), - }), - })); - - ::testing::Matcher break_matcher = - diagnostics_matcher(&code, {u8"^^^^^ Diag_Invalid_Break"_diag}); - EXPECT_FALSE(break_matcher.Matches({ - Diag_Collector::Diag(Diag_Invalid_Continue{ - .continue_statement = Source_Code_Span(&code[0], &code[5]), - }), - })); - EXPECT_TRUE(break_matcher.Matches({ - Diag_Collector::Diag(Diag_Invalid_Break{ - .break_statement = Source_Code_Span(&code[0], &code[5]), - }), - })); -} - -TEST(Test_Diagnostic_Assertion, match_error_type_with_1_field_message) { - Padded_String code(u8"hello"_sv); - ::testing::Matcher matcher = - diagnostics_matcher(&code, {u8"^^^^^ Diag_Invalid_Continue"_diag}); - Diag_Collector::Diag value(Diag_Invalid_Break{ - .break_statement = Source_Code_Span(&code[0], &code[5]), - }); - EXPECT_EQ(get_matcher_message(matcher, {value}), - "whose element #0 doesn't match, whose type (Diag_Invalid_Break) " - "isn't Diag_Invalid_Continue"); -} - -TEST(Test_Diagnostic_Assertion, match_offsets_of_1_field_span) { - Padded_String code(u8"hello"_sv); - - ::testing::Matcher continue_matcher = - diagnostics_matcher(&code, {u8" ^^^^ Diag_Invalid_Continue"_diag}); - EXPECT_TRUE(continue_matcher.Matches({ - Diag_Collector::Diag(Diag_Invalid_Continue{ - .continue_statement = Source_Code_Span(&code[1], &code[5]), - }), - })); - EXPECT_FALSE(continue_matcher.Matches({ - Diag_Collector::Diag(Diag_Invalid_Continue{ - .continue_statement = Source_Code_Span(&code[0], &code[5]), - }), - })); - EXPECT_FALSE(continue_matcher.Matches({ - Diag_Collector::Diag(Diag_Invalid_Continue{ - .continue_statement = Source_Code_Span(&code[0], &code[4]), - }), - })); -} - -TEST(Test_Diagnostic_Assertion, match_offsets_of_1_field_message) { - Padded_String code(u8"hello"_sv); - - { - ::testing::Matcher matcher = - diagnostics_matcher(&code, {u8"^^^^^ Diag_Invalid_Continue"_diag}); - Diag_Collector::Diag value(Diag_Invalid_Continue{ - .continue_statement = Source_Code_Span(&code[1], &code[4]), - }); - EXPECT_EQ(get_matcher_message(matcher, {value}), - "whose element #0 doesn't match, whose .continue_statement (1-4) " - "doesn't equal 0-5"); - } - - { - ::testing::Matcher matcher = - diagnostics_matcher(&code, {u8"^^^^^ Diag_Invalid_Break"_diag}); - Diag_Collector::Diag value(Diag_Invalid_Break{ - .break_statement = Source_Code_Span(&code[1], &code[4]), - }); - EXPECT_EQ(get_matcher_message(matcher, {value}), - "whose element #0 doesn't match, whose .break_statement (1-4) " - "doesn't equal 0-5"); - } -} - -TEST(Test_Diagnostic_Assertion, match_span_and_char8) { - Padded_String code(u8"(hello"_sv); - - ::testing::Matcher matcher = diagnostics_matcher( - &code, - {u8"^ Diag_Expected_Parenthesis_Around_Do_While_Condition.where{.token=)}"_diag}); - EXPECT_TRUE(matcher.Matches({ - Diag_Collector::Diag(Diag_Expected_Parenthesis_Around_Do_While_Condition{ - .where = Source_Code_Span(&code[0], &code[1]), - .token = u8')', - }), - })); - EXPECT_FALSE(matcher.Matches({ - Diag_Collector::Diag(Diag_Expected_Parenthesis_Around_Do_While_Condition{ - .where = Source_Code_Span(&code[0], &code[1]), - .token = u8'(', - }), - })); -} - -TEST(Test_Diagnostic_Assertion, char8_message) { - Padded_String code(u8"hello"_sv); - - ::testing::Matcher matcher = diagnostics_matcher( - &code, - {u8"^ Diag_Expected_Parenthesis_Around_Do_While_Condition.where{.token=)}"_diag}); - - Diag_Collector::Diag value( - Diag_Expected_Parenthesis_Around_Do_While_Condition{ - .where = Source_Code_Span(&code[0], &code[1]), - .token = u8'(', - }); - EXPECT_EQ(get_matcher_message(matcher, {value}), - "whose element #0 doesn't match, whose .where (0-1) equals 0-1 and " - "whose .token ('(') doesn't equal ')'"); -} - -TEST(Test_Diagnostic_Assertion, match_span_and_string8_view) { - Padded_String code(u8"hi"_sv); - - ::testing::Matcher matcher = diagnostics_matcher( - &code, - {u8"^ Diag_Integer_Literal_Will_Lose_Precision.characters{.rounded_val=hello}"_diag}); - EXPECT_TRUE(matcher.Matches({ - Diag_Collector::Diag(Diag_Integer_Literal_Will_Lose_Precision{ - .characters = Source_Code_Span(&code[0], &code[1]), - .rounded_val = u8"hello"_sv, - }), - })); - EXPECT_FALSE(matcher.Matches({ - Diag_Collector::Diag(Diag_Integer_Literal_Will_Lose_Precision{ - .characters = Source_Code_Span(&code[0], &code[1]), - .rounded_val = u8"HELLO"_sv, - }), - })); -} - -TEST(Test_Diagnostic_Assertion, string8_view_message) { - Padded_String code(u8"hi"_sv); - - ::testing::Matcher matcher = diagnostics_matcher( - &code, - {u8"^ Diag_Integer_Literal_Will_Lose_Precision.characters{.rounded_val=hello}"_diag}); - - Diag_Collector::Diag value(Diag_Integer_Literal_Will_Lose_Precision{ - .characters = Source_Code_Span(&code[0], &code[1]), - .rounded_val = u8"HELLO"_sv, - }); - EXPECT_EQ( - get_matcher_message(matcher, {value}), - "whose element #0 doesn't match, whose .characters (0-1) equals 0-1 and " - "whose .rounded_val (\"HELLO\") doesn't equal \"hello\""); -} - -TEST(Test_Diagnostic_Assertion, multiple_diagnostics_are_matched_in_any_order) { - Padded_String code(u8"hello"_sv); - - ::testing::Matcher continue_break_matcher = - diagnostics_matcher(&code, {u8"^^^^^ Diag_Invalid_Continue"_diag, - u8"^^^^^ Diag_Invalid_Break"_diag}); - ::testing::Matcher break_continue_matcher = - diagnostics_matcher(&code, {u8"^^^^^ Diag_Invalid_Break"_diag, - u8"^^^^^ Diag_Invalid_Continue"_diag}); - - Diag_Collector::Diag continue_diag(Diag_Invalid_Continue{ - .continue_statement = Source_Code_Span(&code[0], &code[5]), - }); - Diag_Collector::Diag break_diag(Diag_Invalid_Break{ - .break_statement = Source_Code_Span(&code[0], &code[5]), - }); - - EXPECT_TRUE(break_continue_matcher.Matches({break_diag, continue_diag})); - EXPECT_TRUE(break_continue_matcher.Matches({continue_diag, break_diag})); - EXPECT_TRUE(continue_break_matcher.Matches({break_diag, continue_diag})); - EXPECT_TRUE(continue_break_matcher.Matches({continue_diag, break_diag})); -} - class Test_Diagnostic_Assertion_2 : public ::testing::Test { protected: Monotonic_Allocator memory_{"Test_Diagnostic_Assertion_2"};