Extend the tester to compile sources
This commit is contained in:
1
tests/7_member_sum.eln
Normal file
1
tests/7_member_sum.eln
Normal file
@ -0,0 +1 @@
|
||||
! 3 + 4 + 5 + 1 + 2 + 4 + 3
|
3
tests/const_list.eln
Normal file
3
tests/const_list.eln
Normal file
@ -0,0 +1,3 @@
|
||||
const a = 1, b = 2;
|
||||
! a + b
|
||||
.
|
1
tests/expectations/7_member_sum.txt
Normal file
1
tests/expectations/7_member_sum.txt
Normal file
@ -0,0 +1 @@
|
||||
22
|
1
tests/expectations/const_list.txt
Normal file
1
tests/expectations/const_list.txt
Normal file
@ -0,0 +1 @@
|
||||
3
|
1
tests/expectations/left_nested_sum.txt
Normal file
1
tests/expectations/left_nested_sum.txt
Normal file
@ -0,0 +1 @@
|
||||
8
|
1
tests/expectations/print_number.txt
Normal file
1
tests/expectations/print_number.txt
Normal file
@ -0,0 +1 @@
|
||||
3
|
1
tests/expectations/subtraction.txt
Normal file
1
tests/expectations/subtraction.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
1
tests/expectations/sum.txt
Normal file
1
tests/expectations/sum.txt
Normal file
@ -0,0 +1 @@
|
||||
8
|
1
tests/expectations/sums.txt
Normal file
1
tests/expectations/sums.txt
Normal file
@ -0,0 +1 @@
|
||||
8
|
2
tests/left_nested_sum.eln
Normal file
2
tests/left_nested_sum.eln
Normal file
@ -0,0 +1,2 @@
|
||||
! (3 + 4) + 1
|
||||
.
|
2
tests/print_number.eln
Normal file
2
tests/print_number.eln
Normal file
@ -0,0 +1,2 @@
|
||||
! 3
|
||||
.
|
@ -35,11 +35,48 @@ namespace elna
|
||||
}
|
||||
}
|
||||
|
||||
static std::string in_build_directory(const std::filesystem::path& path)
|
||||
{
|
||||
return "build/riscv" / path;
|
||||
}
|
||||
|
||||
static int build_test(const std::filesystem::directory_entry& test_entry)
|
||||
{
|
||||
const std::filesystem::path test_filename = test_entry.path().filename();
|
||||
|
||||
std::filesystem::path test_binary = in_build_directory(test_filename);
|
||||
std::filesystem::path test_object = test_binary;
|
||||
test_binary.replace_extension();
|
||||
test_object.replace_extension(".o");
|
||||
|
||||
std::filesystem::remove(test_binary);
|
||||
std::filesystem::remove(test_object);
|
||||
|
||||
auto status = boost::process::system("./build/bin/elna",
|
||||
"-o", test_object.string(), test_entry.path().string());
|
||||
if (status != 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
status = boost::process::system(
|
||||
"/opt/riscv/bin/riscv32-unknown-elf-ld",
|
||||
"-o", test_binary.string(),
|
||||
"-L/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.0/",
|
||||
"-L/opt/riscv/riscv32-unknown-elf/lib",
|
||||
"/opt/riscv/riscv32-unknown-elf/lib/crt0.o",
|
||||
"/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.0/crtbegin.o",
|
||||
test_object.string(),
|
||||
"--start-group", "-lgcc", "-lc", "-lgloss", "--end-group",
|
||||
"/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.0/crtend.o"
|
||||
);
|
||||
return status;
|
||||
}
|
||||
|
||||
static int run_test(const std::filesystem::directory_entry& test_entry)
|
||||
{
|
||||
const std::filesystem::path test_filename = test_entry.path().filename();
|
||||
|
||||
std::filesystem::path test_binary = "build/riscv" / test_filename;
|
||||
std::filesystem::path test_binary = in_build_directory(test_filename);
|
||||
test_binary.replace_extension();
|
||||
|
||||
std::filesystem::path expectation_path = test_entry.path().parent_path() / "expectations" / test_filename;
|
||||
@ -75,7 +112,23 @@ namespace elna
|
||||
{
|
||||
continue;
|
||||
}
|
||||
results.add_exit_code(run_test(test_entry));
|
||||
int status{ 0 };
|
||||
|
||||
try
|
||||
{
|
||||
status = build_test(test_entry);
|
||||
}
|
||||
catch (const boost::process::process_error& exception)
|
||||
{
|
||||
std::cout << exception.what() << std::endl;
|
||||
status = 3;
|
||||
continue;
|
||||
}
|
||||
if (status == 0)
|
||||
{
|
||||
status = run_test(test_entry);
|
||||
}
|
||||
results.add_exit_code(status);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
2
tests/subtraction.eln
Normal file
2
tests/subtraction.eln
Normal file
@ -0,0 +1,2 @@
|
||||
! 5 - 4
|
||||
.
|
2
tests/sum.eln
Normal file
2
tests/sum.eln
Normal file
@ -0,0 +1,2 @@
|
||||
! 1 + 7
|
||||
.
|
2
tests/sums.eln
Normal file
2
tests/sums.eln
Normal file
@ -0,0 +1,2 @@
|
||||
! 1 + (3 + 4)
|
||||
.
|
Reference in New Issue
Block a user