зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1426371 - Fix file/path for Windows binjs jsapi-tests;r=Yoric
This patch fixes several errors in Windows file/path management for the binjs-decoder jsapi-tests: - under Windows, files should be explicitly opened as "binary", otherwise the Windows version of the libc can be creative about their contents; - "*.binjs" should not be part of the path; - I/O functions don't all have the same return value conventions to notify of an error. MozReview-Commit-ID: 51rVpRlcUai --HG-- extra : rebase_source : a7d977c7dc0aecb05c4bbbf4547dedffbd4ec974
This commit is contained in:
Родитель
02ce5d2807
Коммит
4a5148bb3b
|
@ -78,11 +78,12 @@ BEGIN_TEST(testBinASTReaderECMAScript2)
|
|||
|
||||
#elif defined(XP_WIN)
|
||||
|
||||
const char PATH[] = "jsapi-tests\\binast\\parser\\tester\\*.binjs";
|
||||
const char PATTERN[] = "jsapi-tests\\binast\\parser\\tester\\*.binjs";
|
||||
const char PATH[] = "jsapi-tests\\binast\\parser\\tester\\";
|
||||
|
||||
WIN32_FIND_DATA FindFileData;
|
||||
enterJsDirectory();
|
||||
HANDLE hFind = FindFirstFile(PATH, &FindFileData);
|
||||
HANDLE hFind = FindFirstFile(PATTERN, &FindFileData);
|
||||
exitJsDirectory();
|
||||
for (bool found = (hFind != INVALID_HANDLE_VALUE);
|
||||
found;
|
||||
|
|
|
@ -71,21 +71,25 @@ void enterJsDirectory() {
|
|||
|
||||
// Find destination directory, if any.
|
||||
char destination[MAX_PATH];
|
||||
if (!GetEnvironmentVariable("CPP_UNIT_TESTS_DIR_JS_SRC", destination, MAX_PATH)) {
|
||||
if (GetLastError() != ERROR_ENVVAR_NOT_FOUND)
|
||||
MOZ_CRASH("Could not get CPP_UNIT_TESTS_DIR_JS_SRC");
|
||||
result = GetEnvironmentVariable("CPP_UNIT_TESTS_DIR_JS_SRC", destination, MAX_PATH);
|
||||
if (result == 0) {
|
||||
if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
|
||||
return; // No need to chdir
|
||||
else
|
||||
return;
|
||||
MOZ_CRASH("Could not get CPP_UNIT_TESTS_DIR_JS_SRC");
|
||||
}
|
||||
if (result > MAX_PATH) {
|
||||
MOZ_CRASH_UNSAFE_PRINTF("Could not get CPP_UNIT_TESTS_DIR_JS_SRC: needed %ld bytes, got %ld\n", result, MAX_PATH);
|
||||
}
|
||||
|
||||
// Go to the directory.
|
||||
if (SetCurrentDirectory(destination) != 0)
|
||||
if (SetCurrentDirectory(destination) == 0)
|
||||
MOZ_CRASH_UNSAFE_PRINTF("Could not chdir to %s", destination);
|
||||
}
|
||||
|
||||
void exitJsDirectory() {
|
||||
MOZ_ASSERT(strlen(gJsDirectory) > 0);
|
||||
if (SetCurrentDirectory(gJsDirectory) != 0)
|
||||
if (SetCurrentDirectory(gJsDirectory) == 0)
|
||||
MOZ_CRASH("Could not return to original directory");
|
||||
gJsDirectory[0] = 0;
|
||||
}
|
||||
|
@ -95,7 +99,7 @@ void exitJsDirectory() {
|
|||
void readFull(const char* path, js::Vector<uint8_t>& buf) {
|
||||
enterJsDirectory();
|
||||
buf.shrinkTo(0);
|
||||
FILE* in = fopen(path, "r");
|
||||
FILE* in = fopen(path, "rb");
|
||||
if (!in)
|
||||
MOZ_CRASH_UNSAFE_PRINTF("Could not open %s: %s", path, strerror(errno));
|
||||
|
||||
|
@ -110,7 +114,7 @@ void readFull(const char* path, js::Vector<uint8_t>& buf) {
|
|||
if (fclose(in) != 0)
|
||||
MOZ_CRASH("Could not close input file");
|
||||
if (result != info.st_size)
|
||||
MOZ_CRASH("Read error");
|
||||
MOZ_CRASH_UNSAFE_PRINTF("Read error while reading %s: expected %llu bytes, got %llu", path, (unsigned long long)info.st_size, (unsigned long long)result);
|
||||
exitJsDirectory();
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче