Skip to content

Commit 836d954

Browse files
committed
Move tests to legacy_ prepend
1 parent 9050dc3 commit 836d954

File tree

114 files changed

+24
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+24
-22
lines changed

src/jsontestrunner/main.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cstdio>
1818
#include <json/json.h>
1919
#include <memory>
20+
#include <iostream>
2021
#include <sstream>
2122

2223
struct Options {
@@ -143,7 +144,8 @@ static int parseAndSaveValueTree(const Json::String& input,
143144
reader->parse(input.data(), input.data() + input.size(), root, &errors);
144145

145146
if (!parsingSuccessful) {
146-
printf("Failed to parse %s file: \n%s\n", kind.c_str(), errors.c_str());
147+
std::cerr << "Failed to parse " << kind << " file: " << std::endl
148+
<< errors << std::endl;
147149
return 1;
148150
}
149151

@@ -154,16 +156,16 @@ static int parseAndSaveValueTree(const Json::String& input,
154156
const bool parsingSuccessful =
155157
reader.parse(input.data(), input.data() + input.size(), *root);
156158
if (!parsingSuccessful) {
157-
printf("Failed to parse %s file: \n%s\n", kind.c_str(),
158-
reader.getFormattedErrorMessages().c_str());
159+
std::cerr << "Failed to parse " << kind << " file: " << std::endl
160+
<< reader.getFormatedErrorMessages() << std::endl;
159161
return 1;
160162
}
161163
}
162164

163165
if (!parseOnly) {
164166
FILE* factual = fopen(actual.c_str(), "wt");
165167
if (!factual) {
166-
printf("Failed to create %s actual file.\n", kind.c_str());
168+
std::cerr << "Failed to create '" << kind << "' actual file." << std::endl;
167169
return 2;
168170
}
169171
printValueTree(factual, *root);
@@ -197,7 +199,7 @@ static int rewriteValueTree(const Json::String& rewritePath,
197199
*rewrite = write(root);
198200
FILE* fout = fopen(rewritePath.c_str(), "wt");
199201
if (!fout) {
200-
printf("Failed to create rewrite file: %s\n", rewritePath.c_str());
202+
std::cerr << "Failed to create rewrite file: " << rewritePath << std::endl;
201203
return 2;
202204
}
203205
fprintf(fout, "%s\n", rewrite->c_str());
@@ -218,14 +220,14 @@ static Json::String removeSuffix(const Json::String& path,
218220
static void printConfig() {
219221
// Print the configuration used to compile JsonCpp
220222
#if defined(JSON_NO_INT64)
221-
printf("JSON_NO_INT64=1\n");
223+
std::cout << "JSON_NO_INT64=1" << std::endl;
222224
#else
223-
printf("JSON_NO_INT64=0\n");
225+
std::cout << "JSON_NO_INT64=0" << std::endl;
224226
#endif
225227
}
226228

227229
static int printUsage(const char* argv[]) {
228-
printf("Usage: %s [--strict] input-json-file", argv[0]);
230+
std::cout << "Usage: " << argv[0] << " [--strict] input-json-file" << std::endl;
229231
return 3;
230232
}
231233

@@ -255,7 +257,7 @@ static int parseCommandLine(int argc, const char* argv[], Options* opts) {
255257
} else if (writerName == "BuiltStyledStreamWriter") {
256258
opts->write = &useBuiltStyledStreamWriter;
257259
} else {
258-
printf("Unknown '--json-writer %s'\n", writerName.c_str());
260+
std::cerr << "Unknown '--json-writer' " << writerName << std::endl;
259261
return 4;
260262
}
261263
}
@@ -271,14 +273,13 @@ static int runTest(Options const& opts, bool use_legacy) {
271273

272274
Json::String input = readInputTestFile(opts.path.c_str());
273275
if (input.empty()) {
274-
printf("Failed to read input or empty input: %s\n", opts.path.c_str());
276+
std::cerr << "Invalid input file: " << opts.path << std::endl;
275277
return 3;
276278
}
277279

278280
Json::String basePath = removeSuffix(opts.path, ".json");
279281
if (!opts.parseOnly && basePath.empty()) {
280-
printf("Bad input path. Path does not end with '.expected':\n%s\n",
281-
opts.path.c_str());
282+
std::cerr << "Bad input path '" << opts.path << "'. Must end with '.expected'" << std::endl;
282283
return 3;
283284
}
284285

@@ -312,21 +313,22 @@ int main(int argc, const char* argv[]) {
312313
try {
313314
int exitCode = parseCommandLine(argc, argv, &opts);
314315
if (exitCode != 0) {
315-
printf("Failed to parse command-line.");
316+
std::cerr << "Failed to parse command-line." << std::endl;
316317
return exitCode;
317318
}
318319

319-
// TODO(baylesj): replace this with proper calls to both. Right now
320-
// we only check the legacy if the modern one is not broken.
321-
const int legacy_return_code = runTest(opts, true);
322320
const int modern_return_code = runTest(opts, false);
323321
if (modern_return_code) {
324322
return modern_return_code;
325-
} else {
326-
return legacy_return_code;
323+
}
324+
325+
const std::string filename = opts.path.substr(opts.path.find_last_of("\\/") + 1);
326+
const bool should_run_legacy = (filename.rfind("legacy_", 0) == 0);
327+
if (should_run_legacy) {
328+
return runTest(opts, true);
327329
}
328330
} catch (const std::exception& e) {
329-
printf("Unhandled exception:\n%s\n", e.what());
331+
std::cerr << "Unhandled exception:" << std::endl << e.what() << std::endl;
330332
return 1;
331333
}
332334
}

src/lib_json/json_reader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,14 +1531,14 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) {
15311531
// We assume we can represent the largest and smallest integer types as
15321532
// unsigned integers with separate sign. This is only true if they can fit
15331533
// into an unsigned integer.
1534-
static_assert(Value::maxLargestInt <= Value::maxLargestUInt);
1534+
static_assert(Value::maxLargestInt <= Value::maxLargestUInt, "Int must be smaller than UInt");
15351535

15361536
// We need to convert minLargestInt into a positive number. The easiest way
15371537
// to do this conversion is to assume our "threshold" value of minLargestInt
15381538
// divided by 10 can fit in maxLargestInt when absolute valued. This should
15391539
// be a safe assumption.
1540-
static_assert(Value::minLargestInt <= -Value::maxLargestInt);
1541-
static_assert(Value::minLargestInt / 10 >= -Value::maxLargestInt);
1540+
static_assert(Value::minLargestInt <= -Value::maxLargestInt, "The absolute value of minLargestInt must be greater than or equal to maxLargestInt");
1541+
static_assert(Value::minLargestInt / 10 >= -Value::maxLargestInt, "The absolute value of minLargestInt must be only 1 magnitude larger than maxLargest Int");
15421542

15431543
static constexpr Value::LargestUInt positive_threshold =
15441544
Value::maxLargestUInt / 10;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)