-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add parsing of task_id, test_code and user_output to bring t…
…est-runner to v3 (#72) * Update Catch2 version to introduce tags as task_id * Update to alpine to use c++ formatter * Add code for cpp xml2json parser * Add test for task_id in test case * Update expected results for new catch2, alpine and v3 version * Add new parser compilation * Change parsing to new cpp version * Remove Python parsing content * Add test case for user output * Add json parsing of cout user output * Add auto conversion to work with Catch2 v2 and v3 * Add test case for catch2 version conversion * Add test_case data generation * Update call and compilation of the parser * Update expected results to include test_case data * Add test case for test_case data parsing
- Loading branch information
Showing
47 changed files
with
60,632 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <algorithm> | ||
#include <functional> | ||
#include <cctype> | ||
#include <locale> | ||
|
||
|
||
// trimming function taken from: https://stackoverflow.com/a/217605/4919081 | ||
|
||
// trim from start (in place) | ||
static inline void ltrim(std::string &s) | ||
{ | ||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), | ||
std::not1(std::ptr_fun<int, int>(std::isspace)))); | ||
} | ||
|
||
// trim from end (in place) | ||
static inline void rtrim(std::string &s) | ||
{ | ||
s.erase(std::find_if(s.rbegin(), s.rend(), | ||
std::not1(std::ptr_fun<int, int>(std::isspace))) | ||
.base(), | ||
s.end()); | ||
} | ||
|
||
// trim from both ends (in place) | ||
static inline void trim(std::string &s) | ||
{ | ||
rtrim(s); | ||
ltrim(s); | ||
} | ||
|
||
// trim from start (copying) | ||
static inline std::string ltrim_copy(std::string s) | ||
{ | ||
ltrim(s); | ||
return s; | ||
} | ||
|
||
// trim from end (copying) | ||
static inline std::string rtrim_copy(std::string s) | ||
{ | ||
rtrim(s); | ||
return s; | ||
} | ||
|
||
// trim from both ends (copying) | ||
static inline std::string trim_copy(std::string s) | ||
{ | ||
trim(s); | ||
return s; | ||
} | ||
|
||
static inline std::string read_file(std::string_view path) | ||
{ | ||
constexpr auto read_size = std::size_t(4096); | ||
auto stream = std::ifstream(path.data()); | ||
stream.exceptions(std::ios_base::badbit); | ||
|
||
if (not stream) | ||
{ | ||
return "compilation error file does not exist"; | ||
} | ||
|
||
auto out = std::string(); | ||
auto buf = std::string(read_size, '\0'); | ||
while (stream.read(&buf[0], read_size)) | ||
{ | ||
out.append(buf, 0, stream.gcount()); | ||
} | ||
out.append(buf, 0, stream.gcount()); | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <boost/property_tree/ptree.hpp> | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace pt = boost ::property_tree; | ||
|
||
struct Test_result | ||
{ | ||
std::string name{}; | ||
std::string status{}; | ||
std::string message{}; | ||
std::string output{}; | ||
std::string test_code{}; | ||
int task_id{}; | ||
void add_result_to_json(std::ofstream &json_file) const; | ||
}; | ||
|
||
struct Output_message | ||
{ | ||
int version{3}; | ||
std::string status{}; | ||
std::string message{}; | ||
std::vector<Test_result> tests{}; | ||
void load_from_catch2_xml(const std::string &xml_test_output_file, const std::string &compilation_error_file); | ||
void save_as_exercism_json(const std::string &filename); | ||
std::string build_test_message(const pt::ptree &tree); | ||
void generate_test_code_from_test_file(const std::string &test_file_path); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <iostream> | ||
#include "xml2json.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
if (argc < 5) | ||
{ | ||
std::cout << "Input, output, compilation errors, and test file names are required but were not supplied.\n" | ||
<< "Usage: " << argv[0] << " input_file_name output_file_name compilation_errors_file_name test_file_path\n"; | ||
return -1; | ||
} | ||
|
||
std::string input_file_file_name_path{argv[1]}; | ||
std::string output_file_file_name_path{argv[2]}; | ||
std::string compilation_errors_file_name_path{argv[3]}; | ||
std::string test_file_path{argv[4]}; | ||
|
||
try | ||
{ | ||
Output_message om{}; | ||
om.load_from_catch2_xml(input_file_file_name_path, compilation_errors_file_name_path); | ||
om.generate_test_code_from_test_file(test_file_path); | ||
om.save_as_exercism_json(output_file_file_name_path); | ||
} | ||
catch (std::exception &e) | ||
{ | ||
std::cout << "Error: " << e.what() << "\n"; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.