| 1278 | } |
| 1279 | |
| 1280 | void CommandCompare::executeCompare() { |
| 1281 | InputStreams inputStreams{ |
| 1282 | InputStream(options.inputFilepaths[0], *this), |
| 1283 | InputStream(options.inputFilepaths[1], *this), |
| 1284 | }; |
| 1285 | |
| 1286 | std::vector<std::string> validationMessages; |
| 1287 | std::vector<int> validationResults; |
| 1288 | |
| 1289 | switch (options.format) { |
| 1290 | case OutputFormat::text: { |
| 1291 | for (std::size_t i = 0; i < inputStreams.size(); ++i) { |
| 1292 | std::ostringstream messagesOS; |
| 1293 | validationResults.emplace_back(validateIOStream(inputStreams[i], fmtInFile(options.inputFilepaths[i]), |
| 1294 | false, false, [&](const ValidationReport& issue) { |
| 1295 | fmt::print(messagesOS, "{}-{:04}: {}\n", toString(issue.type), issue.id, issue.message); |
| 1296 | fmt::print(messagesOS, " {}\n", issue.details); |
| 1297 | })); |
| 1298 | |
| 1299 | validationMessages.emplace_back(std::move(messagesOS).str()); |
| 1300 | } |
| 1301 | |
| 1302 | bool hasValidationMessages = false; |
| 1303 | for (std::size_t i = 0; i < inputStreams.size(); ++i) { |
| 1304 | if (!validationMessages[i].empty()) { |
| 1305 | if (std::exchange(hasValidationMessages, true)) |
| 1306 | fmt::print("\n"); |
| 1307 | |
| 1308 | fmt::print("Validation {} for '{}'\n", validationResults[i] == 0 ? "successful" : "failed", |
| 1309 | options.inputFilepaths[i]); |
| 1310 | fmt::print("\n"); |
| 1311 | fmt::print("{}", validationMessages[i]); |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | for (std::size_t i = 0; i < inputStreams.size(); ++i) { |
| 1316 | if (validationResults[i] != 0) { |
| 1317 | if (validationResults[i] != +rc::INVALID_FILE || !options.allowInvalidInput) |
| 1318 | throw FatalError(ReturnCode{validationResults[i]}); |
| 1319 | |
| 1320 | // Image comparison is only supported for valid input files |
| 1321 | options.contentMode = ContentMode::ignore; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | if (hasValidationMessages) |
| 1326 | fmt::print("\n"); |
| 1327 | |
| 1328 | PrintIndent out{std::cout}; |
| 1329 | PrintDiff diff(out, options.format); |
| 1330 | compareHeader(diff, inputStreams); |
| 1331 | compareLevelIndex(diff, inputStreams); |
| 1332 | compareDFD(diff, inputStreams); |
| 1333 | compareKVD(diff, inputStreams); |
| 1334 | compareSGD(diff, inputStreams); |
| 1335 | compareImages(diff, inputStreams); |
| 1336 | |
| 1337 | if (diff.isDifferent()) |
nothing calls this directly
no test coverage detected