summaryrefslogtreecommitdiffstats
path: root/src/libutil/tests/logging.cc
diff options
context:
space:
mode:
authorBen Burdette <bburdette@gmail.com>2020-06-24 18:31:28 -0600
committerBen Burdette <bburdette@gmail.com>2020-06-24 18:31:28 -0600
commit9c0e1fd4f1151f4780c1ff3db82322d8b28d2d8b (patch)
treeff3d33ed21cd910552be469a8cc6495f064c1d87 /src/libutil/tests/logging.cc
parent6359d71d6b6110ce3608cfd289cae5143e78f123 (diff)
add trace test; error formatting refinements
Diffstat (limited to 'src/libutil/tests/logging.cc')
-rw-r--r--src/libutil/tests/logging.cc33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/libutil/tests/logging.cc b/src/libutil/tests/logging.cc
index 0bbec482f..6d0431133 100644
--- a/src/libutil/tests/logging.cc
+++ b/src/libutil/tests/logging.cc
@@ -11,12 +11,12 @@ namespace nix {
* logEI
* --------------------------------------------------------------------------*/
- const char *test_file =
+ const char *test_file =
"previous line of code\n"
"this is the problem line of code\n"
"next line of code\n";
- const char *one_liner =
- "this is the problem line of code";
+ const char *one_liner =
+ "this is the other problem line of code";
TEST(logEI, catpuresBasicProperties) {
@@ -246,6 +246,33 @@ namespace nix {
}
/* ----------------------------------------------------------------------------
+ * traces
+ * --------------------------------------------------------------------------*/
+
+ TEST(addTrace, showTracesWithShowTrace) {
+ SymbolTable testTable;
+ auto problem_file = testTable.create(test_file);
+
+ auto oneliner_file = testTable.create(one_liner);
+
+ auto e = AssertionError(ErrorInfo {
+ .name = "wat",
+ .description = "a well-known problem occurred",
+ .hint = hintfmt("it has been %1% days since our last error", "zero"),
+ .errPos = Pos(foString, problem_file, 2, 13),
+ });
+
+ e.addTrace(Pos(foStdin, oneliner_file, 1, 19), "while trying to compute %1%", 42);
+
+ testing::internal::CaptureStderr();
+
+ logError(e.info());
+
+ auto str = testing::internal::GetCapturedStderr();
+ ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- AssertionError --- error-unit-test\x1B[0m\n\x1B[34;1mat: \x1B[33;1m(2:13)\x1B[34;1m from command line argument\x1B[0m\n\na well-known problem occurred\n\n 1| previous line of code\n 2| this is the problem line of code\n | \x1B[31;1m^\x1B[0m\n 3| next line of code\n\nit has been \x1B[33;1mzero\x1B[0m days since our last error\n\x1B[34;1m--- show-trace output ---\nwhile trying to compute \x1B[33;1m42\x1B[0m\n\x1B[34;1mat: \x1B[33;1m(1:19)\x1B[34;1m from stdin\x1B[0m\n 1| this is the other problem line of code\n | \x1B[31;1m^\x1B[0m\n");
+ }
+
+ /* ----------------------------------------------------------------------------
* hintfmt
* --------------------------------------------------------------------------*/