mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
libutil: Throw if str("contents") not found
This was broken in 7aa3e7e3a5 (since 2.25).
This commit is contained in:
parent
1e709554d5
commit
242f362567
4 changed files with 52 additions and 2 deletions
47
src/libutil-tests/archive.cc
Normal file
47
src/libutil-tests/archive.cc
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#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
|
||||
BIN
src/libutil-tests/data/nars/invalid-tag-instead-of-contents.nar
Normal file
BIN
src/libutil-tests/data/nars/invalid-tag-instead-of-contents.nar
Normal file
Binary file not shown.
|
|
@ -45,6 +45,7 @@ subdir('nix-meson-build-support/common')
|
|||
subdir('nix-meson-build-support/asan-options')
|
||||
|
||||
sources = files(
|
||||
'archive.cc',
|
||||
'args.cc',
|
||||
'base-n.cc',
|
||||
'canon-path.cc',
|
||||
|
|
|
|||
|
|
@ -187,8 +187,10 @@ static void parse(FileSystemObjectSink & sink, Source & source, const CanonPath
|
|||
tag = getString();
|
||||
}
|
||||
|
||||
if (tag == "contents")
|
||||
parseContents(crf, source);
|
||||
if (tag != "contents")
|
||||
throw badArchive("expected tag 'contents', got '%s'", tag);
|
||||
|
||||
parseContents(crf, source);
|
||||
|
||||
expectTag(")");
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue