static int runTest(Options const& opts) { int exitCode = 0; JSONCPP_STRING input = readInputTestFile(opts.path.c_str()); if (input.empty()) { printf("Failed to read input or empty input: %s\n", opts.path.c_str()); return 3; } JSONCPP_STRING basePath = removeSuffix(opts.path, ".json"); if (!opts.parseOnly && basePath.empty()) { printf("Bad input path. Path does not end with '.expected':\n%s\n", opts.path.c_str()); return 3; } JSONCPP_STRING const actualPath = basePath + ".actual"; JSONCPP_STRING const rewritePath = basePath + ".rewrite"; JSONCPP_STRING const rewriteActualPath = basePath + ".actual-rewrite"; Json::Value root; exitCode = parseAndSaveValueTree( input, actualPath, "input", opts.features, opts.parseOnly, &root); if (exitCode || opts.parseOnly) { return exitCode; } JSONCPP_STRING rewrite; exitCode = rewriteValueTree(rewritePath, root, opts.write, &rewrite); if (exitCode) { return exitCode; } Json::Value rewriteRoot; exitCode = parseAndSaveValueTree( rewrite, rewriteActualPath, "rewrite", opts.features, opts.parseOnly, &rewriteRoot); if (exitCode) { return exitCode; } return 0; }
Json::Value getDOM(std::string const& path) { JSONCPP_STRING input = readInputTestFile(path.c_str()); if (input.empty()) { throw std::runtime_error("Empty input file"); } Json::Features mode = Json::Features::strictMode(); mode.allowComments_ = true; Json::Value root; Json::Reader reader(mode); bool parsingSuccessful = reader.parse(input.data(), input.data() + input.size(), root); if (!parsingSuccessful) { throw std::runtime_error( std::string("Failed to parse file: ") + reader.getFormattedErrorMessages()); } return root; }