diff --git a/src/rpn-test-core.h b/src/rpn-test-core.h index 5dd98a6..c2f2ff4 100644 --- a/src/rpn-test-core.h +++ b/src/rpn-test-core.h @@ -1,11 +1,19 @@ void program::test() { - const string test_filename = "test.txt"; + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_string); + 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; + int steps = 0; + int steps_failed = 0; if (test_file.is_open()) { @@ -14,9 +22,9 @@ void program::test() ret_value ret; stack stk; heap hp; - bool indicate_passed = false; bool failed = false; - int count_tests = 0; + bool is_first_step; + bool is_test_error_shown; int last_err; stringstream cerr_buffer; streambuf* cerr_old_buffer; @@ -24,36 +32,34 @@ void program::test() // redirect cerr cerr_old_buffer = cerr.rdbuf(cerr_buffer.rdbuf()); - while ((!failed) && (!test_file.eof())) + while (!test_file.eof()) { getline(test_file, entry); if (entry.substr(0,2)=="##") { - // read a test section - if (indicate_passed) - { - if (g_verbose > 0) - cout << "\t"; - cout << "passed " << count_tests << " tests"<< endl; - } cout << entry; - if (g_verbose == 0) - cout << " .. "; - else - cout << endl; - indicate_passed = true; - count_tests = 0; + cout << endl; } else if (entry.substr(0,1)=="#") { + // indicates the status of previous test + if (failed == false && tests > 0) + cout< 0) - cout << "\t" << test_title << endl; - count_tests++; + is_first_step = true; + is_test_error_shown = false; + cout << test_title; } else if (entry.find(stack_size, 0) == 0) { + // count test and step + if (is_first_step) + tests++; + steps++; + // check current stack size istringstream isub; int size; @@ -62,14 +68,29 @@ void program::test() isub>>size; if (size != (int)stk.size()) { - cout<>err_should_be; if (err_should_be != last_err) { - cout< 0) + cout << FG_GREEN << " PASSED" << COLOR_OFF << endl; // cerr back cerr.rdbuf(cerr_old_buffer); + + // conclusion + cout<0) + cout<0) + cout<0) + cout<0) + cout<