diff --git a/src/libutil-tests/file-content-address.cc b/src/libutil-tests/file-content-address.cc index 5cdf94edc..92c6059a4 100644 --- a/src/libutil-tests/file-content-address.cc +++ b/src/libutil-tests/file-content-address.cc @@ -1,3 +1,4 @@ +#include #include #include "nix/util/file-content-address.hh" @@ -26,8 +27,11 @@ TEST(FileSerialisationMethod, testRoundTripPrintParse_2) { } } -TEST(FileSerialisationMethod, testParseFileSerialisationMethodOptException) { - EXPECT_THROW(parseFileSerialisationMethod("narwhal"), UsageError); +TEST(FileSerialisationMethod, testParseFileSerialisationMethodOptException) +{ + EXPECT_THAT( + []() { parseFileSerialisationMethod("narwhal"); }, + testing::ThrowsMessage(testing::HasSubstr("narwhal"))); } /* ---------------------------------------------------------------------------- @@ -54,8 +58,11 @@ TEST(FileIngestionMethod, testRoundTripPrintParse_2) { } } -TEST(FileIngestionMethod, testParseFileIngestionMethodOptException) { - EXPECT_THROW(parseFileIngestionMethod("narwhal"), UsageError); +TEST(FileIngestionMethod, testParseFileIngestionMethodOptException) +{ + EXPECT_THAT( + []() { parseFileIngestionMethod("narwhal"); }, + testing::ThrowsMessage(testing::HasSubstr("narwhal"))); } } diff --git a/src/libutil/file-content-address.cc b/src/libutil/file-content-address.cc index 673e1dff1..142bc70d5 100644 --- a/src/libutil/file-content-address.cc +++ b/src/libutil/file-content-address.cc @@ -22,7 +22,7 @@ FileSerialisationMethod parseFileSerialisationMethod(std::string_view input) if (ret) return *ret; else - throw UsageError("Unknown file serialiation method '%s', expect `flat` or `nar`"); + throw UsageError("Unknown file serialiation method '%s', expect `flat` or `nar`", input); } @@ -35,7 +35,7 @@ FileIngestionMethod parseFileIngestionMethod(std::string_view input) if (ret) return static_cast(*ret); else - throw UsageError("Unknown file ingestion method '%s', expect `flat`, `nar`, or `git`"); + throw UsageError("Unknown file ingestion method '%s', expect `flat`, `nar`, or `git`", input); } }