Skip to content

Commit

Permalink
run run_tests.py automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
abxh committed Apr 9, 2024
1 parent b6f96af commit 1992e74
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 12 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# source:
# https://github.com/marketplace/actions/python-action

name: tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-and-analyze:
runs-on: ubuntu-latest

steps:
- run: |
echo "Install required dependencies"
sudo apt-get update
sudo apt-get install python3
- run: |
echo "Run, Build Application using scripts"
python3 -c "
scripts = ['tests/run_tests.py']
for script in scripts:
with open(script, 'r') as file:
exec(file.read())"
7 changes: 5 additions & 2 deletions tests/T_queue_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ int main(void) {
{wraparound_test, "wraparound test"},
{for_each_and_copy_test, "for each and copy test"}};
printf(__FILE_NAME__ ":\n");
bool overall_res = true;
for (size_t i = 0; i < sizeof(bool_f_arr) / sizeof(bool_f_plus); i++) {
printf(" [%s] %s\n", bool_f_arr[i].func() ? GREEN "true" OFF : RED "false" OFF, bool_f_arr[i].desc);
bool res = bool_f_arr[i].func();
overall_res &= res;
printf(" [%s] %s\n", res ? GREEN "true" OFF : RED "false" OFF, bool_f_arr[i].desc);
}
return 0;
return overall_res ? 0 : 1;
}
7 changes: 5 additions & 2 deletions tests/T_stack_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ int main(void) {
{million_elements_test, "million elements test"},
{for_each_and_copy_test, "for each and copy test"}};
printf(__FILE_NAME__ ":\n");
bool overall_res = true;
for (size_t i = 0; i < sizeof(bool_f_arr) / sizeof(bool_f_plus); i++) {
printf(" [%s] %s\n", bool_f_arr[i].func() ? GREEN "true" OFF : RED "false" OFF, bool_f_arr[i].desc);
bool res = bool_f_arr[i].func();
overall_res &= res;
printf(" [%s] %s\n", res ? GREEN "true" OFF : RED "false" OFF, bool_f_arr[i].desc);
}
return 0;
return overall_res ? 0 : 1;
}
7 changes: 5 additions & 2 deletions tests/ll_queue_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ int main(void) {
{million_elements_test, "million elements test"},
{for_each_and_copy_test, "for each and copy test"}};
printf(__FILE_NAME__ ":\n");
bool overall_res = true;
for (size_t i = 0; i < sizeof(bool_f_arr) / sizeof(bool_f_plus); i++) {
printf(" [%s] %s\n", bool_f_arr[i].func() ? GREEN "true" OFF : RED "false" OFF, bool_f_arr[i].desc);
bool res = bool_f_arr[i].func();
overall_res &= res;
printf(" [%s] %s\n", res ? GREEN "true" OFF : RED "false" OFF, bool_f_arr[i].desc);
}
return 0;
return overall_res ? 0 : 1;
}
7 changes: 5 additions & 2 deletions tests/ll_stack_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ int main(void) {
{million_elements_test, "million elements test"},
{for_each_and_copy_test, "for each and copy test"}};
printf(__FILE_NAME__ ":\n");
bool overall_res = true;
for (size_t i = 0; i < sizeof(bool_f_arr) / sizeof(bool_f_plus); i++) {
printf(" [%s] %s\n", bool_f_arr[i].func() ? GREEN "true" OFF : RED "false" OFF, bool_f_arr[i].desc);
bool res = bool_f_arr[i].func();
overall_res &= res;
printf(" [%s] %s\n", res ? GREEN "true" OFF : RED "false" OFF, bool_f_arr[i].desc);
}
return 0;
return overall_res ? 0 : 1;
}
6 changes: 4 additions & 2 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
for name in glob.glob("./*_tests.c"):
s = pathlib.Path(name).stem
if os.system(f"gcc -Wall -Wextra -I{include_dir} -o {bin_dir}/{s}.bin ../src-alt/*/*.c {s}.c") != 0:
exit(1);
exit(1)

overall_res = True
for name in glob.glob("./*_tests.c"):
s = pathlib.Path(name).stem
os.system(f"../bin/{s}.bin")
overall_res &= os.system(f"../bin/{s}.bin") == 0

exit(0 if overall_res else 1)
7 changes: 5 additions & 2 deletions tests/strmap_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,11 @@ int main(void) {
{million_elements_test, "million elements test"},
{for_each_and_copy_test, "for each and copy test"}};
printf(__FILE_NAME__ ":\n");
bool overall_res = true;
for (size_t i = 0; i < sizeof(bool_f_arr) / sizeof(bool_f_plus); i++) {
printf(" [%s] %s\n", bool_f_arr[i].func() ? GREEN "true" OFF : RED "false" OFF, bool_f_arr[i].desc);
bool res = bool_f_arr[i].func();
overall_res &= res;
printf(" [%s] %s\n", res ? GREEN "true" OFF : RED "false" OFF, bool_f_arr[i].desc);
}
return 0;
return overall_res ? 0 : 1;
}

0 comments on commit 1992e74

Please sign in to comment.