From c0ccc9cbff70f388d2c5f2c231db99fb38cf14d5 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 14 Jan 2025 14:55:13 -0800 Subject: [PATCH] core: Improve test error messages when files not found --- src/core/model/ascii-test.h | 19 ++++++++++++++----- src/core/model/example-as-test.cc | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/core/model/ascii-test.h b/src/core/model/ascii-test.h index b3674b028..3a44d38ab 100644 --- a/src/core/model/ascii-test.h +++ b/src/core/model/ascii-test.h @@ -14,6 +14,7 @@ #include "ascii-file.h" #include "test.h" +#include #include /** @@ -28,11 +29,19 @@ do \ { \ uint64_t line(0); \ - bool diff = AsciiFile::Diff(gotFilename, expectedFilename, line); \ - NS_TEST_EXPECT_MSG_EQ(diff, \ - false, \ - "ASCII traces " << gotFilename << " and " << expectedFilename \ - << " differ starting from line " << line); \ + bool fileExists = std::filesystem::exists(expectedFilename); \ + if (fileExists) \ + { \ + bool diff = AsciiFile::Diff(gotFilename, expectedFilename, line); \ + NS_TEST_EXPECT_MSG_EQ(diff, \ + false, \ + "ASCII traces " << gotFilename << " and " << expectedFilename \ + << " differ starting from line " << line); \ + } \ + else \ + { \ + NS_TEST_EXPECT_MSG_EQ(fileExists, true, "File " << expectedFilename << " not found"); \ + } \ } while (false) #endif /* ASCII_TEST_H */ diff --git a/src/core/model/example-as-test.cc b/src/core/model/example-as-test.cc index 93d644dfb..ba246c034 100644 --- a/src/core/model/example-as-test.cc +++ b/src/core/model/example-as-test.cc @@ -122,7 +122,7 @@ ExampleAsTestCase::DoRun() if (m_shouldNotErr) { // Make sure the example didn't outright crash - NS_TEST_ASSERT_MSG_EQ(status, 0, "example " + m_program + " failed"); + NS_TEST_ASSERT_MSG_EQ(status, 0, "example " + m_program + " exited abnormally"); } // If we're just introspecting the command-line