Skip to content

Commit f3d8b29

Browse files
committed
Use CATCH's REQUIRE_THROWS_AS
This avoids warnings about unused local variables and also is more concise. Also change one use of REQUIRE_THROWS to the more precise REQUIRE_THROWS_AS to make sure we are seeing the expected kind of exception.
1 parent d742f58 commit f3d8b29

9 files changed

+27
-81
lines changed

unit/goto-programs/goto_model_function_type_consistency.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,9 @@ SCENARIO(
5252

5353
THEN("The consistency check fails")
5454
{
55-
bool caught = false;
56-
try
57-
{
58-
goto_model.validate(validation_modet::EXCEPTION);
59-
}
60-
catch(incorrect_goto_program_exceptiont &e)
61-
{
62-
caught = true;
63-
}
64-
REQUIRE(caught);
55+
REQUIRE_THROWS_AS(
56+
goto_model.validate(validation_modet::EXCEPTION),
57+
incorrect_goto_program_exceptiont);
6558
}
6659
}
6760
}

unit/goto-programs/goto_program_assume.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,9 @@ SCENARIO(
5353
instructions.back().targets.push_back(instructions.begin());
5454
THEN("The consistency check fails")
5555
{
56-
bool caught = false;
57-
try
58-
{
59-
goto_function.body.validate(ns, validation_modet::EXCEPTION);
60-
}
61-
catch(incorrect_goto_program_exceptiont &e)
62-
{
63-
caught = true;
64-
}
65-
REQUIRE(caught);
56+
REQUIRE_THROWS_AS(
57+
goto_function.body.validate(ns, validation_modet::EXCEPTION),
58+
incorrect_goto_program_exceptiont);
6659
}
6760
}
6861
}

unit/goto-programs/goto_program_dead.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,9 @@ SCENARIO(
5656

5757
THEN("The consistency check fails")
5858
{
59-
bool caught = false;
60-
try
61-
{
62-
goto_function.body.validate(ns, validation_modet::EXCEPTION);
63-
}
64-
catch(incorrect_goto_program_exceptiont &e)
65-
{
66-
caught = true;
67-
}
68-
REQUIRE(caught);
59+
REQUIRE_THROWS_AS(
60+
goto_function.body.validate(ns, validation_modet::EXCEPTION),
61+
incorrect_goto_program_exceptiont);
6962
}
7063
}
7164
}

unit/goto-programs/goto_program_declaration.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,9 @@ SCENARIO(
5555

5656
THEN("The consistency check fails")
5757
{
58-
bool caught = false;
59-
try
60-
{
61-
goto_function.body.validate(ns, validation_modet::EXCEPTION);
62-
}
63-
catch(incorrect_goto_program_exceptiont &e)
64-
{
65-
caught = true;
66-
}
67-
REQUIRE(caught);
58+
REQUIRE_THROWS_AS(
59+
goto_function.body.validate(ns, validation_modet::EXCEPTION),
60+
incorrect_goto_program_exceptiont);
6861
}
6962
}
7063
}

unit/goto-programs/goto_program_function_call.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,9 @@ SCENARIO(
6969

7070
THEN("The consistency check fails")
7171
{
72-
bool caught = false;
73-
try
74-
{
75-
goto_function.body.validate(ns, validation_modet::EXCEPTION);
76-
}
77-
catch(incorrect_goto_program_exceptiont &e)
78-
{
79-
caught = true;
80-
}
81-
REQUIRE(caught);
72+
REQUIRE_THROWS_AS(
73+
goto_function.body.validate(ns, validation_modet::EXCEPTION),
74+
incorrect_goto_program_exceptiont);
8275
}
8376
}
8477
}

unit/goto-programs/goto_program_goto_target.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,9 @@ SCENARIO(
5858
{
5959
THEN("The consistency check fails")
6060
{
61-
bool caught = false;
62-
try
63-
{
64-
goto_function.body.validate(ns, validation_modet::EXCEPTION);
65-
}
66-
catch(incorrect_goto_program_exceptiont &e)
67-
{
68-
caught = true;
69-
}
70-
REQUIRE(caught);
61+
REQUIRE_THROWS_AS(
62+
goto_function.body.validate(ns, validation_modet::EXCEPTION),
63+
incorrect_goto_program_exceptiont);
7164
}
7265
}
7366
}

unit/goto-programs/goto_program_symbol_type_table_consistency.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,9 @@ SCENARIO(
5959

6060
THEN("The consistency check fails")
6161
{
62-
bool caught = false;
63-
try
64-
{
65-
goto_function.validate(ns, validation_modet::EXCEPTION);
66-
}
67-
catch(incorrect_goto_program_exceptiont &e)
68-
{
69-
caught = true;
70-
}
71-
REQUIRE(caught);
62+
REQUIRE_THROWS_AS(
63+
goto_function.validate(ns, validation_modet::EXCEPTION),
64+
incorrect_goto_program_exceptiont);
7265
}
7366
}
7467
}

unit/goto-programs/goto_program_table_consistency.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,9 @@ SCENARIO(
5151
const namespacet ns(symbol_table);
5252
THEN("The consistency check fails")
5353
{
54-
bool caught = false;
55-
try
56-
{
57-
goto_function.validate(ns, validation_modet::EXCEPTION);
58-
}
59-
catch(incorrect_goto_program_exceptiont &e)
60-
{
61-
caught = true;
62-
}
63-
REQUIRE(caught);
54+
REQUIRE_THROWS_AS(
55+
goto_function.validate(ns, validation_modet::EXCEPTION),
56+
incorrect_goto_program_exceptiont);
6457
}
6558
}
6659
}

unit/goto-symex/ssa_equation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ SCENARIO("Validation of well-formed SSA steps", "[core][goto-symex][validate]")
4646

4747
THEN("The consistency check fails")
4848
{
49-
REQUIRE_THROWS(equation.validate(ns, validation_modet::EXCEPTION));
49+
REQUIRE_THROWS_AS(
50+
equation.validate(ns, validation_modet::EXCEPTION),
51+
incorrect_goto_program_exceptiont);
5052
}
5153
}
5254
}

0 commit comments

Comments
 (0)