ASSERT_STREQ(str.c_str(),"\x1B[32;1minfo:\x1B[0m\x1B[34;1m --- Info name ------------------------------------- error-unit-test\x1B[0m\nInfo description\n");
.hint=hintfmt("this hint has %1% templated %2%!!",
"yellow",
"values"),
.nixCode=NixCode{
.errPos=Pos(problem_file,40,13),
.prevLineOfCode="previous line of code",
.errLineOfCode="this is the problem line of code",
.nextLineOfCode="next line of code",
}});
autostr=testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(),"\x1B[31;1merror:\x1B[0m\x1B[34;1m --- error name ----------------------------------- error-unit-test\x1B[0m\nin file: \x1B[34;1mmyfile.nix (40:13)\x1B[0m\n\nerror with code lines\n\n 39| previous line of code\n 40| this is the problem line of code\n | \x1B[31;1m^\x1B[0m\n 41| next line of code\n\nthis hint has \x1B[33;1myellow\x1B[0m templated \x1B[33;1mvalues\x1B[0m!!\n");
}
TEST(logError,logErrorWithoutLinesOfCode){
SymbolTabletestTable;
autoproblem_file=testTable.create("myfile.nix");
testing::internal::CaptureStderr();
logError({
.name="error name",
.description="error without any code lines.",
.hint=hintfmt("this hint has %1% templated %2%!!",
"yellow",
"values"),
.nixCode=NixCode{
.errPos=Pos(problem_file,40,13)
}});
autostr=testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(),"\x1B[31;1merror:\x1B[0m\x1B[34;1m --- error name ----------------------------------- error-unit-test\x1B[0m\nin file: \x1B[34;1mmyfile.nix (40:13)\x1B[0m\n\nerror without any code lines.\n\nthis hint has \x1B[33;1myellow\x1B[0m templated \x1B[33;1mvalues\x1B[0m!!\n");
}
TEST(logError,logErrorWithOnlyHintAndName){
SymbolTabletestTable;
autoproblem_file=testTable.create("myfile.nix");
testing::internal::CaptureStderr();
logError({
.name="error name",
.hint=hintfmt("hint %1%","only"),
.nixCode=NixCode{
.errPos=Pos(problem_file,40,13)
}});
autostr=testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(),"\x1B[31;1merror:\x1B[0m\x1B[34;1m --- error name ----------------------------------- error-unit-test\x1B[0m\nin file: \x1B[34;1mmyfile.nix (40:13)\x1B[0m\n\nhint \x1B[33;1monly\x1B[0m\n");
ASSERT_STREQ(str.c_str(),"\x1B[33;1mwarning:\x1B[0m\x1B[34;1m --- name --------------------------------------- error-unit-test\x1B[0m\nerror description\n\nthere was a \x1B[33;1mwarning\x1B[0m\n");
.hint=hintfmt("this hint has %1% templated %2%!!",
"yellow",
"values"),
.nixCode=NixCode{
.errPos=Pos(problem_file,40,13),
.prevLineOfCode=std::nullopt,
.errLineOfCode="this is the problem line of code",
.nextLineOfCode=std::nullopt
}});
autostr=testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(),"\x1B[33;1mwarning:\x1B[0m\x1B[34;1m --- warning name ------------------------------- error-unit-test\x1B[0m\nin file: \x1B[34;1mmyfile.nix (40:13)\x1B[0m\n\nwarning description\n\n 40| this is the problem line of code\n | \x1B[31;1m^\x1B[0m\n\nthis hint has \x1B[33;1myellow\x1B[0m templated \x1B[33;1mvalues\x1B[0m!!\n");