Skip to content

Commit

Permalink
Make json parser unit tests independent of working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-steffenhagen-diffblue committed Jul 19, 2018
1 parent 14dc11e commit ed48122
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 0 additions & 1 deletion unit/json/invalid.json

This file was deleted.

18 changes: 16 additions & 2 deletions unit/json/json_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,30 @@
\*******************************************************************/

#include <fstream>
#include <json/json_parser.h>
#include <testing-utils/catch.hpp>
#include <testing-utils/message.h>
#include <util/tempfile.h>

SCENARIO("Loading JSON files")
{
GIVEN("A invalid JSON file and a valid JSON file")
{
const std::string valid_json_path = "./json/valid.json";
const std::string invalid_json_path = "./json/invalid.json";
temporary_filet valid_json_file("cbmc_unit_json_parser_valid", ".json");
temporary_filet invalid_json_file("cbmc_unit_json_parser_invalid", ".json");
const std::string valid_json_path = valid_json_file();
const std::string invalid_json_path = invalid_json_file();
{
std::ofstream valid_json_out(valid_json_path);
valid_json_out << "{\n"
<< " \"hello\": \"world\"\n"
<< "}\n";
}
{
std::ofstream invalid_json_out(invalid_json_path);
invalid_json_out << "foo\n";
}

WHEN("Loading the invalid JSON file")
{
Expand Down
3 changes: 0 additions & 3 deletions unit/json/valid.json

This file was deleted.

0 comments on commit ed48122

Please sign in to comment.