Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added angry
Empty file.
Empty file added file
Empty file.
8 changes: 6 additions & 2 deletions src/arkreactor/Error/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ namespace Ark::Diagnostics
else if (maybe_context && !ctx_same_file && !maybe_context->filename.empty())
{
// show the location of the parent of our error first
fmt::print(os, "Error originated from file {}:{}\n", maybe_context->filename, maybe_context->at.start.line + 1);
std::string uniformised_filename;
std::ranges::replace_copy(maybe_context->filename, std::back_inserter(uniformised_filename), '\\', '/');
fmt::print(os, "Error originated from file {}:{}\n", uniformised_filename, maybe_context->at.start.line + 1);

std::optional<decltype(internal::FilePos::line)> maybe_end_line = std::nullopt;
if (maybe_context->at.end)
Expand Down Expand Up @@ -193,9 +195,11 @@ namespace Ark::Diagnostics
const std::string& filename, const internal::FileSpan& at,
const std::optional<CodeErrorContext>& maybe_context = std::nullopt)
{
std::string uniformised_filename;
std::ranges::replace_copy(filename, std::back_inserter(uniformised_filename), '\\', '/');
makeContext(
ErrorLocation {
.filename = filename,
.filename = uniformised_filename,
.start = at.start,
.end = at.end },
os, maybe_context, colorize);
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/Suites/CompilerSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ut::suite<"Compiler"> compiler_suite = [] {

iterTestFiles(
"CompilerSuite/ir",
[](TestData&& data) {
[](const TestData& data) {
Ark::Welder welder(0, { lib_path }, features);

should("compile without error ir/" + data.stem) = [&] {
Expand All @@ -103,7 +103,7 @@ ut::suite<"Compiler"> compiler_suite = [] {

iterTestFiles(
"CompilerSuite/optimized_ir",
[](TestData&& data) {
[](const TestData& data) {
Ark::Welder welder(0, { lib_path }, features);

should("compile without error optimized_ir/" + data.stem) = [&] {
Expand Down
6 changes: 3 additions & 3 deletions tests/unittests/Suites/DiagnosticsSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ut::suite<"Diagnostics"> diagnostics_suite = [] {

iterTestFiles(
"DiagnosticsSuite/compileTime",
[](TestData&& data) {
[](const TestData& data) {
Ark::State state({ lib_path });

should("generate an error message at compile time for compileTime/" + data.stem) = [&] {
Expand All @@ -36,7 +36,7 @@ ut::suite<"Diagnostics"> diagnostics_suite = [] {

iterTestFiles(
"DiagnosticsSuite/runtime",
[](TestData&& data) {
[](const TestData& data) {
Ark::State state({ lib_path });

should("compile without error runtime/" + data.stem) = [&] {
Expand All @@ -62,7 +62,7 @@ ut::suite<"Diagnostics"> diagnostics_suite = [] {

iterTestFiles(
"DiagnosticsSuite/typeChecking",
[](TestData&& data) {
[](const TestData& data) {
Ark::State state({ lib_path });

should("compile without error typeChecking/" + data.stem) = [&] {
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/Suites/FormatterSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ut::suite<"Formatter"> formatter_suite = [] {

iterTestFiles(
"FormatterSuite",
[](TestData&& data) {
[](const TestData& data) {
std::string formatted_code;

should("output a correctly formatted code for " + data.stem) = [&] {
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/Suites/OptimizerSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ut::suite<"Optimizer"> optimizer_suite = [] {
"[generate optimized ast]"_test = [] {
iterTestFiles(
"OptimizerSuite",
[](TestData&& data) {
[](const TestData& data) {
JsonCompiler compiler(false, { lib_path }, Ark::FeatureASTOptimizer);

std::string json;
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/Suites/ParserSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ut::suite<"Parser"> parser_suite = [] {
"[successful parsing]"_test = [] {
iterTestFiles(
"ParserSuite/success",
[](TestData&& data) {
[](const TestData& data) {
Ark::internal::Parser parser(/* debug= */ 0);

should("parse " + data.stem) = [&] {
Expand All @@ -68,7 +68,7 @@ ut::suite<"Parser"> parser_suite = [] {
"[error reporting]"_test = [] {
iterTestFiles(
"ParserSuite/failure",
[](TestData&& data) {
[](const TestData& data) {
try
{
Ark::internal::Parser parser(/* debug= */ 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/Suites/RosettaSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ut::suite<"Rosetta"> rosetta_suite = [] {
"[run arkscript rosetta code solutions]"_test = [] {
iterTestFiles(
"RosettaSuite",
[](TestData&& data) {
[](const TestData&data) {
Ark::State state({ lib_path });

should("compile " + data.stem) = [&] {
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/Suites/TypeCheckerSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ ut::suite<"TypeChecker"> type_checker_suite = [] {

iterTestFiles(
"TypeCheckerSuite",
[&](TestData&& data) {
[&](const TestData& data) {
std::vector<Input> inputs;
std::vector<Ark::types::Contract> contracts;

if (data.is_folder)
{
iterTestFiles(
data.path,
[&inputs](TestData&& inner) {
[&inputs](const TestData& inner) {
const Input input = parse_input(inner.path);
expect(fatal(input.initialized)) << "invalid test input: " << inner.stem;
inputs.push_back(input);
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/Suites/ValidAstSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ut::suite<"AST"> ast_suite = [] {
"[generate valid ast]"_test = [] {
iterTestFiles(
"ASTSuite",
[](TestData&& data) {
[](const TestData& data) {
JsonCompiler compiler(false, { lib_path });

std::string json;
Expand Down
5 changes: 3 additions & 2 deletions tests/unittests/TestsHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void updateExpectedFile(const TestData& data, const std::string& actual)
}
}

void iterTestFiles(const std::string& folder, std::function<void(TestData&&)>&& test, IterTestFilesParam&& params)
void iterTestFiles(const std::string& folder, std::function<void(const TestData&)>&& test, IterTestFilesParam&& params)
{
boost::ut::test(folder) = [&] {
const auto path = params.folder_is_resource ? getResourcePath(folder) : folder;
Expand Down Expand Up @@ -58,7 +58,7 @@ void iterTestFiles(const std::string& folder, std::function<void(TestData&&)>&&
.is_folder = is_directory(entry.path())
};

test(std::move(data));
test(data);
}
};
}
Expand All @@ -75,6 +75,7 @@ std::string sanitizeCodeError(const Ark::CodeError& e)

std::string diag = stream.str();
diag.erase(std::ranges::remove(diag, '\r').begin(), diag.end());

while (diag.find(ARK_TESTS_ROOT) != std::string::npos)
diag.erase(diag.find(ARK_TESTS_ROOT), std::size(ARK_TESTS_ROOT) - 1);

Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/TestsHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void updateExpectedFile(const TestData& data, const std::string& actual);
* @param test test function, taking a TestData&& with the paths of the input and its expected result
* @param params optionally specify the expected extension. Defaults to "expected"
*/
void iterTestFiles(const std::string& folder, std::function<void(TestData&&)>&& test, IterTestFilesParam&& params = {});
void iterTestFiles(const std::string& folder, std::function<void(const TestData&)>&& test, IterTestFilesParam&& params = {});

/**
* @brief Given an input folder, returns the resource path relatives to the project root
Expand Down
Loading