Skip to content

Make json parser unit tests independent of working directory #2586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.