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 23:57:18 +00:00
|
|
|
TEST(OutputsSpec_parse, basic)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto outputsSpec = OutputsSpec::parse("*");
|
|
|
|
ASSERT_TRUE(std::get_if<OutputsSpec::All>(&outputsSpec));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto outputsSpec = OutputsSpec::parse("out");
|
|
|
|
ASSERT_TRUE(std::get<OutputsSpec::Names>(outputsSpec) == OutputsSpec::Names({"out"}));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto outputsSpec = OutputsSpec::parse("out,bin");
|
|
|
|
ASSERT_TRUE(std::get<OutputsSpec::Names>(outputsSpec) == OutputsSpec::Names({"out", "bin"}));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::optional outputsSpecOpt = OutputsSpec::parseOpt("&*()");
|
|
|
|
ASSERT_FALSE(outputsSpecOpt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-11 07:00:44 +00:00
|
|
|
TEST(ExtendedOutputsSpec_parse, basic)
|
2022-04-22 13:17:01 +00:00
|
|
|
{
|
|
|
|
{
|
2023-01-11 07:00:44 +00:00
|
|
|
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo");
|
2022-04-22 13:17:01 +00:00
|
|
|
ASSERT_EQ(prefix, "foo");
|
2023-01-11 23:57:18 +00:00
|
|
|
ASSERT_TRUE(std::get_if<ExtendedOutputsSpec::Default>(&extendedOutputsSpec));
|
2022-04-22 13:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-01-11 07:00:44 +00:00
|
|
|
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^*");
|
2022-04-22 13:17:01 +00:00
|
|
|
ASSERT_EQ(prefix, "foo");
|
2023-01-11 23:57:18 +00:00
|
|
|
auto * explicit_p = std::get_if<ExtendedOutputsSpec::Explicit>(&extendedOutputsSpec);
|
|
|
|
ASSERT_TRUE(explicit_p);
|
|
|
|
ASSERT_TRUE(std::get_if<OutputsSpec::All>(explicit_p));
|
2022-04-22 13:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-01-11 07:00:44 +00:00
|
|
|
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^out");
|
2022-04-22 13:17:01 +00:00
|
|
|
ASSERT_EQ(prefix, "foo");
|
2023-01-11 23:57:18 +00:00
|
|
|
ASSERT_TRUE(std::get<OutputsSpec::Names>(std::get<ExtendedOutputsSpec::Explicit>(extendedOutputsSpec)) == OutputsSpec::Names({"out"}));
|
2022-04-22 13:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-01-11 07:00:44 +00:00
|
|
|
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^out,bin");
|
2022-04-22 13:17:01 +00:00
|
|
|
ASSERT_EQ(prefix, "foo");
|
2023-01-11 23:57:18 +00:00
|
|
|
ASSERT_TRUE(std::get<OutputsSpec::Names>(std::get<ExtendedOutputsSpec::Explicit>(extendedOutputsSpec)) == OutputsSpec::Names({"out", "bin"}));
|
2022-04-22 13:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-01-11 07:00:44 +00:00
|
|
|
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^bar^out,bin");
|
2022-04-22 13:17:01 +00:00
|
|
|
ASSERT_EQ(prefix, "foo^bar");
|
2023-01-11 23:57:18 +00:00
|
|
|
ASSERT_TRUE(std::get<OutputsSpec::Names>(std::get<ExtendedOutputsSpec::Explicit>(extendedOutputsSpec)) == OutputsSpec::Names({"out", "bin"}));
|
2022-04-22 13:17:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|