From 34b5340d717af65f0968e8a4e2ce1d212e4b813e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 8 Aug 2017 14:03:24 -0700 Subject: [PATCH] Fix paths to corpus files on windows --- test/helpers/file_helpers.cc | 15 ++++++++++++++- test/helpers/file_helpers.h | 1 + test/helpers/load_language.cc | 12 ------------ test/helpers/read_test_entries.cc | 14 ++++++-------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/test/helpers/file_helpers.cc b/test/helpers/file_helpers.cc index 604f5133..48f58891 100644 --- a/test/helpers/file_helpers.cc +++ b/test/helpers/file_helpers.cc @@ -42,6 +42,8 @@ void write_file(const string &path, const string &content) { #include +const char *path_separator = "\\"; + vector list_directory(const string &path) { vector result; @@ -60,6 +62,8 @@ vector list_directory(const string &path) { #include +const char *path_separator = "/"; + vector list_directory(const string &path) { vector result; @@ -81,4 +85,13 @@ vector list_directory(const string &path) { return result; } -#endif \ No newline at end of file +#endif + +string join_path(const vector &parts) { + string result; + for (const string &part : parts) { + if (!result.empty()) result += path_separator; + result += part; + } + return result; +} diff --git a/test/helpers/file_helpers.h b/test/helpers/file_helpers.h index c3d798ea..23867367 100644 --- a/test/helpers/file_helpers.h +++ b/test/helpers/file_helpers.h @@ -10,5 +10,6 @@ int get_modified_time(const std::string &path); std::string read_file(const std::string &path); void write_file(const std::string &path, const std::string &content); std::vector list_directory(const std::string &path); +std::string join_path(const std::vector &parts); #endif // HELPERS_FILE_HELPERS_H_ diff --git a/test/helpers/load_language.cc b/test/helpers/load_language.cc index 872d2d42..8dbeef0b 100644 --- a/test/helpers/load_language.cc +++ b/test/helpers/load_language.cc @@ -25,7 +25,6 @@ int compile_result_count = 0; #include const char *libcompiler_path = "test\\lib\\compiler.lib"; -const char *path_separator = "\\"; const char *dylib_extension = ".dll"; static int compile_parser( @@ -67,13 +66,11 @@ static void *load_function_from_library(string library_path, string function_nam #ifdef __linux const char *libcompiler_path = "out/Test/obj.target/libcompiler.a"; -const char *path_separator = "/"; const char *dylib_extension = ".so"; #else // macOS const char *libcompiler_path = "out/Test/libcompiler.a"; -const char *path_separator = "/"; const char *dylib_extension = ".dylib"; #endif @@ -131,15 +128,6 @@ static void *load_function_from_library(string library_path, string function_nam #endif -string join_path(const vector &parts) { - string result; - for (const string &part : parts) { - if (!result.empty()) result += path_separator; - result += part; - } - return result; -} - static const TSLanguage *load_language(const string &source_filename, const string &lib_filename, const string &language_name, diff --git a/test/helpers/read_test_entries.cc b/test/helpers/read_test_entries.cc index 733522ad..d8df3b03 100644 --- a/test/helpers/read_test_entries.cc +++ b/test/helpers/read_test_entries.cc @@ -12,8 +12,6 @@ using std::smatch; using std::string; using std::vector; -string fixtures_dir = "test/fixtures/"; - static string trim_output(const string &input) { string result(input); result = regex_replace(result, regex("[\n\t ]+", extended), string(" ")); @@ -65,14 +63,14 @@ static vector parse_test_entries(string content) { vector read_real_language_corpus(string language_name) { vector result; - string corpus_directory = fixtures_dir + "grammars/" + language_name + "/corpus"; + string corpus_directory = join_path({"test", "fixtures", "grammars", language_name, "corpus"}); for (string &test_filename : list_directory(corpus_directory)) { for (TestEntry &entry : parse_test_entries(read_file(corpus_directory + "/" + test_filename))) { result.push_back(entry); } } - string error_test_filename = fixtures_dir + "/error_corpus/" + language_name + "_errors.txt"; + string error_test_filename = join_path({"test", "fixtures", "error_corpus", language_name + "_errors.txt"}); for (TestEntry &entry : parse_test_entries(read_file(error_test_filename))) { result.push_back(entry); } @@ -83,9 +81,9 @@ vector read_real_language_corpus(string language_name) { vector read_test_language_corpus(string language_name) { vector result; - string test_directory = fixtures_dir + "test_grammars/" + language_name; + string test_directory = join_path({"test", "fixtures", "test_grammars", language_name}); for (string &test_filename : list_directory(test_directory)) { - for (TestEntry &entry : parse_test_entries(read_file(test_directory + "/" + test_filename))) { + for (TestEntry &entry : parse_test_entries(read_file(join_path({test_directory, test_filename})))) { result.push_back(entry); } } @@ -95,11 +93,11 @@ vector read_test_language_corpus(string language_name) { vector examples_for_language(string language_name) { vector result; - string examples_directory = fixtures_dir + "grammars/" + language_name + "/examples"; + string examples_directory = join_path({"test", "fixtures", "grammars", language_name, "examples"}); for (string &filename : list_directory(examples_directory)) { result.push_back({ filename, - read_file(examples_directory + "/" + filename) + read_file(join_path({examples_directory, filename})) }); } return result;