-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tooling: add testharnish and a great some first tests (#28)
Additions: * CBuilder JUNIT Tests * CBuilder JUNIT System-Tests * C-Runtime Catch2 System-Tests * Gtihub Action test_suite.yml
- Loading branch information
Showing
131 changed files
with
9,433 additions
and
554 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 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
126 changes: 126 additions & 0 deletions
126
c-runtime/test/Systemtests/ArithmeticOps/TestArithmeticOps.cpp
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,126 @@ | ||
#define CATCH_CONFIG_MAIN | ||
|
||
#include <stddef.h> | ||
|
||
#include "catch_amalgamated.hpp" | ||
#include "assert.h" | ||
#include "mpy_aliases.h" | ||
#include "mpy_obj.h" | ||
#include "builtins-setup.h" | ||
#include "function-args.h" | ||
#include "literals/tuple.h" | ||
#include "literals/int.h" | ||
#include "literals/boolean.h" | ||
#include "literals/str.h" | ||
#include "type-hierarchy/object.h" | ||
#include "type-hierarchy/type.h" | ||
#include "test/test_helpers.h" | ||
|
||
int add_op(int i, int j){ | ||
__MPyObj *a; | ||
|
||
__mpy_builtins_setup(); | ||
a = __mpy_obj_init_object(); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
a = __mpy_call(__mpy_obj_get_attr(__mpy_obj_init_int(i), "__add__"), __mpy_tuple_assign(0, __mpy_obj_init_int(j), __mpy_obj_init_tuple(1)), NULL); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
|
||
printf("[ADD] i : %d --- j : %d\n",i,j); | ||
print_mpyobj_int(a); | ||
|
||
__mpy_builtins_cleanup(); | ||
|
||
return (*(int*)(a->content)) == (i+j) ? 1 : 0; | ||
} | ||
|
||
int sub_op(int i, int j){ | ||
__MPyObj *a; | ||
|
||
__mpy_builtins_setup(); | ||
a = __mpy_obj_init_object(); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
a = __mpy_call(__mpy_obj_get_attr(__mpy_obj_init_int(i), "__sub__"), __mpy_tuple_assign(0, __mpy_obj_init_int(j), __mpy_obj_init_tuple(1)), NULL); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
|
||
printf("[SUB] i : %d --- j : %d\n",i,j); | ||
print_mpyobj_int(a); | ||
|
||
__mpy_builtins_cleanup(); | ||
|
||
return (*(int*)(a->content)) == (i-j) ? 1 : 0; | ||
} | ||
|
||
int mul_op(int i, int j){ | ||
__MPyObj *a; | ||
|
||
__mpy_builtins_setup(); | ||
a = __mpy_obj_init_object(); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
a = __mpy_call(__mpy_obj_get_attr(__mpy_obj_init_int(i), "__mul__"), __mpy_tuple_assign(0, __mpy_obj_init_int(j), __mpy_obj_init_tuple(1)), NULL); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
|
||
printf("[MUL] i : %d --- j : %d\n",i,j); | ||
print_mpyobj_int(a); | ||
|
||
__mpy_builtins_cleanup(); | ||
|
||
return (*(int*)(a->content)) == (i*j) ? 1 : 0; | ||
} | ||
|
||
int div_op(int i, int j){ | ||
__MPyObj *a; | ||
|
||
__mpy_builtins_setup(); | ||
a = __mpy_obj_init_object(); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
a = __mpy_call(__mpy_obj_get_attr(__mpy_obj_init_int(i), "__div__"), __mpy_tuple_assign(0, __mpy_obj_init_int(j), __mpy_obj_init_tuple(1)), NULL); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
|
||
printf("[DIV] i : %d --- j : %d\n",i,j); | ||
print_mpyobj_int(a); | ||
|
||
__mpy_builtins_cleanup(); | ||
|
||
return (*(int*)(a->content)) == (i/j) ? 1 : 0; | ||
} | ||
|
||
|
||
TEST_CASE("GENERATE ADD OP"){ | ||
auto i = GENERATE(1, 3, 5); | ||
auto j = GENERATE(2, 4, 6); | ||
CHECK(add_op(i, j) == 1); | ||
} | ||
|
||
TEST_CASE("GENERATE SUB OP"){ | ||
auto i = GENERATE(1, 3, 5); | ||
auto j = GENERATE(2, 4, 6); | ||
CHECK(sub_op(i, j) == 1); | ||
} | ||
|
||
TEST_CASE("GENERATE MUL OP"){ | ||
auto i = GENERATE(1, 3, 5); | ||
auto j = GENERATE(2, 4, 6); | ||
CHECK(mul_op(i, j) == 1); | ||
} | ||
|
||
TEST_CASE("GENERATE DIV OP"){ | ||
auto i = GENERATE(3, 8, 12); | ||
auto j = GENERATE(2, 4, 6); | ||
CHECK(div_op(i, j) == 1); | ||
} |
103 changes: 103 additions & 0 deletions
103
c-runtime/test/Systemtests/BuiltInFunctions/TestCastInt.cpp
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,103 @@ | ||
#define CATCH_CONFIG_MAIN | ||
|
||
#include <stddef.h> | ||
|
||
#include "catch_amalgamated.hpp" | ||
#include "assert.h" | ||
#include "mpy_aliases.h" | ||
#include "mpy_obj.h" | ||
#include "builtins-setup.h" | ||
#include "function-args.h" | ||
#include "literals/tuple.h" | ||
#include "literals/int.h" | ||
#include "literals/boolean.h" | ||
#include "literals/str.h" | ||
#include "type-hierarchy/object.h" | ||
#include "type-hierarchy/type.h" | ||
#include "test/test_helpers.h" | ||
|
||
void exit(int status) { | ||
throw std::runtime_error("Error"); | ||
} | ||
|
||
int cast_bool_to_int(bool input){ | ||
__MPyObj *a; | ||
|
||
__mpy_builtins_setup(); | ||
a = __mpy_obj_init_object(); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
a = __mpy_obj_init_boolean(input); | ||
__mpy_obj_ref_inc(a); | ||
|
||
a = __mpy_call(__mpy_obj_get_attr(a, "__int__"), __mpy_obj_init_tuple(0), NULL); | ||
|
||
__mpy_obj_ref_dec(a); | ||
|
||
print_mpyobj_int(a); | ||
|
||
__mpy_builtins_cleanup(); | ||
|
||
return (*(int*)(a->content)); | ||
} | ||
|
||
int cast_string_to_int(const char* input){ | ||
__MPyObj *a; | ||
|
||
__mpy_builtins_setup(); | ||
a = __mpy_obj_init_object(); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
a = __mpy_obj_init_str_static(input); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
a = __mpy_call(__mpy_obj_get_attr(a, "__int__"), __mpy_obj_init_tuple(0), NULL); | ||
__mpy_obj_ref_inc(a); | ||
|
||
__mpy_obj_ref_dec(a); | ||
|
||
print_mpyobj_int(a); | ||
|
||
__mpy_builtins_cleanup(); | ||
|
||
return (*(int*)(a->content)); | ||
} | ||
|
||
TEST_CASE("TEST CAST BOOL TO INT") | ||
{ | ||
auto [input, expected_output] = GENERATE(table<bool, int>({ | ||
{ true, 1 }, | ||
{ false, 0 }, | ||
{10, 1}, | ||
})); | ||
|
||
CAPTURE(input); | ||
CHECK(cast_bool_to_int(input) == expected_output); | ||
} | ||
|
||
TEST_CASE("TEST CAST STRING TO INT") | ||
{ | ||
auto [input, expected_output] = GENERATE(table<const char*, int>({ | ||
{ "1", 1 }, | ||
{ "0", 0 }, | ||
{ "10", 10}, | ||
})); | ||
|
||
CAPTURE(input); | ||
CHECK(cast_string_to_int(input) == expected_output); | ||
} | ||
|
||
TEST_CASE("TEST CAST STRING TO INT ERROR") { | ||
REQUIRE_THROWS_AS(cast_string_to_int("false"), std::runtime_error); | ||
} | ||
|
||
/* | ||
And | ||
int cast_int_to_int(int i){ | ||
} | ||
*/ |
Oops, something went wrong.