int main( int argc, const char *argv[] ) { std::string path; Json::Features features; bool parseOnly; int exitCode = parseCommandLine( argc, argv, features, path, parseOnly ); if ( exitCode != 0 ) { return exitCode; } try { std::string input = readInputTestFile( path.c_str() ); if ( input.empty() ) { printf( "Failed to read input or empty input: %s\n", path.c_str() ); return 3; } std::string basePath = removeSuffix( argv[1], ".json" ); if ( !parseOnly && basePath.empty() ) { printf( "Bad input path. Path does not end with '.expected':\n%s\n", path.c_str() ); return 3; } std::string actualPath = basePath + ".actual"; std::string rewritePath = basePath + ".rewrite"; std::string rewriteActualPath = basePath + ".actual-rewrite"; Json::Value root; exitCode = parseAndSaveValueTree( input, actualPath, "input", root, features, parseOnly ); if ( exitCode == 0 && !parseOnly ) { std::string rewrite; exitCode = rewriteValueTree( rewritePath, root, rewrite ); if ( exitCode == 0 ) { Json::Value rewriteRoot; exitCode = parseAndSaveValueTree( rewrite, rewriteActualPath, "rewrite", rewriteRoot, features, parseOnly ); } } } catch ( const std::exception &e ) { printf( "Unhandled exception:\n%s\n", e.what() ); exitCode = 1; } return exitCode; }
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; }
int main( int argc, const char *argv[] ) { if ( argc != 2 ) { printf( "Usage: %s input-json-file", argv[0] ); return 3; } std::string input = readInputTestFile( argv[1] ); if ( input.empty() ) { printf( "Failed to read input or empty input: %s\n", argv[1] ); return 3; } std::string basePath = removeSuffix( argv[1], ".json" ); if ( basePath.empty() ) { printf( "Bad input path. Path does not end with '.expected':\n%s\n", argv[1] ); return 3; } std::string actualPath = basePath + ".actual"; std::string rewritePath = basePath + ".rewrite"; std::string rewriteActualPath = basePath + ".actual-rewrite"; Json::Value root; int exitCode = parseAndSaveValueTree( input, actualPath, "input", root ); if ( exitCode == 0 ) { std::string rewrite; exitCode = rewriteValueTree( rewritePath, root, rewrite ); if ( exitCode == 0 ) { Json::Value rewriteRoot; exitCode = parseAndSaveValueTree( rewrite, rewriteActualPath, "rewrite", rewriteRoot ); } } return exitCode; }