Fix paths to corpus files on windows
This commit is contained in:
parent
ac99985a97
commit
34b5340d71
4 changed files with 21 additions and 21 deletions
|
|
@ -42,6 +42,8 @@ void write_file(const string &path, const string &content) {
|
|||
|
||||
#include <windows.h>
|
||||
|
||||
const char *path_separator = "\\";
|
||||
|
||||
vector<string> list_directory(const string &path) {
|
||||
vector<string> result;
|
||||
|
||||
|
|
@ -60,6 +62,8 @@ vector<string> list_directory(const string &path) {
|
|||
|
||||
#include <dirent.h>
|
||||
|
||||
const char *path_separator = "/";
|
||||
|
||||
vector<string> list_directory(const string &path) {
|
||||
vector<string> result;
|
||||
|
||||
|
|
@ -81,4 +85,13 @@ vector<string> list_directory(const string &path) {
|
|||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
string join_path(const vector<string> &parts) {
|
||||
string result;
|
||||
for (const string &part : parts) {
|
||||
if (!result.empty()) result += path_separator;
|
||||
result += part;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<std::string> list_directory(const std::string &path);
|
||||
std::string join_path(const std::vector<std::string> &parts);
|
||||
|
||||
#endif // HELPERS_FILE_HELPERS_H_
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ int compile_result_count = 0;
|
|||
#include <windows.h>
|
||||
|
||||
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<string> &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,
|
||||
|
|
|
|||
|
|
@ -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<TestEntry> parse_test_entries(string content) {
|
|||
vector<TestEntry> read_real_language_corpus(string language_name) {
|
||||
vector<TestEntry> 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<TestEntry> read_real_language_corpus(string language_name) {
|
|||
vector<TestEntry> read_test_language_corpus(string language_name) {
|
||||
vector<TestEntry> 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<TestEntry> read_test_language_corpus(string language_name) {
|
|||
|
||||
vector<ExampleEntry> examples_for_language(string language_name) {
|
||||
vector<ExampleEntry> 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue