Skip to content

Commit 81db3c3

Browse files
committed
[libcxx] [test] Fix all remaining issues with fs::path::string_type being wstring
Use fs::path as variable type instead of std::string, when the input potentially is a path, as they can't be implicitly converted back to string. Differential Revision: https://reviews.llvm.org/D89674
1 parent 5c39eeb commit 81db3c3

File tree

13 files changed

+36
-25
lines changed

13 files changed

+36
-25
lines changed

libcxx/test/std/input.output/filesystems/class.path/path.itr/iterator.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ void checkIteratorConcepts() {
4949
ASSERT_SAME_TYPE(It, decltype(it--));
5050
ASSERT_SAME_TYPE(Traits::reference, decltype(*it));
5151
ASSERT_SAME_TYPE(Traits::pointer, decltype(it.operator->()));
52+
#ifdef _WIN32
53+
ASSERT_SAME_TYPE(std::wstring const&, decltype(it->native()));
54+
#else
5255
ASSERT_SAME_TYPE(std::string const&, decltype(it->native()));
56+
#endif
5357
ASSERT_SAME_TYPE(bool, decltype(it == it));
5458
ASSERT_SAME_TYPE(bool, decltype(it != it));
5559
}

libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/braced_init.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ int main(int, char**) {
2626
using namespace fs;
2727
path p("abc");
2828
p = {};
29+
#ifdef _WIN32
30+
assert(p.native() == L"");
31+
#else
2932
assert(p.native() == "");
33+
#endif
3034

3135
return 0;
3236
}

libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/source.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
template <class CharT>
3636
void RunTestCase(MultiStringType const& MS) {
3737
using namespace fs;
38-
const char* Expect = MS;
38+
const fs::path::value_type* Expect = MS;
3939
const CharT* TestPath = MS;
4040
const CharT* TestPathEnd = StrEnd(TestPath);
4141
const std::size_t Size = TestPathEnd - TestPath;
@@ -211,9 +211,9 @@ void test_sfinae() {
211211
}
212212
}
213213

214-
void RunStringMoveTest(const char* Expect) {
214+
void RunStringMoveTest(const fs::path::value_type* Expect) {
215215
using namespace fs;
216-
std::string ss(Expect);
216+
fs::path::string_type ss(Expect);
217217
path p;
218218
{
219219
DisableAllocationGuard g; ((void)g);

libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
#include "verbose_assert.h"
5656

5757
struct ComparePathExact {
58-
bool operator()(std::string const& LHS, std::string const& RHS) const {
59-
return LHS == RHS;
58+
bool operator()(fs::path const& LHS, std::string const& RHS) const {
59+
return LHS.string() == RHS;
6060
}
6161
};
6262

libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_normal.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int main(int, char**) {
131131
" Input: '%s'\n"
132132
" Expected: '%s'\n"
133133
" Output: '%s'\n",
134-
ID, TC.input.c_str(), TC.expect.c_str(), output.native().c_str());
134+
ID, TC.input.c_str(), TC.expect.c_str(), output.string().c_str());
135135
}
136136
}
137137
return Failed;

libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main(int, char**) {
6969
" Expected: '%s'\n"
7070
" Output: '%s'\n",
7171
ID, Testing, TC.input.c_str(), TC.base.c_str(),
72-
Expected.c_str(), Output.native().c_str());
72+
Expected.string().c_str(), Output.string().c_str());
7373
};
7474
if (!PathEq(output, TC.expect))
7575
ReportErr("path::lexically_relative", output, TC.expect);

libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ TEST_CASE(test_PR35078)
314314
ExceptionChecker Checker(std::errc::permission_denied,
315315
"recursive_directory_iterator::operator++()",
316316
format_string("attempting recursion into \"%s\"",
317-
nestedDir.native()));
317+
nestedDir.string().c_str()));
318318
TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ++it);
319319
}
320320
}

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.absolute/absolute.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ TEST_CASE(basic_test)
3838
const fs::path cwd = fs::current_path();
3939
const struct {
4040
std::string input;
41-
std::string expect;
41+
fs::path expect;
4242
} TestCases [] = {
4343
{"", cwd / ""},
4444
{"foo", cwd / "foo"},

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct Times {
106106

107107
Times GetTimes(path const& p) {
108108
StatT st;
109-
if (::stat(p.c_str(), &st) == -1) {
109+
if (::stat(p.string().c_str(), &st) == -1) {
110110
std::error_code ec(errno, std::generic_category());
111111
#ifndef TEST_HAS_NO_EXCEPTIONS
112112
throw ec;
@@ -123,7 +123,7 @@ TimeSpec LastWriteTime(path const& p) { return GetTimes(p).write; }
123123

124124
Times GetSymlinkTimes(path const& p) {
125125
StatT st;
126-
if (::lstat(p.c_str(), &st) == -1) {
126+
if (::lstat(p.string().c_str(), &st) == -1) {
127127
std::error_code ec(errno, std::generic_category());
128128
#ifndef TEST_HAS_NO_EXCEPTIONS
129129
throw ec;
@@ -395,7 +395,7 @@ TEST_CASE(get_last_write_time_dynamic_env_test)
395395
SleepFor(Sec(2));
396396

397397
// update file and add a file to the directory. Make sure the times increase.
398-
std::FILE* of = std::fopen(file.c_str(), "a");
398+
std::FILE* of = std::fopen(file.string().c_str(), "a");
399399
std::fwrite("hello", 1, sizeof("hello"), of);
400400
std::fclose(of);
401401
env.create_file("dir/file1", 1);

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.proximate/proximate.pass.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ TEST_CASE(basic_test) {
6060
path relative_cwd = cwd.native().substr(1);
6161
// clang-format off
6262
struct {
63-
std::string input;
64-
std::string base;
65-
std::string expect;
63+
fs::path input;
64+
fs::path base;
65+
fs::path expect;
6666
} TestCases[] = {
6767
{"", "", "."},
6868
{cwd, "a", ".."},
@@ -104,7 +104,8 @@ TEST_CASE(basic_test) {
104104
" Input: '%s'\n"
105105
" Base: '%s'\n"
106106
" Expected: '%s'\n",
107-
ID, TC.input.c_str(), TC.base.c_str(), TC.expect.c_str());
107+
ID, TC.input.string().c_str(), TC.base.string().c_str(),
108+
TC.expect.string().c_str());
108109
} else if (!PathEq(output, TC.expect)) {
109110
TEST_CHECK(PathEq(output, TC.expect));
110111

@@ -119,9 +120,10 @@ TEST_CASE(basic_test) {
119120
" Lex Prox: '%s'\n"
120121
" Canon Input: '%s'\n"
121122
" Canon Base: '%s'\n",
122-
ID, TC.input.c_str(), TC.base.c_str(), TC.expect.c_str(),
123-
output.native().c_str(), lexically_p.native().c_str(),
124-
canon_input.c_str(), canon_base.c_str());
123+
ID, TC.input.string().c_str(), TC.base.string().c_str(),
124+
TC.expect.string().c_str(), output.string().c_str(),
125+
lexically_p.string().c_str(), canon_input.string().c_str(),
126+
canon_base.string().c_str());
125127
}
126128
}
127129
}

0 commit comments

Comments
 (0)