diff --git a/ocov.cc b/ocov.cc index e1f427e..f1d6a33 100644 --- a/ocov.cc +++ b/ocov.cc @@ -64,11 +64,15 @@ CURRENT_STRUCT(OCOVFile) { CURRENT_FIELD(coverage, Optional); }; -CURRENT_STRUCT(OCOV) { +CURRENT_STRUCT(OPATestInput) { CURRENT_FIELD(files, (std::map)); CURRENT_FIELD(coverage, Optional); }; +CURRENT_STRUCT(OPAEvalInput) { + CURRENT_FIELD(coverage, OPATestInput); +}; + int main(int argc, char** argv) { ParseDFlags(&argc, &argv); if (FLAGS_version || FLAGS_v) { @@ -77,7 +81,24 @@ int main(int argc, char** argv) { } try { - OCOV const ocov = ParseJSON(ReadInput()); + std::string const input = ReadInput(); + OPATestInput ocov; + std::string test_or_eval; + auto as_test_input = TryParseJSON(input); + if (Exists(as_test_input)) { + test_or_eval = "test"; + ocov = std::move(Value(as_test_input)); + } else { + auto as_eval_input = TryParseJSON(input); + if (Exists(as_eval_input)) { + test_or_eval = "eval"; + ocov = std::move(Value(as_eval_input).coverage); + } + } + if (test_or_eval.empty()) { + std::cerr << red << bold << "The input should be from `opa test` or from `opa eval`." << reset << std::endl; + std::exit(1); + } bool first = true; for (auto const& file : ocov.files) { if (!first) { @@ -87,8 +108,8 @@ int main(int argc, char** argv) { } std::cout << bold << "# " << blue << file.first << reset << std::endl; if (Exists(file.second.coverage)) { - std::cout << bold << "# " << yellow << "file test coverage: " << Value(file.second.coverage) << '%' << reset - << std::endl; + std::cout << bold << "# " << yellow << "file " << test_or_eval + << " coverage: " << Value(file.second.coverage) << '%' << reset << std::endl; } try { std::string const filename = current::FileSystem::JoinPath(FLAGS_basedir, file.first); @@ -147,8 +168,8 @@ int main(int argc, char** argv) { } if (Exists(ocov.coverage)) { std::cout << std::endl - << bold << "# " << yellow << "total test coverage: " << Value(ocov.coverage) << '%' << reset - << std::endl; + << bold << "# " << yellow << "total " << test_or_eval + << " coverage: " << Value(ocov.coverage) << '%' << reset << std::endl; } return 0; } catch (current::Exception const& e) {