mirror of
https://github.com/louisrubet/rpn
synced 2024-11-17 07:47:50 +01:00
#69: added includes in test files, changed conclusion
This commit is contained in:
parent
f6f6bb82aa
commit
47252ae44b
9 changed files with 52 additions and 18 deletions
|
@ -28,17 +28,46 @@ void test_get_stack(string& stack_is, stack& stk)
|
|||
}
|
||||
}
|
||||
|
||||
void test_show_result(string title, int tests, int tests_failed, int steps, int steps_failed)
|
||||
{
|
||||
printf("%s: run %d tests: %d passed, ", title.c_str(), tests, tests-tests_failed);
|
||||
if(tests_failed>0)
|
||||
printf(FG_RED);
|
||||
printf("%d failed", tests_failed);
|
||||
if(tests_failed>0)
|
||||
printf(COLOR_OFF);
|
||||
|
||||
printf(" (%d steps: %d passed, ", steps, steps-steps_failed);
|
||||
if(steps_failed>0)
|
||||
printf(FG_RED);
|
||||
printf("%d failed", steps_failed);
|
||||
if(steps_failed>0)
|
||||
printf(COLOR_OFF);
|
||||
printf(")\n");
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_string);
|
||||
|
||||
int total_tests=0;
|
||||
int total_tests_failed=0;
|
||||
int total_steps=0;
|
||||
int total_steps_failed=0;
|
||||
|
||||
string test_filename = ((ostring*)_stack->pop_back())->_value;
|
||||
test(test_filename, total_tests, total_tests_failed, total_steps, total_steps_failed);
|
||||
test_show_result("Total", total_tests, total_tests_failed, total_steps, total_steps_failed);
|
||||
}
|
||||
|
||||
void test(string test_filename, int& total_tests, int& total_tests_failed, int& total_steps, int& total_steps_failed)
|
||||
{
|
||||
const string stack_size("-> stack size should be ");
|
||||
const string stack_value("-> stack should be ");
|
||||
const string cmd_error("-> error should be ");
|
||||
const string cmd_exit("exit test");
|
||||
|
||||
string test_filename = ((ostring*)_stack->pop_back())->_value;
|
||||
ifstream test_file(test_filename.c_str());
|
||||
int tests = 0;
|
||||
int tests_failed = 0;
|
||||
|
@ -65,8 +94,11 @@ void test()
|
|||
while (!test_file.eof())
|
||||
{
|
||||
getline(test_file, entry);
|
||||
if (entry.substr(0,2)=="##")
|
||||
printf("%s\n", entry.c_str());
|
||||
|
||||
if (entry.substr(0,8)=="#include")
|
||||
test(entry.substr(9), total_tests, total_tests_failed, total_steps, total_steps_failed);
|
||||
else if (entry.substr(0,2)=="##")
|
||||
printf("\n%s: %s\n", test_filename.c_str(), entry.substr(3).c_str());
|
||||
else if (entry.substr(0,2)=="# ")
|
||||
{
|
||||
// indicates the status of previous test
|
||||
|
@ -202,21 +234,16 @@ void test()
|
|||
// cerr back
|
||||
cerr.rdbuf(cerr_old_buffer);
|
||||
|
||||
// conclusion
|
||||
printf("\nRun %d tests: %d passed, ", tests, tests-tests_failed);
|
||||
if(tests_failed>0)
|
||||
printf(FG_RED);
|
||||
printf("%d failed", tests_failed);
|
||||
if(tests_failed>0)
|
||||
printf(COLOR_OFF);
|
||||
|
||||
printf(" (%d steps: %d passed, ", steps, steps-steps_failed);
|
||||
if(steps_failed>0)
|
||||
printf(FG_RED);
|
||||
printf("%d failed", steps_failed);
|
||||
if(steps_failed>0)
|
||||
printf(COLOR_OFF);
|
||||
printf(")\n");
|
||||
// conclusion: show and keep for total
|
||||
if (tests != 0)
|
||||
{
|
||||
test_show_result(test_filename, tests, tests_failed, steps, steps_failed);
|
||||
|
||||
total_tests += tests;
|
||||
total_tests_failed += tests_failed;
|
||||
total_steps += steps;
|
||||
total_steps_failed += steps_failed;
|
||||
}
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "test file '%s' not found\n", test_filename.c_str());
|
||||
|
|
7
test/1-all.txt
Normal file
7
test/1-all.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include test/2-entry.txt
|
||||
#include test/3-general.txt
|
||||
#include test/4-branch.txt
|
||||
#include test/5-stack.txt
|
||||
#include test/6-real.txt
|
||||
#include test/7-string.txt
|
||||
#include test/8-test.txt
|
Loading…
Reference in a new issue