2023-01-10 16:27:19 +00:00
|
|
|
#include "outputs-spec.hh"
|
2022-04-22 13:17:01 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-01-11 22:31:32 +00:00
|
|
|
#define TEST_DONT_PARSE(NAME, STR) \
|
|
|
|
TEST(OutputsSpec, bad_ ## NAME) { \
|
|
|
|
std::optional OutputsSpecOpt = \
|
|
|
|
OutputsSpec::parseOpt(STR); \
|
|
|
|
ASSERT_FALSE(OutputsSpecOpt); \
|
2023-01-11 23:57:18 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 22:31:32 +00:00
|
|
|
TEST_DONT_PARSE(empty, "")
|
|
|
|
TEST_DONT_PARSE(garbage, "&*()")
|
|
|
|
TEST_DONT_PARSE(double_star, "**")
|
|
|
|
TEST_DONT_PARSE(star_first, "*,foo")
|
|
|
|
TEST_DONT_PARSE(star_second, "foo,*")
|
2023-01-11 23:57:18 +00:00
|
|
|
|
2023-01-11 22:31:32 +00:00
|
|
|
#undef TEST_DONT_PARSE
|
2023-01-11 23:57:18 +00:00
|
|
|
|
2023-01-11 22:31:32 +00:00
|
|
|
TEST(OutputsSpec, all) {
|
|
|
|
std::string_view str = "*";
|
|
|
|
OutputsSpec expected = OutputsSpec::All { };
|
|
|
|
ASSERT_EQ(OutputsSpec::parse(str), expected);
|
|
|
|
ASSERT_EQ(expected.to_string(), str);
|
2023-01-11 23:57:18 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 22:31:32 +00:00
|
|
|
TEST(OutputsSpec, names_out) {
|
|
|
|
std::string_view str = "out";
|
|
|
|
OutputsSpec expected = OutputsSpec::Names { "out" };
|
|
|
|
ASSERT_EQ(OutputsSpec::parse(str), expected);
|
|
|
|
ASSERT_EQ(expected.to_string(), str);
|
|
|
|
}
|
2023-01-11 23:57:18 +00:00
|
|
|
|
2023-01-11 22:31:32 +00:00
|
|
|
TEST(OutputsSpec, names_out_bin) {
|
|
|
|
OutputsSpec expected = OutputsSpec::Names { "out", "bin" };
|
|
|
|
ASSERT_EQ(OutputsSpec::parse("out,bin"), expected);
|
|
|
|
// N.B. This normalization is OK.
|
|
|
|
ASSERT_EQ(expected.to_string(), "bin,out");
|
|
|
|
}
|
2022-04-22 13:17:01 +00:00
|
|
|
|
|
|
|
|
2023-01-11 22:31:32 +00:00
|
|
|
#define TEST_DONT_PARSE(NAME, STR) \
|
|
|
|
TEST(ExtendedOutputsSpec, bad_ ## NAME) { \
|
|
|
|
std::optional extendedOutputsSpecOpt = \
|
|
|
|
ExtendedOutputsSpec::parseOpt(STR); \
|
|
|
|
ASSERT_FALSE(extendedOutputsSpecOpt); \
|
2022-04-22 13:17:01 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 22:31:32 +00:00
|
|
|
TEST_DONT_PARSE(carot_empty, "^")
|
|
|
|
TEST_DONT_PARSE(prefix_carot_empty, "foo^")
|
2022-04-22 13:17:01 +00:00
|
|
|
|
2023-01-11 22:31:32 +00:00
|
|
|
#undef TEST_DONT_PARSE
|
|
|
|
|
|
|
|
TEST(ExtendedOutputsSpec, defeault) {
|
|
|
|
std::string_view str = "foo";
|
|
|
|
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse(str);
|
|
|
|
ASSERT_EQ(prefix, "foo");
|
|
|
|
ExtendedOutputsSpec expected = ExtendedOutputsSpec::Default { };
|
|
|
|
ASSERT_EQ(extendedOutputsSpec, expected);
|
|
|
|
ASSERT_EQ(std::string { prefix } + expected.to_string(), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ExtendedOutputsSpec, all) {
|
|
|
|
std::string_view str = "foo^*";
|
|
|
|
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse(str);
|
|
|
|
ASSERT_EQ(prefix, "foo");
|
|
|
|
ExtendedOutputsSpec expected = OutputsSpec::All { };
|
|
|
|
ASSERT_EQ(extendedOutputsSpec, expected);
|
|
|
|
ASSERT_EQ(std::string { prefix } + expected.to_string(), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ExtendedOutputsSpec, out) {
|
|
|
|
std::string_view str = "foo^out";
|
|
|
|
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse(str);
|
|
|
|
ASSERT_EQ(prefix, "foo");
|
|
|
|
ExtendedOutputsSpec expected = OutputsSpec::Names { "out" };
|
|
|
|
ASSERT_EQ(extendedOutputsSpec, expected);
|
|
|
|
ASSERT_EQ(std::string { prefix } + expected.to_string(), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ExtendedOutputsSpec, out_bin) {
|
|
|
|
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^out,bin");
|
|
|
|
ASSERT_EQ(prefix, "foo");
|
|
|
|
ExtendedOutputsSpec expected = OutputsSpec::Names { "out", "bin" };
|
|
|
|
ASSERT_EQ(extendedOutputsSpec, expected);
|
|
|
|
ASSERT_EQ(std::string { prefix } + expected.to_string(), "foo^bin,out");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ExtendedOutputsSpec, many_carrot) {
|
|
|
|
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^bar^out,bin");
|
|
|
|
ASSERT_EQ(prefix, "foo^bar");
|
|
|
|
ExtendedOutputsSpec expected = OutputsSpec::Names { "out", "bin" };
|
|
|
|
ASSERT_EQ(extendedOutputsSpec, expected);
|
|
|
|
ASSERT_EQ(std::string { prefix } + expected.to_string(), "foo^bar^bin,out");
|
2022-04-22 13:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|