Skip to content

Commit cd1a8bd

Browse files
committed
refactor(test): move EXPECT_THAT call to enable future refactor
1 parent 5bee328 commit cd1a8bd

File tree

1 file changed

+59
-41
lines changed

1 file changed

+59
-41
lines changed

test/test-variable-analyzer-type.cpp

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,6 @@ TEST(Test_Variable_Analyzer_Type, type_use_does_not_see_non_type_variables) {
285285

286286
TEST(Test_Variable_Analyzer_Type,
287287
interfaces_are_ignored_in_runtime_expressions) {
288-
using Diags_Matcher =
289-
testing::Matcher<const std::vector<Diag_Collector::Diag>&>;
290-
291288
static const Char8 outer_declaration[] = u8"I";
292289
static const Char8 declaration[] = u8"I";
293290

@@ -312,8 +309,15 @@ TEST(Test_Variable_Analyzer_Type,
312309
//
313310
// If no run-time variable exists with the same name as the interface,
314311
// 'runtime_var_kind' is nullopt.
315-
Diags_Matcher (*get_diags_matcher)(
316-
std::optional<Variable_Kind> runtime_var_kind);
312+
void (*check_diagnostics_impl)(
313+
Diag_Collector& diags, std::optional<Variable_Kind> runtime_var_kind,
314+
Source_Location caller);
315+
316+
void check_diagnostics(
317+
Diag_Collector& diags, std::optional<Variable_Kind> runtime_var_kind,
318+
Source_Location caller = Source_Location::current()) {
319+
return this->check_diagnostics_impl(diags, runtime_var_kind, caller);
320+
}
317321
};
318322

319323
Variable_Visit_Kind variable_visit_kinds[] = {
@@ -324,24 +328,31 @@ TEST(Test_Variable_Analyzer_Type,
324328
l.visit_variable_assignment(identifier_of(assignment),
325329
Variable_Assignment_Flags::none);
326330
},
327-
.get_diags_matcher = [](std::optional<Variable_Kind> runtime_var_kind)
328-
-> Diags_Matcher {
331+
.check_diagnostics_impl =
332+
[](Diag_Collector& diags,
333+
std::optional<Variable_Kind> runtime_var_kind,
334+
Source_Location caller) -> void {
329335
if (runtime_var_kind.has_value()) {
330336
if (*runtime_var_kind == Variable_Kind::_const) {
331-
return ElementsAreArray({
332-
DIAG_TYPE_2_SPANS(Diag_Assignment_To_Const_Variable, //
333-
assignment, span_of(assignment), //
334-
declaration, span_of(outer_declaration)),
335-
});
337+
EXPECT_THAT_AT_CALLER(
338+
diags.errors,
339+
ElementsAreArray({
340+
DIAG_TYPE_2_SPANS(Diag_Assignment_To_Const_Variable, //
341+
assignment, span_of(assignment), //
342+
declaration,
343+
span_of(outer_declaration)),
344+
}));
336345
} else {
337-
return IsEmpty();
346+
EXPECT_THAT_AT_CALLER(diags.errors, IsEmpty());
338347
}
339348
} else {
340349
// TODO(strager): Report a more helpful message.
341-
return ElementsAreArray({
342-
DIAG_TYPE_SPAN(Diag_Assignment_To_Undeclared_Variable,
343-
assignment, span_of(assignment)),
344-
});
350+
EXPECT_THAT_AT_CALLER(
351+
diags.errors,
352+
ElementsAreArray({
353+
DIAG_TYPE_SPAN(Diag_Assignment_To_Undeclared_Variable,
354+
assignment, span_of(assignment)),
355+
}));
345356
}
346357
},
347358
},
@@ -353,17 +364,21 @@ TEST(Test_Variable_Analyzer_Type,
353364
l.visit_variable_delete_use(Identifier(deleted_variable_span),
354365
delete_keyword_span);
355366
},
356-
.get_diags_matcher = [](std::optional<Variable_Kind> runtime_var_kind)
357-
-> Diags_Matcher {
367+
.check_diagnostics_impl =
368+
[](Diag_Collector& diags,
369+
std::optional<Variable_Kind> runtime_var_kind,
370+
Source_Location caller) -> void {
358371
if (runtime_var_kind.has_value()) {
359-
return ElementsAreArray({
360-
DIAG_TYPE_OFFSETS(
361-
&delete_expression,
362-
Diag_Redundant_Delete_Statement_On_Variable, //
363-
delete_expression, 0, u8"delete I"_sv),
364-
});
372+
EXPECT_THAT_AT_CALLER(
373+
diags.errors,
374+
ElementsAreArray({
375+
DIAG_TYPE_OFFSETS(
376+
&delete_expression,
377+
Diag_Redundant_Delete_Statement_On_Variable, //
378+
delete_expression, 0, u8"delete I"_sv),
379+
}));
365380
} else {
366-
return IsEmpty();
381+
EXPECT_THAT_AT_CALLER(diags.errors, IsEmpty());
367382
}
368383
},
369384
},
@@ -373,16 +388,19 @@ TEST(Test_Variable_Analyzer_Type,
373388
[](Variable_Analyzer& l) {
374389
l.visit_variable_use(identifier_of(use));
375390
},
376-
.get_diags_matcher =
377-
[](std::optional<Variable_Kind> runtime_var_kind) -> Diags_Matcher {
391+
.check_diagnostics_impl =
392+
[](Diag_Collector& diags,
393+
std::optional<Variable_Kind> runtime_var_kind,
394+
Source_Location caller) -> void {
378395
if (runtime_var_kind.has_value()) {
379-
return IsEmpty();
396+
EXPECT_THAT_AT_CALLER(diags.errors, IsEmpty());
380397
} else {
381398
// TODO(strager): Report a more helpful message.
382-
return ElementsAreArray({
383-
DIAG_TYPE_SPAN(Diag_Use_Of_Undeclared_Variable, name,
384-
span_of(use)),
385-
});
399+
EXPECT_THAT_AT_CALLER(
400+
diags.errors, ElementsAreArray({
401+
DIAG_TYPE_SPAN(Diag_Use_Of_Undeclared_Variable,
402+
name, span_of(use)),
403+
}));
386404
}
387405
}},
388406
};
@@ -401,7 +419,7 @@ TEST(Test_Variable_Analyzer_Type,
401419
visit_kind.visit(l);
402420
l.visit_end_of_module();
403421

404-
EXPECT_THAT(v.errors, visit_kind.get_diags_matcher(std::nullopt));
422+
visit_kind.check_diagnostics(v, std::nullopt);
405423
}
406424

407425
{
@@ -419,7 +437,7 @@ TEST(Test_Variable_Analyzer_Type,
419437
l.visit_exit_block_scope();
420438
l.visit_end_of_module();
421439

422-
EXPECT_THAT(v.errors, visit_kind.get_diags_matcher(std::nullopt));
440+
visit_kind.check_diagnostics(v, std::nullopt);
423441
}
424442

425443
{
@@ -443,7 +461,7 @@ TEST(Test_Variable_Analyzer_Type,
443461
l.visit_exit_function_scope();
444462
l.visit_end_of_module();
445463

446-
EXPECT_THAT(v.errors, visit_kind.get_diags_matcher(std::nullopt));
464+
visit_kind.check_diagnostics(v, std::nullopt);
447465
}
448466

449467
for (Variable_Kind outer_kind : {
@@ -477,7 +495,7 @@ TEST(Test_Variable_Analyzer_Type,
477495
l.visit_exit_block_scope();
478496
l.visit_end_of_module();
479497

480-
EXPECT_THAT(v.errors, visit_kind.get_diags_matcher(outer_kind));
498+
visit_kind.check_diagnostics(v, outer_kind);
481499
}
482500

483501
{
@@ -499,7 +517,7 @@ TEST(Test_Variable_Analyzer_Type,
499517
l.visit_exit_block_scope();
500518
l.visit_end_of_module();
501519

502-
EXPECT_THAT(v.errors, visit_kind.get_diags_matcher(outer_kind));
520+
visit_kind.check_diagnostics(v, outer_kind);
503521
}
504522

505523
{
@@ -517,7 +535,7 @@ TEST(Test_Variable_Analyzer_Type,
517535
visit_kind.visit(l);
518536
l.visit_end_of_module();
519537

520-
EXPECT_THAT(v.errors, visit_kind.get_diags_matcher(outer_kind));
538+
visit_kind.check_diagnostics(v, outer_kind);
521539
}
522540

523541
{
@@ -535,7 +553,7 @@ TEST(Test_Variable_Analyzer_Type,
535553
visit_kind.visit(l);
536554
l.visit_end_of_module();
537555

538-
EXPECT_THAT(v.errors, visit_kind.get_diags_matcher(outer_kind));
556+
visit_kind.check_diagnostics(v, outer_kind);
539557
}
540558

541559
{
@@ -558,7 +576,7 @@ TEST(Test_Variable_Analyzer_Type,
558576
Variable_Declaration_Flags::none);
559577
l.visit_end_of_module();
560578

561-
EXPECT_THAT(v.errors, visit_kind.get_diags_matcher(outer_kind));
579+
visit_kind.check_diagnostics(v, outer_kind);
562580
}
563581
}
564582
}

0 commit comments

Comments
 (0)