Skip to content

Commit

Permalink
wip: windows
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFola committed Feb 21, 2024
1 parent 39da9c0 commit 679d938
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ jobs:
- name: Setup tests
uses: ./.github/workflows/setup-tests

- name: Unit tests
- name: C++ unit tests
shell: bash
run: |
export ASAN_OPTIONS=detect_odr_violation=0
./unittests
- name: Unit tests
- name: ArkScript unit tests
shell: bash
run: |
export ASAN_OPTIONS=detect_odr_violation=0
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ if (ARK_TESTS)

add_compile_definitions(BOOST_UT_DISABLE_MODULE)
target_compile_features(unittests PRIVATE cxx_std_20)
target_compile_definitions(unittests PRIVATE ARK_TESTS_ROOT="${CMAKE_CURRENT_SOURCE_DIR}/")
endif()

if (ARK_BUILD_EXE)
Expand Down
13 changes: 7 additions & 6 deletions tests/unittests/ASTSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@ ut::suite<"AST"> ast_suite = [] {
using namespace ut;

"[generate valid ast]"_test = [] {
for (const auto& entry : fs::directory_iterator("tests/unittests/resources/ASTSuite"))
for (const auto& entry : fs::directory_iterator(ARK_TESTS_ROOT "tests/unittests/resources/ASTSuite"))
{
if (entry.path().extension() != ".ark")
continue;

std::string path = entry.path().string();
std::string stem = entry.path().stem().string();
std::string path = entry.path().generic_string();
std::string stem = entry.path().stem().generic_string();
fs::path expected_path = entry.path();
expected_path.replace_extension("json");

Ark::JsonCompiler compiler(false, { "lib/std/" });
Ark::JsonCompiler compiler(false, { ARK_TESTS_ROOT "lib/std/" });

should("parse " + stem + " and generate a valid AST") = [&] {
std::string test_name = "parse " + stem + " and generate a valid AST";
should(std::string_view(test_name)) = [&] {
expect(nothrow([&] {
mut(compiler).feed(path);
}));

std::string json = compiler.compile();
std::string expected = Ark::Utils::readFile(expected_path.string());
std::string expected = Ark::Utils::readFile(expected_path.generic_string());
expect(that % json == expected);
};
}
Expand Down
32 changes: 22 additions & 10 deletions tests/unittests/ParserSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <termcolor/proxy.hpp>

#include <sstream>
#include <algorithm>
#include <filesystem>

namespace fs = std::filesystem;
Expand Down Expand Up @@ -48,15 +49,15 @@ ut::suite<"Parser"> parser_suite = [] {
using namespace ut;

"[successful parsing]"_test = [] {
for (const auto& entry : fs::directory_iterator("tests/unittests/resources/ParserSuite/success"))
for (const auto& entry : fs::directory_iterator(ARK_TESTS_ROOT "tests/unittests/resources/ParserSuite/success"))
{
if (entry.path().extension() != ".ark")
continue;

Ark::internal::Parser parser;

std::string path = entry.path().string();
std::string stem = entry.path().stem().string();
std::string path = entry.path().generic_string();
std::string stem = entry.path().stem().generic_string();
fs::path expected_path = entry.path();
expected_path.replace_extension("expected");

Expand All @@ -69,22 +70,25 @@ ut::suite<"Parser"> parser_suite = [] {
// expect(that % parser.ast().constList().size() >= 1_u);
std::string ast = astToString(parser);

should("output the same AST and imports (" + stem + ")") = [&] {
expect(that % ast == Ark::Utils::readFile(expected_path.string()));
std::string test_name = "output the same AST and imports (" + stem + ")";
should(std::string_view(test_name)) = [&] {
std::string file = Ark::Utils::readFile(expected_path.generic_string());
file.erase(std::remove(file.begin(), file.end(), '\r'), file.end());
expect(that % ast == file);
};
}
};

"[error reporting]"_test = [] {
for (const auto& entry : fs::directory_iterator("tests/unittests/resources/ParserSuite/failure"))
for (const auto& entry : fs::directory_iterator(ARK_TESTS_ROOT "tests/unittests/resources/ParserSuite/failure"))
{
if (entry.path().extension() != ".ark")
continue;

Ark::internal::Parser parser;

std::string path = entry.path().string();
std::string stem = entry.path().stem().string();
std::string path = entry.path().generic_string();
std::string stem = entry.path().stem().generic_string();
fs::path expected_path = entry.path();
expected_path.replace_extension("expected");

Expand All @@ -98,8 +102,16 @@ ut::suite<"Parser"> parser_suite = [] {
ss << termcolor::nocolorize;
Ark::Diagnostics::generate(e, "", ss);

should("output the same error message (" + stem + ")") = [&] {
expect(that % ss.str() == Ark::Utils::readFile(expected_path.string()));
std::string test_name = "output the same error message (" + stem + ")";
should(std::string_view(test_name)) = [&] {
std::string file = Ark::Utils::readFile(expected_path.generic_string());
file.erase(std::remove(file.begin(), file.end(), '\r'), file.end());

std::string tested = ss.str();
tested.erase(std::remove(tested.begin(), tested.end(), '\r'), tested.end());
tested.erase(tested.find(ARK_TESTS_ROOT), std::size(ARK_TESTS_ROOT) - 1);

expect(that % tested == file);
};
}
catch (...)
Expand Down

0 comments on commit 679d938

Please sign in to comment.