Skip to content

Commit edd85ec

Browse files
authored
Add a test for std::filesystem API. NFC (#24721)
See #24722
1 parent da51007 commit edd85ec

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

test/other/test_std_filesystem.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <cstdint>
2+
#include <filesystem>
3+
#include <fstream>
4+
#include <iostream>
5+
6+
namespace fs = std::filesystem;
7+
8+
int main() {
9+
fs::path tmp{std::filesystem::temp_directory_path()};
10+
11+
const auto foo{"foo"};
12+
std::ofstream{tmp / foo} << foo; // creates file containing "foo"
13+
std::cout << "remove(): " << fs::remove(tmp / foo) << '\n'; // success
14+
std::cout << "remove(): " << fs::remove(tmp / foo) << '\n'; // fail
15+
16+
std::filesystem::create_directories(tmp / "abcdef/example");
17+
const std::uintmax_t n{fs::remove_all(tmp / "abcdef")};
18+
std::cout << "remove_all(): " << n << " files or directories\n";
19+
}

test/other/test_std_filesystem.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
remove(): 1
2+
remove(): 0
3+
remove_all(): 2 files or directories

test/test_other.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15035,6 +15035,10 @@ def test_fs_icase(self):
1503515035
# c++20 for ends_with().
1503615036
self.do_other_test('test_fs_icase.cpp', cflags=['-sCASE_INSENSITIVE_FS', '-std=c++20'])
1503715037

15038+
@with_all_fs
15039+
def test_std_filesystem(self):
15040+
self.do_other_test('test_std_filesystem.cpp')
15041+
1503815042
def test_strict_js_closure(self):
1503915043
self.do_runf('hello_world.c', cflags=['-sSTRICT_JS', '-Werror=closure', '--closure=1', '-O3'])
1504015044

0 commit comments

Comments
 (0)