mirror of
https://github.com/NixOS/nix.git
synced 2025-12-21 00:11:08 +01:00
* It is tough to contribute to a project that doesn't use a formatter, * It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files * Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose, Let's rip the bandaid off? Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
72 lines
2.1 KiB
C++
72 lines
2.1 KiB
C++
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "nix/util/file-content-address.hh"
|
|
|
|
namespace nix {
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
* parseFileSerialisationMethod, renderFileSerialisationMethod
|
|
* --------------------------------------------------------------------------*/
|
|
|
|
TEST(FileSerialisationMethod, testRoundTripPrintParse_1)
|
|
{
|
|
for (const FileSerialisationMethod fim : {
|
|
FileSerialisationMethod::Flat,
|
|
FileSerialisationMethod::NixArchive,
|
|
}) {
|
|
EXPECT_EQ(parseFileSerialisationMethod(renderFileSerialisationMethod(fim)), fim);
|
|
}
|
|
}
|
|
|
|
TEST(FileSerialisationMethod, testRoundTripPrintParse_2)
|
|
{
|
|
for (const std::string_view fimS : {
|
|
"flat",
|
|
"nar",
|
|
}) {
|
|
EXPECT_EQ(renderFileSerialisationMethod(parseFileSerialisationMethod(fimS)), fimS);
|
|
}
|
|
}
|
|
|
|
TEST(FileSerialisationMethod, testParseFileSerialisationMethodOptException)
|
|
{
|
|
EXPECT_THAT(
|
|
[]() { parseFileSerialisationMethod("narwhal"); },
|
|
testing::ThrowsMessage<UsageError>(testing::HasSubstr("narwhal")));
|
|
}
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
* parseFileIngestionMethod, renderFileIngestionMethod
|
|
* --------------------------------------------------------------------------*/
|
|
|
|
TEST(FileIngestionMethod, testRoundTripPrintParse_1)
|
|
{
|
|
for (const FileIngestionMethod fim : {
|
|
FileIngestionMethod::Flat,
|
|
FileIngestionMethod::NixArchive,
|
|
FileIngestionMethod::Git,
|
|
}) {
|
|
EXPECT_EQ(parseFileIngestionMethod(renderFileIngestionMethod(fim)), fim);
|
|
}
|
|
}
|
|
|
|
TEST(FileIngestionMethod, testRoundTripPrintParse_2)
|
|
{
|
|
for (const std::string_view fimS : {
|
|
"flat",
|
|
"nar",
|
|
"git",
|
|
}) {
|
|
EXPECT_EQ(renderFileIngestionMethod(parseFileIngestionMethod(fimS)), fimS);
|
|
}
|
|
}
|
|
|
|
TEST(FileIngestionMethod, testParseFileIngestionMethodOptException)
|
|
{
|
|
EXPECT_THAT(
|
|
[]() { parseFileIngestionMethod("narwhal"); },
|
|
testing::ThrowsMessage<UsageError>(testing::HasSubstr("narwhal")));
|
|
}
|
|
|
|
} // namespace nix
|