Skip to content

Commit 81578d4

Browse files
committed
relative, proximate: empty output for both inputs empty
1 parent 4af5f84 commit 81578d4

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

src/relative.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ std::string fs_relative_to(std::string_view base, std::string_view other)
1818

1919
std::error_code ec;
2020

21+
if (base.empty() && other.empty())
22+
return "";
23+
2124
#ifdef HAVE_CXX_FILESYSTEM
2225
if(std::string r = Filesystem::relative(other, base, ec).generic_string(); !ec)
2326
return r;
2427
// this implements
25-
// std::filesystem::weakly_canonical(other, ec).lexically_relative(std::filesystem::weakly_canonical(base, ec)).generic_string();
28+
// std::filesystem::weakly_canonical(other, ec).lexically_relative(std::filesystem::weakly_canonical(base, ec));
2629
#else
2730
ec = std::make_error_code(std::errc::function_not_supported);
2831
#endif
@@ -39,6 +42,9 @@ std::string fs_proximate_to(std::string_view base, std::string_view other)
3942

4043
std::error_code ec;
4144

45+
if (base.empty() && other.empty())
46+
return "";
47+
4248
#ifdef HAVE_CXX_FILESYSTEM
4349
if(std::string r = Filesystem::proximate(other, base, ec).generic_string(); !ec)
4450
return r;

test/core/test_proximate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
TEST(TestProximate, Agnostic)
88
{
99

10-
EXPECT_EQ(fs_proximate_to("", ""), ".");
10+
EXPECT_EQ(fs_proximate_to("", ""), "");
1111
EXPECT_EQ(fs_proximate_to("Hello", "Hello"), ".");
1212
EXPECT_EQ(fs_proximate_to("Hello", "Hello/"), ".");
1313
EXPECT_EQ(fs_proximate_to("a/b", "a/b"), ".");

test/core/test_proximate.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ program main
66

77
implicit none
88

9-
if(proximate_to("", "") /= ".") error stop "proximate_to empty failed"
9+
if(proximate_to("", "") /= "") error stop "proximate_to empty failed"
1010

1111
if(proximate_to("Hello", "Hello/") /= ".") error stop "proximate_to same dir failed"
1212

test/core/test_relative.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
TEST(TestRelative, Agnostic)
66
{
77

8-
EXPECT_EQ(fs_relative_to("", ""), ".");
8+
EXPECT_EQ(fs_relative_to("", ""), "");
99
EXPECT_EQ(fs_relative_to("Hello", "Hello"), ".");
1010
EXPECT_EQ(fs_relative_to("Hello", "Hello/"), ".");
1111
EXPECT_EQ(fs_relative_to("a/b", "a/b"), ".");

test/core/test_relative.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ program main
66

77
implicit none
88

9-
if(relative_to("", "") /= ".") error stop "FAIL: relative_to()"
9+
if(relative_to("", "") /= "") error stop "FAIL: relative_to()"
1010

1111
if(relative_to("a/b/c", "a/b") /= "..") error stop "FAIL: relative_to()"
1212

0 commit comments

Comments
 (0)