Skip to content

Commit

Permalink
Changes to make filesystem_test work properly on Windows (#2836)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgritz committed Jan 20, 2021
1 parent 038e3d1 commit 92593fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
12 changes: 5 additions & 7 deletions src/libutil/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,7 @@ Filesystem::scan_for_matching_filenames(const std::string& pattern_,
std::string directory = Filesystem::parent_path(pattern);
if (directory.size() == 0) {
directory = ".";
#ifdef _WIN32
pattern = ".\\\\" + pattern;
#else
pattern = "./" + pattern;
#endif
pattern = "./" + pattern;
}

if (!exists(directory))
Expand Down Expand Up @@ -922,8 +918,10 @@ Filesystem::scan_for_matching_filenames(const std::string& pattern_,
error_code ec;
for (filesystem::directory_iterator it(u8path(directory), ec), end_it;
!ec && it != end_it; ++it) {
if (filesystem::is_regular(it->path(), ec)) {
const std::string f = pathstr(it->path());
std::string itpath = Filesystem::generic_filepath(
it->path().string());
if (filesystem::is_regular(itpath, ec)) {
const std::string f = pathstr(itpath);
match_results<std::string::const_iterator> frame_match;
if (regex_match(f, frame_match, pattern_re)) {
std::string thenumber(frame_match[1].first,
Expand Down
26 changes: 5 additions & 21 deletions src/libutil/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test_filename_decomposition()
std::cout << "Testing generic_string\n";
#if _WIN32
OIIO_CHECK_EQUAL(Filesystem::generic_filepath("\\x\\y"), "/x/y");
OIIO_CHECK_EQUAL(Filesystem::generic_filepath("c:\\x\\y"), "/c/x/y");
OIIO_CHECK_EQUAL(Filesystem::generic_filepath("c:\\x\\y"), "c:/x/y");
#endif
}

Expand Down Expand Up @@ -113,7 +113,7 @@ static void
test_file_status()
{
// Make test file, test Filesystem::fopen in the process.
FILE* file = Filesystem::fopen("testfile", "w");
FILE* file = Filesystem::fopen("testfile", "wb");
OIIO_CHECK_ASSERT(file != NULL);
const char testtext[] = "test\nfoo\nbar\n";
fputs(testtext, file);
Expand Down Expand Up @@ -204,7 +204,7 @@ test_file_seq(const char* pattern, const char* override,
Filesystem::parse_pattern(pattern, 0, normalized_pattern, frame_range);
if (override && strlen(override) > 0)
frame_range = override;
Filesystem::enumerate_sequence(frame_range.c_str(), numbers);
Filesystem::enumerate_sequence(frame_range, numbers);
Filesystem::enumerate_file_sequence(normalized_pattern, numbers, names);
std::string joined = Strutil::join(names, " ");
std::cout << " " << pattern;
Expand Down Expand Up @@ -287,7 +287,8 @@ test_scan_file_seq_with_views(const char* pattern, const char** views_,
std::vector<string_view> views;

for (size_t i = 0; views_[i]; ++i)
views.emplace_back(views_[i]);
if (views_[i])
views.emplace_back(views_[i]);

Filesystem::parse_pattern(pattern, 0, normalized_pattern, frame_range);
Filesystem::scan_for_matching_filenames(normalized_pattern, views,
Expand Down Expand Up @@ -436,15 +437,9 @@ test_scan_sequences()
create_test_file(fn);
}

#ifdef _WIN32
test_scan_file_seq(
"foo.#.exr",
".\\foo.0001.exr .\\foo.0002.exr .\\foo.0003.exr .\\foo.0004.exr .\\foo.0005.exr");
#else
test_scan_file_seq(
"foo.#.exr",
"./foo.0001.exr ./foo.0002.exr ./foo.0003.exr ./foo.0004.exr ./foo.0005.exr");
#endif

filenames.clear();

Expand All @@ -459,15 +454,9 @@ test_scan_sequences()

const char* views[] = { "left", NULL };

#ifdef _WIN32
test_scan_file_seq_with_views(
"%V/%v/foo_%V_%v.#.exr", views,
"left\\l\\foo_left_l.0001.exr left\\l\\foo_left_l.0002.exr left\\l\\foo_left_l.0003.exr left\\l\\foo_left_l.0004.exr left\\l\\foo_left_l.0005.exr");
#else
test_scan_file_seq_with_views(
"%V/%v/foo_%V_%v.#.exr", views,
"left/l/foo_left_l.0001.exr left/l/foo_left_l.0002.exr left/l/foo_left_l.0003.exr left/l/foo_left_l.0004.exr left/l/foo_left_l.0005.exr");
#endif

filenames.clear();

Expand All @@ -486,13 +475,8 @@ test_scan_sequences()

const char* views2[] = { "left", "right", NULL };

#ifdef _WIN32
test_scan_file_seq_with_views("%V/%v/foo_%V_%v", views2,
"left\\l\\foo_left_l right\\r\\foo_right_r");
#else
test_scan_file_seq_with_views("%V/%v/foo_%V_%v", views2,
"left/l/foo_left_l right/r/foo_right_r");
#endif
}


Expand Down

0 comments on commit 92593fc

Please sign in to comment.