diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-06-28 16:09:21 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-06-30 14:16:27 +0100 |
commit | 1eef21ccfa5988a23a3b71a99613f27ea6a26da6 (patch) | |
tree | 144bbcd52978c765c87546bcfbe758a8253c5271 /libstdc++-v3/testsuite | |
parent | 6c96b14a19a9e6c365eacc59868a866b99f9786d (diff) |
libstdc++: Improve exceptions thrown from fs::temp_directory_path
Currently the throwing overload of fs::temp_directory_path() will
discard the path that was obtained from the environment. When it fails
because the path doesn't resolve to a directory you get an unhelpful
error like:
filesystem error: temp_directory_path: Not a directory
It would be better to also print the path in that case, e.g.
filesystem error: temp_directory_path: Not a directory [/home/bob/tmp]
libstdc++-v3/ChangeLog:
* src/c++17/fs_ops.cc (fs::temp_directory_path()): Include path
in exception.
(fs::temp_directory_path(error_code&)): Rearrange to more
closely match the structure of the first overload.
* src/filesystem/ops.cc (fs::temp_directory_path): Likewise.
* testsuite/27_io/filesystem/operations/temp_directory_path.cc:
Check that exception contains the path.
* testsuite/experimental/filesystem/operations/temp_directory_path.cc:
Likewise.
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r-- | libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc | 5 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc index b4ef77f05e4..56bd7408c2d 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc @@ -140,12 +140,17 @@ test04() VERIFY( r == fs::path() ); std::error_code ec2; + std::string failed_path; try { fs::temp_directory_path(); } catch (const fs::filesystem_error& e) { ec2 = e.code(); + // On Windows the returned path will be in preferred form, i.e. using L'\\' + // and will have a trailing slash, so compare generic forms. + failed_path = e.path1().generic_string(); } VERIFY( ec2 == ec ); + VERIFY( failed_path.find(f.path.generic_string()) != std::string::npos ); } int diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc index c2945c90866..1772f9737c1 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc @@ -141,12 +141,17 @@ test04() VERIFY( r == fs::path() ); std::error_code ec2; + std::string failed_path; try { fs::temp_directory_path(); } catch (const fs::filesystem_error& e) { ec2 = e.code(); + // On Windows the returned path will be in preferred form, i.e. using L'\\' + // and will have a trailing slash, so compare generic forms. + failed_path = e.path1().generic_string(); } VERIFY( ec2 == ec ); + VERIFY( failed_path.find(f.path.generic_string()) != std::string::npos ); } int |