Skip to content

Commit 3784bdf

Browse files
committed
[libcxx] [test] Fix string type handling in a few fairly trivial class.path tests
Use string() for convenience for testing where possible, but keep using native() for move tests where we want to check that no allocations are made, constructing a reference fs::path::string_type instead. Use the right value_type in a few places. Make the synop test check for the right types and for the expected preferred separator. Differential Revision: https://reviews.llvm.org/D89537
1 parent b740899 commit 3784bdf

File tree

11 files changed

+37
-20
lines changed

11 files changed

+37
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ int main(int, char**) {
2929
const path p(s);
3030
path p2;
3131
path& pref = (p2 = p);
32-
assert(p.native() == s);
33-
assert(p2.native() == s);
32+
assert(p.string() == s);
33+
assert(p2.string() == s);
3434
assert(&pref == &p2);
3535

3636
return 0;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ int main(int, char**) {
2929
const std::string s("we really really really really really really really "
3030
"really really long string so that we allocate");
3131
assert(globalMemCounter.checkOutstandingNewEq(1));
32+
const fs::path::string_type ps(s.begin(), s.end());
3233
path p(s);
3334
{
3435
DisableAllocationGuard g;
3536
path p2;
3637
path& pref = (p2 = std::move(p));
37-
assert(p2.native() == s);
38-
assert(p.native() != s); // Testing moved from state
38+
assert(p2.native() == ps);
39+
assert(p.native() != ps); // Testing moved from state
3940
assert(&pref == &p2);
4041
}
4142

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ int main(int, char**) {
2828
const std::string s("foo");
2929
const path p(s);
3030
path p2(p);
31-
assert(p.native() == s);
32-
assert(p2.native() == s);
31+
assert(p.string() == s);
32+
assert(p2.string() == s);
3333

3434
return 0;
3535
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ int main(int, char**) {
2929
const std::string s("we really really really really really really really "
3030
"really really long string so that we allocate");
3131
assert(globalMemCounter.checkOutstandingNewEq(1));
32+
const fs::path::string_type ps(s.begin(), s.end());
3233
path p(s);
3334
{
3435
DisableAllocationGuard g;
3536
path p2(std::move(p));
36-
assert(p2.native() == s);
37-
assert(p.native() != s); // Testing moved from state
37+
assert(p2.native() == ps);
38+
assert(p.native() != ps); // Testing moved from state
3839
}
3940

4041
return 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
template <class CharT, class ...Args>
3232
void RunTestCaseImpl(MultiStringType const& MS, Args... args) {
3333
using namespace fs;
34-
const char* Expect = MS;
34+
const fs::path::value_type* Expect = MS;
3535
const CharT* TestPath = MS;
3636
const CharT* TestPathEnd = StrEnd(TestPath);
3737
const std::size_t Size = TestPathEnd - TestPath;

libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/c_str.pass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ int main(int, char**)
2828
using namespace fs;
2929
const char* const value = "hello world";
3030
const std::string str_value = value;
31+
const fs::path::string_type pathstr_value(str_value.begin(), str_value.end());
3132
{ // Check signature
3233
path p(value);
3334
ASSERT_SAME_TYPE(path::value_type const*, decltype(p.c_str()));
3435
ASSERT_NOEXCEPT(p.c_str());
3536
}
3637
{
3738
path p(value);
38-
assert(p.c_str() == str_value);
39+
assert(p.c_str() == pathstr_value);
3940
assert(p.native().c_str() == p.c_str());
4041
}
4142

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ int main(int, char**)
2626
{
2727
using namespace fs;
2828
const char* const value = "hello world";
29+
std::string value_str(value);
30+
fs::path::string_type pathstr_value(value_str.begin(), value_str.end());
2931
{ // Check signature
3032
path p(value);
3133
ASSERT_SAME_TYPE(path::string_type const&, decltype(p.native()));
3234
ASSERT_NOEXCEPT(p.native());
3335
}
3436
{ // native() is tested elsewhere
3537
path p(value);
36-
assert(p.native() == value);
38+
assert(p.native() == pathstr_value);
3739
}
3840

3941
return 0;

libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/operator_string.pass.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ int main(int, char**)
2828
using namespace fs;
2929
using string_type = path::string_type;
3030
const char* const value = "hello world";
31+
std::string value_str(value);
32+
fs::path::string_type pathstr_value(value_str.begin(), value_str.end());
3133
{ // Check signature
3234
path p(value);
3335
static_assert(std::is_convertible<path, string_type>::value, "");
@@ -37,10 +39,10 @@ int main(int, char**)
3739
}
3840
{
3941
path p(value);
40-
assert(p.native() == value);
42+
assert(p.native() == pathstr_value);
4143
string_type s = p;
42-
assert(s == value);
43-
assert(p == value);
44+
assert(s == pathstr_value);
45+
assert(p == pathstr_value);
4446
}
4547

4648
return 0;

libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void doIOTest() {
5353
{ // test input
5454
path p_in;
5555
auto& ret = ss >> p_in;
56-
assert(p_in.native() == (const char*)InStr);
56+
assert(p_in.native() == (const path::value_type*)InStr);
5757
assert(&ret == &ss);
5858
}
5959
}

libcxx/test/std/input.output/filesystems/class.path/path.nonmember/swap.pass.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ int main(int, char**)
2929
const char* value2 = "_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG";
3030
path p1(value1);
3131
path p2(value2);
32+
fs::path::string_type ps1 = p1.native();
33+
fs::path::string_type ps2 = p2.native();
3234
{
3335
using namespace std; using namespace fs;
3436
ASSERT_NOEXCEPT(swap(p1, p2));
@@ -39,11 +41,11 @@ int main(int, char**)
3941
using namespace std;
4042
using namespace fs;
4143
swap(p1, p2);
42-
assert(p1.native() == value2);
43-
assert(p2.native() == value1);
44+
assert(p1.native() == ps2);
45+
assert(p2.native() == ps1);
4446
swap(p1, p2);
45-
assert(p1.native() == value1);
46-
assert(p2.native() == value2);
47+
assert(p1.native() == ps1);
48+
assert(p2.native() == ps2);
4749
}
4850

4951
return 0;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,21 @@
2525

2626
int main(int, char**) {
2727
using namespace fs;
28+
#ifdef _WIN32
29+
ASSERT_SAME_TYPE(path::value_type, wchar_t);
30+
#else
2831
ASSERT_SAME_TYPE(path::value_type, char);
32+
#endif
2933
ASSERT_SAME_TYPE(path::string_type, std::basic_string<path::value_type>);
3034
{
3135
ASSERT_SAME_TYPE(const path::value_type, decltype(path::preferred_separator));
36+
#ifdef _WIN32
37+
static_assert(path::preferred_separator == '\\', "");
38+
#else
3239
static_assert(path::preferred_separator == '/', "");
40+
#endif
3341
// Make preferred_separator ODR used by taking its address.
34-
const char* dummy = &path::preferred_separator;
42+
const path::value_type* dummy = &path::preferred_separator;
3543
((void)dummy);
3644
}
3745

0 commit comments

Comments
 (0)