Merge to upstream r350972.

Test: ./run_tests.py --bitness 32
Test: ./run_tests.py --bitness 64
Test: ./run_tests.py --bitness 64 --host
Bug: None
Change-Id: I96552544c8305853be519855982caf716930519e
This commit is contained in:
Dan Albert
2019-01-11 14:07:42 -08:00
404 changed files with 8700 additions and 1735 deletions

View File

@@ -65,6 +65,8 @@ const PathCompareTest CompareTestCases[] =
{"//foo//bar///baz////", "//foo/bar/baz/", 0}, // duplicate separators
{"///foo/bar", "/foo/bar", 0}, // "///" is not a root directory
{"/foo/bar/", "/foo/bar", 1}, // trailing separator
{"foo", "/foo", -1}, // if !this->has_root_directory() and p.has_root_directory(), a value less than 0.
{"/foo", "foo", 1}, // if this->has_root_directory() and !p.has_root_directory(), a value greater than 0.
{"//" LONGA "////" LONGB "/" LONGC "///" LONGD, "//" LONGA "/" LONGB "/" LONGC "/" LONGD, 0},
{ LONGA "/" LONGB "/" LONGC, LONGA "/" LONGB "/" LONGB, 1}
@@ -79,7 +81,7 @@ static inline int normalize_ret(int ret)
return ret < 0 ? -1 : (ret > 0 ? 1 : 0);
}
int main()
void test_compare_basic()
{
using namespace fs;
for (auto const & TC : CompareTestCases) {
@@ -136,3 +138,54 @@ int main()
}
}
}
int CompareElements(std::vector<std::string> const& LHS, std::vector<std::string> const& RHS) {
bool IsLess = std::lexicographical_compare(LHS.begin(), LHS.end(), RHS.begin(), RHS.end());
if (IsLess)
return -1;
bool IsGreater = std::lexicographical_compare(RHS.begin(), RHS.end(), LHS.begin(), LHS.end());
if (IsGreater)
return 1;
return 0;
}
void test_compare_elements() {
struct {
std::vector<std::string> LHSElements;
std::vector<std::string> RHSElements;
int Expect;
} TestCases[] = {
{{"a"}, {"a"}, 0},
{{"a"}, {"b"}, -1},
{{"b"}, {"a"}, 1},
{{"a", "b", "c"}, {"a", "b", "c"}, 0},
{{"a", "b", "c"}, {"a", "b", "d"}, -1},
{{"a", "b", "d"}, {"a", "b", "c"}, 1},
{{"a", "b"}, {"a", "b", "c"}, -1},
{{"a", "b", "c"}, {"a", "b"}, 1},
};
auto BuildPath = [](std::vector<std::string> const& Elems) {
fs::path p;
for (auto &E : Elems)
p /= E;
return p;
};
for (auto &TC : TestCases) {
fs::path LHS = BuildPath(TC.LHSElements);
fs::path RHS = BuildPath(TC.RHSElements);
const int ExpectCmp = CompareElements(TC.LHSElements, TC.RHSElements);
assert(ExpectCmp == TC.Expect);
const int GotCmp = normalize_ret(LHS.compare(RHS));
assert(GotCmp == TC.Expect);
}
}
int main() {
test_compare_basic();
test_compare_elements();
}

View File

@@ -40,8 +40,8 @@ int main() {
{"a", "/", ""},
{"//net", "a", ""},
{"a", "//net", ""},
{"//net/", "//net", ""},
{"//net", "//net/", ".."},
{"//net/", "//net", "."},
{"//net", "//net/", "."},
{"//base", "a", ""},
{"a", "a", "."},
{"a/b", "a/b", "."},

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03
// <filesystem>
#include "filesystem_include.hpp"
using namespace fs;
struct ConvToPath {
operator fs::path() const {
return "";
}
};
int main() {
ConvToPath LHS, RHS;
(void)(LHS / RHS); // expected-error {{invalid operands to binary expression}}
}

View File

@@ -20,7 +20,6 @@
#include "test_macros.h"
#include "filesystem_test_helper.hpp"
// This is mainly tested via the member append functions.
int main()
{
@@ -29,4 +28,7 @@ int main()
path p2("def");
path p3 = p1 / p2;
assert(p3 == "abc/def");
path p4 = p1 / "def";
assert(p4 == "abc/def");
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03
// <filesystem>
#include "filesystem_include.hpp"
using namespace fs;
struct ConvToPath {
operator fs::path() const {
return "";
}
};
int main() {
ConvToPath LHS, RHS;
(void)(LHS == RHS); // expected-error {{invalid operands to binary expression}}
(void)(LHS != RHS); // expected-error {{invalid operands to binary expression}}
(void)(LHS < RHS); // expected-error {{invalid operands to binary expression}}
(void)(LHS <= RHS); // expected-error {{invalid operands to binary expression}}
(void)(LHS > RHS); // expected-error {{invalid operands to binary expression}}
(void)(LHS >= RHS); // expected-error {{invalid operands to binary expression}}
}

View File

@@ -125,7 +125,7 @@ TimeSpec LastAccessTime(path const& p) { return GetTimes(p).access; }
TimeSpec LastWriteTime(path const& p) { return GetTimes(p).write; }
std::pair<TimeSpec, TimeSpec> GetSymlinkTimes(path const& p) {
Times GetSymlinkTimes(path const& p) {
StatT st;
if (::lstat(p.c_str(), &st) == -1) {
std::error_code ec(errno, std::generic_category());
@@ -136,7 +136,10 @@ std::pair<TimeSpec, TimeSpec> GetSymlinkTimes(path const& p) {
std::exit(EXIT_FAILURE);
#endif
}
return {extract_atime(st), extract_mtime(st)};
Times res;
res.access = extract_atime(st);
res.write = extract_mtime(st);
return res;
}
namespace {
@@ -427,7 +430,7 @@ TEST_CASE(set_last_write_time_dynamic_env_test)
epoch_time - Minutes(3) - Sec(42) - SubSec(17);
// FreeBSD has a bug in their utimes implementation where the time is not update
// when the number of seconds is '-1'.
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) || defined(__NetBSD__)
const file_time_type just_before_epoch_time =
epoch_time - Sec(2) - SubSec(17);
#else
@@ -500,9 +503,8 @@ TEST_CASE(last_write_time_symlink_test)
TEST_CHECK(CompareTime(LastWriteTime(file), new_time));
TEST_CHECK(CompareTime(LastAccessTime(sym), old_times.access));
std::pair<TimeSpec, TimeSpec> sym_times = GetSymlinkTimes(sym);
TEST_CHECK(CompareTime(sym_times.first, old_sym_times.first));
TEST_CHECK(CompareTime(sym_times.second, old_sym_times.second));
Times sym_times = GetSymlinkTimes(sym);
TEST_CHECK(CompareTime(sym_times.write, old_sym_times.write));
}

View File

@@ -159,11 +159,12 @@ TEST_CASE(test_no_resolve_symlink_on_symlink)
{perms::owner_all, perms::group_all, perm_options::remove},
};
for (auto const& TC : cases) {
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__ANDROID__)
// On OS X symlink permissions are supported. We should get an empty
// error code and the expected permissions.
const auto expected_link_perms = TC.expected;
std::error_code expected_ec;
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
defined(__ANDROID__)
// On OS X symlink permissions are supported. We should get an empty
// error code and the expected permissions.
const auto expected_link_perms = TC.expected;
std::error_code expected_ec;
#else
// On linux symlink permissions are not supported. The error code should
// be 'operation_not_supported' and the symlink permissions should be

View File

@@ -79,12 +79,12 @@ TEST_CASE(basic_test) {
#endif
{"/", "a", dot_dot_to_root / ".."},
{"/", "a/b", dot_dot_to_root / "../.."},
{"/", "a/b/", dot_dot_to_root / "../../.."},
{"/", "a/b/", dot_dot_to_root / "../.."},
{"a", "/", relative_cwd / "a"},
{"a/b", "/", relative_cwd / "a/b"},
{"a", "/net", ".." / relative_cwd / "a"},
{"//foo/", "//foo", "/foo/"},
{"//foo", "//foo/", ".."},
{"//foo/", "//foo", "."},
{"//foo", "//foo/", "."},
{"//foo", "//foo", "."},
{"//foo/", "//foo/", "."},
{"//base", "a", dot_dot_to_root / "../base"},

View File

@@ -16,9 +16,8 @@
// path proximate(const path& p, const path& base, error_code& ec);
#include "filesystem_include.hpp"
#include <string>
#include <type_traits>
#include <vector>
#include <iostream>
#include <cassert>
#include "test_macros.h"
@@ -30,49 +29,90 @@
TEST_SUITE(filesystem_proximate_path_test_suite)
TEST_CASE(test_signature) {
TEST_CASE(test_signature_0) {
fs::path p("");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(fs::current_path()));
}
int main() {
// clang-format off
struct {
std::string input;
std::string expect;
} TestCases[] = {
{"", fs::current_path()},
{".", fs::current_path()},
{StaticEnv::File, StaticEnv::File},
{StaticEnv::Dir, StaticEnv::Dir},
{StaticEnv::SymlinkToDir, StaticEnv::Dir},
{StaticEnv::SymlinkToDir / "dir2/.", StaticEnv::Dir / "dir2"},
// FIXME? If the trailing separator occurs in a part of the path that exists,
// it is ommitted. Otherwise it is added to the end of the result.
{StaticEnv::SymlinkToDir / "dir2/./", StaticEnv::Dir / "dir2"},
{StaticEnv::SymlinkToDir / "dir2/DNE/./", StaticEnv::Dir / "dir2/DNE/"},
{StaticEnv::SymlinkToDir / "dir2", StaticEnv::Dir2},
{StaticEnv::SymlinkToDir / "dir2/../dir2/DNE/..", StaticEnv::Dir2 / ""},
{StaticEnv::SymlinkToDir / "dir2/dir3/../DNE/DNE2", StaticEnv::Dir2 / "DNE/DNE2"},
{StaticEnv::Dir / "../dir1", StaticEnv::Dir},
{StaticEnv::Dir / "./.", StaticEnv::Dir},
{StaticEnv::Dir / "DNE/../foo", StaticEnv::Dir / "foo"}
};
// clang-format on
int ID = 0;
bool Failed = false;
for (auto& TC : TestCases) {
++ID;
fs::path p(TC.input);
const fs::path output = fs::weakly_canonical(p);
if (output != TC.expect) {
Failed = true;
std::cerr << "TEST CASE #" << ID << " FAILED: \n";
std::cerr << " Input: '" << TC.input << "'\n";
std::cerr << " Expected: '" << TC.expect << "'\n";
std::cerr << " Output: '" << output.native() << "'";
std::cerr << std::endl;
}
}
return Failed;
TEST_CASE(test_signature_1) {
fs::path p(".");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(fs::current_path()));
}
TEST_CASE(test_signature_2) {
fs::path p(StaticEnv::File);
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::File));
}
TEST_CASE(test_signature_3) {
fs::path p(StaticEnv::Dir);
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir));
}
TEST_CASE(test_signature_4) {
fs::path p(StaticEnv::SymlinkToDir);
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir));
}
TEST_CASE(test_signature_5) {
fs::path p(StaticEnv::SymlinkToDir / "dir2/.");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir / "dir2"));
}
TEST_CASE(test_signature_6) {
// FIXME? If the trailing separator occurs in a part of the path that exists,
// it is ommitted. Otherwise it is added to the end of the result.
fs::path p(StaticEnv::SymlinkToDir / "dir2/./");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir / "dir2"));
}
TEST_CASE(test_signature_7) {
fs::path p(StaticEnv::SymlinkToDir / "dir2/DNE/./");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir / "dir2/DNE/"));
}
TEST_CASE(test_signature_8) {
fs::path p(StaticEnv::SymlinkToDir / "dir2");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir2));
}
TEST_CASE(test_signature_9) {
fs::path p(StaticEnv::SymlinkToDir / "dir2/../dir2/DNE/..");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir2 / ""));
}
TEST_CASE(test_signature_10) {
fs::path p(StaticEnv::SymlinkToDir / "dir2/dir3/../DNE/DNE2");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir2 / "DNE/DNE2"));
}
TEST_CASE(test_signature_11) {
fs::path p(StaticEnv::Dir / "../dir1");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir));
}
TEST_CASE(test_signature_12) {
fs::path p(StaticEnv::Dir / "./.");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir));
}
TEST_CASE(test_signature_13) {
fs::path p(StaticEnv::Dir / "DNE/../foo");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir / "foo"));
}
TEST_SUITE_END()

View File

@@ -14,6 +14,7 @@
// REQUIRES: locale.en_US.UTF-8
#include <iomanip>
#include <istream>
#include <cassert>
#include "platform_support.h" // locale name macros

View File

@@ -14,6 +14,7 @@
// template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
#include <iomanip>
#include <istream>
#include <cassert>
#include "platform_support.h" // locale name macros

View File

@@ -14,6 +14,7 @@
// REQUIRES: locale.en_US.UTF-8
#include <iomanip>
#include <ostream>
#include <cassert>
#include "platform_support.h" // locale name macros

View File

@@ -14,6 +14,7 @@
// template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
#include <iomanip>
#include <ostream>
#include <cassert>
#include "platform_support.h" // locale name macros

View File

@@ -15,6 +15,7 @@
// operator>>(int& val);
#include <istream>
#include <limits>
#include <cassert>
template <class CharT>

View File

@@ -15,6 +15,7 @@
// operator>>(short& val);
#include <istream>
#include <limits>
#include <cassert>
template <class CharT>

View File

@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
// XFAIL: with_system_cxx_lib=macosx10.7
// <istream>
// int_type get();

View File

@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
// XFAIL: with_system_cxx_lib=macosx10.7
// <istream>
// basic_istream<charT,traits>& get(char_type& c);

View File

@@ -7,13 +7,14 @@
//
//===----------------------------------------------------------------------===//
// In macosx10.9 to macosx10.14, streams are provided in the dylib AND they
// have a bug in how they handle null-termination in case of errors (see D40677).
// XFAIL: with_system_cxx_lib=macosx10.14
// XFAIL: with_system_cxx_lib=macosx10.13
// XFAIL: with_system_cxx_lib=macosx10.12
// XFAIL: with_system_cxx_lib=macosx10.11
// XFAIL: with_system_cxx_lib=macosx10.10
// XFAIL: with_system_cxx_lib=macosx10.9
// XFAIL: with_system_cxx_lib=macosx10.8
// XFAIL: with_system_cxx_lib=macosx10.7
// <istream>

View File

@@ -7,13 +7,14 @@
//
//===----------------------------------------------------------------------===//
// In macosx10.9 to macosx10.14, streams are provided in the dylib AND they
// have a bug in how they handle null-termination in case of errors (see D40677).
// XFAIL: with_system_cxx_lib=macosx10.14
// XFAIL: with_system_cxx_lib=macosx10.13
// XFAIL: with_system_cxx_lib=macosx10.12
// XFAIL: with_system_cxx_lib=macosx10.11
// XFAIL: with_system_cxx_lib=macosx10.10
// XFAIL: with_system_cxx_lib=macosx10.9
// XFAIL: with_system_cxx_lib=macosx10.8
// XFAIL: with_system_cxx_lib=macosx10.7
// <istream>

View File

