mirror of
https://github.com/NixOS/nix.git
synced 2025-11-18 16:29:36 +01:00
libfetchers: Restore path separator ignoring behavior for indirect and git-archive flakerefs
Old versions of nix happily accepted a lot of weird flake references,
which we didn't have tests for, so this was accidentally broken in
c436b7a32a.
This patch restores previous behavior and adds a plethora of tests
to ensure we don't break this in the future.
These test cases are aligned with how 2.18/2.28 parsed flake references.
This commit is contained in:
parent
511d885d60
commit
a38ebdd511
5 changed files with 184 additions and 2 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include <ranges>
|
||||
|
||||
namespace nix {
|
||||
|
||||
/* ----------- tests for url.hh --------------------------------------------------*/
|
||||
|
|
@ -686,7 +688,102 @@ TEST(parseURL, gitlabNamespacedProjectUrls)
|
|||
ASSERT_EQ(s, parsed.to_string());
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* pathSegments
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
struct ParsedURLPathSegmentsTestCase
|
||||
{
|
||||
std::string url;
|
||||
std::vector<std::string> segments;
|
||||
std::string path;
|
||||
bool skipEmpty;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
class ParsedURLPathSegmentsTest : public ::testing::TestWithParam<ParsedURLPathSegmentsTestCase>
|
||||
{};
|
||||
|
||||
TEST_P(ParsedURLPathSegmentsTest, segmentsAreCorrect)
|
||||
{
|
||||
const auto & testCase = GetParam();
|
||||
auto segments = parseURL(testCase.url).pathSegments(/*skipEmpty=*/testCase.skipEmpty)
|
||||
| std::ranges::to<decltype(testCase.segments)>();
|
||||
EXPECT_EQ(segments, testCase.segments);
|
||||
EXPECT_EQ(encodeUrlPath(segments), testCase.path);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
ParsedURL,
|
||||
ParsedURLPathSegmentsTest,
|
||||
::testing::Values(
|
||||
ParsedURLPathSegmentsTestCase{
|
||||
.url = "scheme:",
|
||||
.segments = {""},
|
||||
.path = "",
|
||||
.skipEmpty = false,
|
||||
.description = "no_authority_empty_path",
|
||||
},
|
||||
ParsedURLPathSegmentsTestCase{
|
||||
.url = "scheme://",
|
||||
.segments = {""},
|
||||
.path = "",
|
||||
.skipEmpty = false,
|
||||
.description = "empty_authority_empty_path",
|
||||
},
|
||||
ParsedURLPathSegmentsTestCase{
|
||||
.url = "scheme:///",
|
||||
.segments = {"", ""},
|
||||
.path = "/",
|
||||
.skipEmpty = false,
|
||||
.description = "empty_authority_empty_path_trailing",
|
||||
},
|
||||
ParsedURLPathSegmentsTestCase{
|
||||
.url = "scheme://example.com/",
|
||||
.segments = {"", ""},
|
||||
.path = "/",
|
||||
.skipEmpty = false,
|
||||
.description = "non_empty_authority_empty_path",
|
||||
},
|
||||
ParsedURLPathSegmentsTestCase{
|
||||
.url = "scheme://example.com//",
|
||||
.segments = {"", "", ""},
|
||||
.path = "//",
|
||||
.skipEmpty = false,
|
||||
.description = "non_empty_authority_non_empty_path",
|
||||
},
|
||||
ParsedURLPathSegmentsTestCase{
|
||||
.url = "scheme://example.com///path///with//strange/empty///segments////",
|
||||
.segments = {"path", "with", "strange", "empty", "segments"},
|
||||
.path = "path/with/strange/empty/segments",
|
||||
.skipEmpty = true,
|
||||
.description = "skip_all_empty_segments_with_authority",
|
||||
},
|
||||
ParsedURLPathSegmentsTestCase{
|
||||
.url = "scheme://example.com///lots///empty///",
|
||||
.segments = {"", "", "", "lots", "", "", "empty", "", "", ""},
|
||||
.path = "///lots///empty///",
|
||||
.skipEmpty = false,
|
||||
.description = "empty_segments_with_authority",
|
||||
},
|
||||
ParsedURLPathSegmentsTestCase{
|
||||
.url = "scheme:/path///with//strange/empty///segments////",
|
||||
.segments = {"path", "with", "strange", "empty", "segments"},
|
||||
.path = "path/with/strange/empty/segments",
|
||||
.skipEmpty = true,
|
||||
.description = "skip_all_empty_segments_no_authority_starts_with_slash",
|
||||
},
|
||||
ParsedURLPathSegmentsTestCase{
|
||||
.url = "scheme:path///with//strange/empty///segments////",
|
||||
.segments = {"path", "with", "strange", "empty", "segments"},
|
||||
.path = "path/with/strange/empty/segments",
|
||||
.skipEmpty = true,
|
||||
.description = "skip_all_empty_segments_no_authority_doesnt_start_with_slash",
|
||||
}),
|
||||
[](const auto & info) { return info.param.description; });
|
||||
|
||||
TEST(nix, isValidSchemeName)
|
||||
|
||||
{
|
||||
ASSERT_TRUE(isValidSchemeName("http"));
|
||||
ASSERT_TRUE(isValidSchemeName("https"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue