Skip to content

Commit

Permalink
feat(tests): moving the parser tests under tests/unittests using boos…
Browse files Browse the repository at this point in the history
…t:ut
  • Loading branch information
SuperFola committed Jan 15, 2024
1 parent 3a59548 commit 619bffc
Show file tree
Hide file tree
Showing 79 changed files with 193 additions and 175 deletions.
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ option(ARK_PROFILER_MIPS "Enable MIPS calculation" Off)
option(ARK_NO_STDLIB "Do not install the standard library with the Ark library" Off)
option(ARK_BUILD_MODULES "Build the std library modules or not" Off)
option(ARK_SANITIZERS "Enable ASAN and UBSAN" Off)
option(ARK_TESTS "Build ArkScript unit tests" Off)

if (ARK_PROFILER_COUNT)
target_compile_definitions(ArkReactor PRIVATE -DARK_PROFILER_COUNT)
Expand All @@ -170,10 +171,15 @@ if (ARK_BUILD_MODULES)
add_subdirectory(${ark_SOURCE_DIR}/lib/modules)
endif()

if (ARK_BUILD_PARSER_TESTS)
add_executable(parser ${ark_SOURCE_DIR}/tests/parser/main.cpp)
target_link_libraries(parser PUBLIC ArkReactor)
target_compile_features(parser PRIVATE cxx_std_17)
# TODO: consider using ctest
if (ARK_TESTS)
file(GLOB_RECURSE UT_SOURCES ${ark_SOURCE_DIR}/tests/unittests/*.cpp)
add_executable(unittests ${UT_SOURCES})

target_include_directories(unittests PUBLIC ${ark_SOURCE_DIR}/lib/ut/include)
target_link_libraries(unittests PUBLIC ArkReactor termcolor)

target_compile_features(unittests PRIVATE cxx_std_20)
endif()

if (ARK_BUILD_EXE)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Different CMake switches are available to customize the build:
* `-DARK_NO_STDLIB` to avoid the installation of the ArkScript standard library
* `-DARK_BUILD_MODULES` to trigger the modules build
* `-DARK_SANITIZERS` to enable ASAN and UBSAN
* `-DARK_TESTS` to build the unit tests (separate target named `unittests`)

```bash
# first, clone it
Expand Down Expand Up @@ -240,6 +241,6 @@ This project was inspired by [gameprogramingpatterns](http://gameprogrammingpatt

## Copyright and Licence information

Copyright (c) 2019-2021 Alexandre Plateau. All rights reserved.
Copyright (c) 2019-2024 Alexandre Plateau. All rights reserved.

This ArkScript distribution contains no GNU GPL code, which means it can be used in proprietary projects.
8 changes: 5 additions & 3 deletions include/Ark/Exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file Exceptions.hpp
* @author Alexandre Plateau ([email protected]), Max ([email protected])
* @brief ArkScript homemade exceptions
* @version 1.0
* @version 1.1
* @date 2020-10-27
*
* @copyright Copyright (c) 2020-2021
* @copyright Copyright (c) 2020-2024
*
*/

Expand All @@ -20,6 +20,7 @@
#include <optional>
#include <ostream>
#include <iomanip>
#include <iostream>

#include <Ark/Compiler/AST/utf8_char.hpp>
#include <Ark/Platform.hpp>
Expand Down Expand Up @@ -144,8 +145,9 @@ namespace Ark
*
* @param e code error
* @param code code of the file in which the error occurred
* @param os output stream
*/
ARK_API void generate(const CodeError& e, std::string code = "");
ARK_API void generate(const CodeError& e, std::string code = "", std::ostream& os = std::cout);
}
}

Expand Down
21 changes: 8 additions & 13 deletions src/arkreactor/Exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Ark::Diagnostics
return c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}';
}

std::string colorizeLine(const std::string& line, LineColorContextCounts& line_color_context_counts)
void colorizeLine(const std::string& line, LineColorContextCounts& line_color_context_counts, std::ostream& ss)
{
constexpr std::array<std::ostream& (*)(std::ostream& stream), 3> pairing_color {
termcolor::bright_blue,
Expand All @@ -30,9 +30,6 @@ namespace Ark::Diagnostics
};
std::size_t pairing_color_size = pairing_color.size();

std::stringstream colorized_line;
colorized_line << termcolor::colorize;

for (const char& c : line)
{
if (isPairableChar(c))
Expand Down Expand Up @@ -69,18 +66,15 @@ namespace Ark::Diagnostics
break;
}

colorized_line << pairing_color[pairing_color_index] << c << termcolor::reset;
ss << pairing_color[pairing_color_index] << c << termcolor::reset;
}
else
colorized_line << c;
ss << c;
}

return colorized_line.str();
}

void makeContext(std::ostream& os, const std::string& code, std::size_t target_line, std::size_t col_start, std::size_t sym_size)
{
os << termcolor::colorize;
std::vector<std::string> ctx = Utils::splitString(code, '\n');

std::size_t first_line = target_line >= 3 ? target_line - 3 : 0;
Expand All @@ -90,8 +84,9 @@ namespace Ark::Diagnostics

for (auto i = first_line; i < last_line; ++i)
{
os << termcolor::green << std::setw(5) << (i + 1) << termcolor::reset
<< " | " << colorizeLine(ctx[i], line_color_context_counts) << "\n";
os << termcolor::green << std::setw(5) << (i + 1) << termcolor::reset << " | ";
colorizeLine(ctx[i], line_color_context_counts, os);
os << "\n";

if (i == target_line || (i > target_line && overflow > 0))
{
Expand Down Expand Up @@ -156,7 +151,7 @@ namespace Ark::Diagnostics
return ss.str();
}

void generate(const CodeError& e, std::string code)
void generate(const CodeError& e, std::string code, std::ostream& os)
{
std::string escaped_symbol;
if (e.symbol.has_value())
Expand Down Expand Up @@ -184,7 +179,7 @@ namespace Ark::Diagnostics

// TODO enhance the error messages
helper(
std::cout,
os,
e.what(),
e.filename,
file_content,
Expand Down
60 changes: 0 additions & 60 deletions tests/parser/main.cpp

This file was deleted.

5 changes: 0 additions & 5 deletions tests/parser/tests/incomplete_arguments.expected

This file was deleted.

5 changes: 0 additions & 5 deletions tests/parser/tests/incomplete_del.expected

This file was deleted.

5 changes: 0 additions & 5 deletions tests/parser/tests/incomplete_macro_arguments.expected

This file was deleted.

49 changes: 0 additions & 49 deletions tests/parser/tests/run

This file was deleted.

12 changes: 12 additions & 0 deletions tests/unittests/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <boost/ut.hpp>

int main(int argc, const char** argv)
{
using namespace boost;
using namespace boost::ut::literals;
using namespace boost::ut::operators;

ut::expect((argc == 2_i) >> ut::fatal) << "Not enough parameters!";
ut::cfg<ut::override> = { .filter = argv[1] };
return ut::cfg<ut::override>.run();
}
Loading

0 comments on commit 619bffc

Please sign in to comment.