@@ -7,13 +7,14 @@
//
//===----------------------------------------------------------------------===//
// In macosx10.9 to macosx10.14, streams are provided in the dylib AND they
// have a bug in how they handle null-termination in case of errors (see D40677).
// XFAIL: with_system_cxx_lib=macosx10.14
// XFAIL: with_system_cxx_lib=macosx10.13
// XFAIL: with_system_cxx_lib=macosx10.12
// XFAIL: with_system_cxx_lib=macosx10.11
// XFAIL: with_system_cxx_lib=macosx10.10
// XFAIL: with_system_cxx_lib=macosx10.9
// XFAIL: with_system_cxx_lib=macosx10.8
// XFAIL: with_system_cxx_lib=macosx10.7
// <istream>

View File

@@ -7,13 +7,14 @@
//
//===----------------------------------------------------------------------===//
// In macosx10.9 to macosx10.14, streams are provided in the dylib AND they
// have a bug in how they handle null-termination in case of errors (see D40677).
// XFAIL: with_system_cxx_lib=macosx10.14
// XFAIL: with_system_cxx_lib=macosx10.13
// XFAIL: with_system_cxx_lib=macosx10.12
// XFAIL: with_system_cxx_lib=macosx10.11
// XFAIL: with_system_cxx_lib=macosx10.10
// XFAIL: with_system_cxx_lib=macosx10.9
// XFAIL: with_system_cxx_lib=macosx10.8
// XFAIL: with_system_cxx_lib=macosx10.7
// <istream>

View File

@@ -7,9 +7,6 @@
//
//===----------------------------------------------------------------------===//
// XFAIL: with_system_cxx_lib=macosx10.7
// XFAIL: with_system_cxx_lib=macosx10.8
// <istream>
// basic_istream<charT,traits>&

View File

@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
// XFAIL: with_system_cxx_lib=macosx10.7
// <istream>
// basic_istream<charT,traits>& read(char_type* s, streamsize n);

View File

@@ -7,9 +7,6 @@
//
//===----------------------------------------------------------------------===//
// XFAIL: with_system_cxx_lib=macosx10.7
// XFAIL: with_system_cxx_lib=macosx10.8
// <istream>
// streamsize readsome(char_type* s, streamsize n);

View File

@@ -7,9 +7,6 @@
//
//===----------------------------------------------------------------------===//
// XFAIL: with_system_cxx_lib=macosx10.7
// XFAIL: with_system_cxx_lib=macosx10.8
// <istream>
// basic_istream<charT,traits>& seekg(pos_type pos);

View File

@@ -10,8 +10,6 @@
// XFAIL: with_system_cxx_lib=macosx10.11
// XFAIL: with_system_cxx_lib=macosx10.10
// XFAIL: with_system_cxx_lib=macosx10.9
// XFAIL: with_system_cxx_lib=macosx10.7
// XFAIL: with_system_cxx_lib=macosx10.8
// <istream>

View File

@@ -46,7 +46,7 @@ static void test(std::ios_base::fmtflags fmt, const char *expected)
assert(ss.str() == expected);
}
int main(void)
int main()
{
const std::ios_base::fmtflags o = std::ios_base::oct;
const std::ios_base::fmtflags d = std::ios_base::dec;

View File

@@ -12,6 +12,8 @@
// T1 resetiosflags(ios_base::fmtflags mask);
#include <iomanip>
#include <istream>
#include <ostream>
#include <cassert>
template <class CharT>

View File

@@ -12,6 +12,8 @@
// T3 setbase(int base);
#include <iomanip>
#include <istream>
#include <ostream>
#include <cassert>
template <class CharT>

View File

@@ -12,6 +12,7 @@
// template<charT> T4 setfill(charT c);
#include <iomanip>
#include <ostream>
#include <cassert>
template <class CharT>

View File

@@ -12,6 +12,8 @@
// T2 setiosflags (ios_base::fmtflags mask);
#include <iomanip>
#include <istream>
#include <ostream>
#include <cassert>
template <class CharT>

View File

@@ -12,6 +12,8 @@
// T5 setprecision(int n);
#include <iomanip>
#include <istream>
#include <ostream>
#include <cassert>
template <class CharT>

View File

@@ -12,6 +12,8 @@
// T6 setw(int n);
#include <iomanip>
#include <istream>
#include <ostream>
#include <cassert>
template <class CharT>