|
11 | 11 | #include <solvers/smt2_incremental/smt_terms.h>
|
12 | 12 | #include <util/arith_tools.h>
|
13 | 13 | #include <util/bitvector_types.h>
|
| 14 | +#include <util/exception_utils.h> |
14 | 15 | #include <util/make_unique.h>
|
15 | 16 | #include <util/namespace.h>
|
16 | 17 | #include <util/symbol_table.h>
|
|
23 | 24 |
|
24 | 25 | #include <deque>
|
25 | 26 |
|
| 27 | +class analysis_execption_with_messaget |
| 28 | + : public Catch::MatcherBase<analysis_exceptiont> |
| 29 | +{ |
| 30 | +public: |
| 31 | + explicit analysis_execption_with_messaget(std::string message); |
| 32 | + bool match(const analysis_exceptiont &exception) const override; |
| 33 | + std::string describe() const override; |
| 34 | + |
| 35 | +private: |
| 36 | + std::string expected; |
| 37 | +}; |
| 38 | + |
| 39 | +analysis_execption_with_messaget::analysis_execption_with_messaget( |
| 40 | + std::string message) |
| 41 | + : expected{std::move(message)} |
| 42 | +{ |
| 43 | +} |
| 44 | + |
| 45 | +bool analysis_execption_with_messaget::match( |
| 46 | + const analysis_exceptiont &exception) const |
| 47 | +{ |
| 48 | + return expected == exception.what(); |
| 49 | +} |
| 50 | + |
| 51 | +std::string analysis_execption_with_messaget::describe() const |
| 52 | +{ |
| 53 | + return std::string{"analysis_exceptiont with `.what' containing - \""} + |
| 54 | + expected + "\""; |
| 55 | +} |
| 56 | + |
26 | 57 | class smt_mock_solver_processt : public smt_base_solver_processt
|
27 | 58 | {
|
28 | 59 | std::function<void(const smt_commandt &)> _send;
|
@@ -293,7 +324,57 @@ TEST_CASE(
|
293 | 324 | "[core][smt2_incremental]")
|
294 | 325 | {
|
295 | 326 | decision_procedure_test_environmentt test{};
|
296 |
| - test.mock_responses = {smt_success_responset{}, |
297 |
| - smt_check_sat_responset{smt_sat_responset{}}}; |
298 |
| - REQUIRE_NOTHROW(test.procedure()); |
| 327 | + SECTION("Expected success response.") |
| 328 | + { |
| 329 | + test.mock_responses = {smt_success_responset{}, |
| 330 | + smt_check_sat_responset{smt_sat_responset{}}}; |
| 331 | + REQUIRE_NOTHROW(test.procedure()); |
| 332 | + } |
| 333 | + SECTION("Duplicated success messages.") |
| 334 | + { |
| 335 | + test.mock_responses = {smt_success_responset{}, |
| 336 | + smt_success_responset{}, |
| 337 | + smt_check_sat_responset{smt_sat_responset{}}}; |
| 338 | + REQUIRE_THROWS_MATCHES( |
| 339 | + test.procedure(), |
| 340 | + analysis_exceptiont, |
| 341 | + analysis_execption_with_messaget{ |
| 342 | + "Unexpected kind of response from SMT solver."}); |
| 343 | + } |
| 344 | +} |
| 345 | + |
| 346 | +TEST_CASE( |
| 347 | + "smt2_incremental_decision_proceduret receives unexpected responses to " |
| 348 | + "check-sat.", |
| 349 | + "[core][smt2_incremental]") |
| 350 | +{ |
| 351 | + decision_procedure_test_environmentt test{}; |
| 352 | + SECTION("get-value response") |
| 353 | + { |
| 354 | + test.mock_responses = { |
| 355 | + smt_get_value_responset{{{"x", smt_bool_literal_termt{false}}}}}; |
| 356 | + REQUIRE_THROWS_MATCHES( |
| 357 | + test.procedure(), |
| 358 | + analysis_exceptiont, |
| 359 | + analysis_execption_with_messaget{ |
| 360 | + "Unexpected kind of response from SMT solver."}); |
| 361 | + } |
| 362 | + SECTION("error message response") |
| 363 | + { |
| 364 | + test.mock_responses = {smt_error_responset{"foobar"}}; |
| 365 | + REQUIRE_THROWS_MATCHES( |
| 366 | + test.procedure(), |
| 367 | + analysis_exceptiont, |
| 368 | + analysis_execption_with_messaget{ |
| 369 | + "SMT solver returned an error message - foobar"}); |
| 370 | + } |
| 371 | + SECTION("unsupported response") |
| 372 | + { |
| 373 | + test.mock_responses = {smt_unsupported_responset{}}; |
| 374 | + REQUIRE_THROWS_MATCHES( |
| 375 | + test.procedure(), |
| 376 | + analysis_exceptiont, |
| 377 | + analysis_execption_with_messaget{ |
| 378 | + "SMT solver does not support given command."}); |
| 379 | + } |
299 | 380 | }
|
0 commit comments