1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-07 01:21:00 +01:00
nix/src/libutil-tests/archive.cc
Samuel Connelly 7a05ed9c12 libutil: Throw if str("contents") not found
This was broken in 7aa3e7e3a5 (since 2.25).

(cherry picked from commit 242f362567)
2025-10-07 21:33:19 +00:00

47 lines
1.2 KiB
C++

#include "nix/util/archive.hh"
#include "nix/util/tests/characterization.hh"
#include "nix/util/tests/gmock-matchers.hh"
#include <gtest/gtest.h>
namespace nix {
namespace {
class NarTest : public CharacterizationTest
{
std::filesystem::path unitTestData = getUnitTestData() / "nars";
public:
std::filesystem::path goldenMaster(std::string_view testStem) const override
{
return unitTestData / (std::string(testStem) + ".nar");
}
};
class InvalidNarTest : public NarTest, public ::testing::WithParamInterface<std::tuple<std::string, std::string>>
{};
} // namespace
TEST_P(InvalidNarTest, throwsErrorMessage)
{
const auto & [name, message] = GetParam();
readTest(name, [&](const std::string & narContents) {
ASSERT_THAT(
[&]() {
StringSource source{narContents};
NullFileSystemObjectSink sink;
parseDump(sink, source);
},
::testing::ThrowsMessage<SerialisationError>(testing::HasSubstrIgnoreANSIMatcher(message)));
});
}
INSTANTIATE_TEST_SUITE_P(
NarTest,
InvalidNarTest,
::testing::Values(
std::pair{"invalid-tag-instead-of-contents", "bad archive: expected tag 'contents', got 'AAAAAAAA'"}));
} // namespace nix