From b53e84b08d98ac03ffa7aa4500db9701c7b0b88f Mon Sep 17 00:00:00 2001 From: iWas-Coder Date: Sat, 20 Jul 2024 20:59:39 +0200 Subject: [PATCH] Output git-style diff between original test code and generated one --- .gitignore | 1 + ai/testgen.cc | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 9cf433c..a05c0f3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ ai/build/ *.xml test/carbon ai/testgen +ai/*.diff diff --git a/ai/testgen.cc b/ai/testgen.cc index c9105b2..87a6875 100644 --- a/ai/testgen.cc +++ b/ai/testgen.cc @@ -171,4 +171,12 @@ int main(int argc, char **argv) { std::cout << "\n\n2. It builds?:" << std::endl; if (it_builds(buf)) std::cout << "Yes. Hurray!" << std::endl; else std::cout << "No. Maybe next time..." << std::endl; + + std::ofstream ofs { "tmp.cc" }; + if (not ofs) throw std::runtime_error { "unable to open/create file for writing (`./tmp.cc`)" }; + ofs << buf.str(); + ofs.close(); + [[maybe_unused]] int result { std::system(("diff -u " + test_file + " tmp.cc > testgen.diff").c_str()) }; + std::remove("tmp.cc"); + std::cout << "\nOutput from BSD Carbon AI written to: `testgen.diff`" << std::endl; }