Skip to content

Commit eba51ae

Browse files
committed
fix(test): make tests pass in Italian locale
If the system is in an Italian locale (or perhaps Brazilian or other locales), some test_file tests fail: test-file.cpp:79: Failure Value of: file_content.error().to_string() Expected: (has substring "No such file") or (has substring "cannot find") Actual: "failed to read from /tmp/quick-lint-js.3SzKMa/does-not-exist.js: File o directory non esistente" [ FAILED ] test_file.read_non_existing_file (0 ms) test-file.cpp:91: Failure Value of: file_content.error().to_string() Expected: (has substring "Is a directory") or (has substring "Access is denied") Actual: "failed to read from /tmp/quick-lint-js.1PkP4o: \xC3\x88 una directory" As Text: "failed to read from /tmp/quick-lint-js.1PkP4o: È una directory" [ FAILED ] test_file.read_directory (0 ms) Fix these tests by checking error codes instead of strings. This patch should address the following issues: * #751 * #80
1 parent 3d40711 commit eba51ae

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Semantic Versioning.
3232
as the use of a variable called `async` followed by a non-async function, per
3333
the language standard.
3434
* `((x)) => {}` no longer crashes the parser with an assertion failure.
35+
* Tests now pass if the user's locale is Italian (`it_IT.utf8` on Linux).
3536

3637
## 2.5.0 (2022-05-23)
3738

test/test-file.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#include <type_traits>
3434
#include <vector>
3535

36+
#if QLJS_HAVE_WINDOWS_H
37+
#include <quick-lint-js/windows.h>
38+
#endif
39+
3640
#if QLJS_HAVE_MKFIFO
3741
#include <sys/stat.h>
3842
#include <sys/types.h>
@@ -76,8 +80,13 @@ TEST_F(test_file, read_non_existing_file) {
7680
EXPECT_FALSE(file_content.ok());
7781
EXPECT_TRUE(file_content.error().is_file_not_found_error());
7882
EXPECT_THAT(file_content.error().to_string(), HasSubstr("does-not-exist.js"));
79-
EXPECT_THAT(file_content.error().to_string(),
80-
AnyOf(HasSubstr("No such file"), HasSubstr("cannot find")));
83+
#if QLJS_HAVE_UNISTD_H
84+
EXPECT_EQ(file_content.error().io_error.error, ENOENT);
85+
#elif QLJS_HAVE_WINDOWS_H
86+
EXPECT_EQ(file_content.error().io_error.error, ERROR_FILE_NOT_FOUND);
87+
#else
88+
#error "Unknown platform"
89+
#endif
8190
}
8291

8392
TEST_F(test_file, read_directory) {
@@ -88,12 +97,13 @@ TEST_F(test_file, read_directory) {
8897
EXPECT_FALSE(file_content.ok());
8998
EXPECT_FALSE(file_content.error().is_file_not_found_error());
9099
EXPECT_THAT(file_content.error().to_string(), HasSubstr(temp_file_path));
91-
EXPECT_THAT(
92-
file_content.error().to_string(),
93-
testing::AnyOf(
94-
HasSubstr("Is a directory"),
95-
HasSubstr("Access is denied") // TODO(strager): Improve this message.
96-
));
100+
#if QLJS_HAVE_UNISTD_H
101+
EXPECT_EQ(file_content.error().io_error.error, EISDIR);
102+
#elif QLJS_HAVE_WINDOWS_H
103+
EXPECT_EQ(file_content.error().io_error.error, ERROR_ACCESS_DENIED);
104+
#else
105+
#error "Unknown platform"
106+
#endif
97107
}
98108

99109
#if QLJS_HAVE_MKFIFO

0 commit comments

Comments
 (0)