From fd6802b5d389121b638e058ddfe16fd3a05564fb Mon Sep 17 00:00:00 2001 From: toole1 <toole1@6fbd10e7-183d-0410-a318-cb416676e4f2> Date: Sat, 16 Jul 2011 02:00:28 +0000 Subject: [PATCH] jack git-svn-id: https://subversion.cs.illinois.edu/svn/cs225@3369 6fbd10e7-183d-0410-a318-cb416676e4f2 --- Makefile | 2 +- Makefile.proxy | 2 +- config.ini | 7 ++--- monad.cpp | 4 +-- output.cpp => monad_shared.cpp | 50 ++++++++++++++++++---------------- unit_test.h => monad_shared.h | 23 ++++++++++------ output.h | 18 ------------ proxy.cpp | 13 ++++----- proxy.h | 11 ++++---- 9 files changed, 60 insertions(+), 70 deletions(-) rename output.cpp => monad_shared.cpp (91%) mode change 100644 => 100755 rename unit_test.h => monad_shared.h (68%) mode change 100644 => 100755 delete mode 100644 output.h diff --git a/Makefile b/Makefile index e2d8253..bcd7876 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC = g++ CFLAGS = -Wall EXENAME = monad -OBJS = $(EXENAME).o util.o output.o +OBJS = $(EXENAME).o util.o monad_shared.o IDFILE = .monadid OPTIMIZE = off diff --git a/Makefile.proxy b/Makefile.proxy index e52be4a..207f56d 100644 --- a/Makefile.proxy +++ b/Makefile.proxy @@ -1,7 +1,7 @@ CC = g++ CFLAGS += -Wall TESTEXE = proxy -TESTOBJS += $(TESTEXE).o util.o unit_tests.o output.o +TESTOBJS += $(TESTEXE).o util.o unit_tests.o monad_shared.o OPTIMIZE = off ifeq ($(strip $(OPTIMIZE)),on) diff --git a/config.ini b/config.ini index 3381fea..8a95ec2 100644 --- a/config.ini +++ b/config.ini @@ -7,11 +7,10 @@ [Monad Files] Makefile.proxy memcheck.h -output.cpp -output.h -proxy.cpp +monad_shared.h +monad_shared.cpp proxy.h -unit_test.h +proxy.cpp valgrind.h [Libraries] diff --git a/monad.cpp b/monad.cpp index 2442657..5e19ea3 100755 --- a/monad.cpp +++ b/monad.cpp @@ -14,11 +14,11 @@ #include <vector> #include "util.h" -#include "output.h" +#include "proxy.h" using namespace std; using namespace util; -using namespace output; +using namespace monad_shared; namespace monad { diff --git a/output.cpp b/monad_shared.cpp old mode 100644 new mode 100755 similarity index 91% rename from output.cpp rename to monad_shared.cpp index b96afcc..7fe7d2f --- a/output.cpp +++ b/monad_shared.cpp @@ -1,13 +1,17 @@ #include <iostream> -#include "output.h" +#include "monad_shared.h" #include "util.h" -using namespace proxy; +using namespace monad_shared; using namespace util; using std::cout; using std::cerr; using std::endl; +namespace monad_shared +{ +const char * unit_test::pass_string = "~~PASSED~~"; + namespace output { @@ -17,6 +21,24 @@ void header(const string & title) << "================================" << endl; } +void warning(const string & message) +{ + cerr << endl + << "********************************" + "********************************" << endl + << "WARNING!" << endl + << message << endl + << "********************************" + "********************************" << endl << endl; +} + + +void total_score(int32_t score) +{ + output::header("Total score (out of 100)"); + cout << "TOTAL SCORE: " << score << endl << endl; +} + void testname(const unit_test & curr_test, int32_t max_testname_len, int32_t max_points_len) { // Output test name @@ -56,25 +78,6 @@ void testname(const unit_test & curr_test, int32_t max_testname_len, int32_t max } -void warning(const string & message) -{ - cerr << endl - << "********************************" - "********************************" << endl - << "WARNING!" << endl - << message << endl - << "********************************" - "********************************" << endl << endl; -} - - -void total_score(int32_t score) -{ - output::header("Total score (out of 100)"); - cout << "TOTAL SCORE: " << score << endl << endl; -} - - void detailed_info(const unit_test & curr_test) { std::cout << "--------------------------------" << endl @@ -85,7 +88,7 @@ void detailed_info(const unit_test & curr_test) const string & error = curr_test.errormsg; const string & output = curr_test.output; - if (error == PASS_STRING) + if (curr_test.passed()) std::cout << "Result: passed" << endl; else std::cout << "Result: FAILED: " << error << endl; @@ -112,5 +115,6 @@ void detailed_info(const unit_test & curr_test) } -} // namespace testoutput +} // namespace output +} // namespace monad_shared diff --git a/unit_test.h b/monad_shared.h old mode 100644 new mode 100755 similarity index 68% rename from unit_test.h rename to monad_shared.h index 13e1d24..b1136cc --- a/unit_test.h +++ b/monad_shared.h @@ -1,13 +1,11 @@ -#ifndef UNIT_TEST_H -#define UNIT_TEST_H +#ifndef MONAD_SHARED +#define MONAD_SHARED -#include <string> +#include "util.h" #include "pipestream.h" -namespace proxy +namespace monad_shared { - class RunTests; - struct unit_test { typedef std::string return_type; @@ -48,8 +46,15 @@ namespace proxy return errormsg == pass_string; } }; -} -#define PASS_STRING "~~PASSED~~" + namespace output + { + void header(const std::string & title); + void total_score(int32_t score); + void warning(const std::string & message); + void testname(const unit_test & curr_test, int32_t max_testname_len, int32_t max_points_len); + void detailed_info(const unit_test & curr_test); + } // namespace output +} -#endif +#endif // MONAD_SHARED diff --git a/output.h b/output.h deleted file mode 100644 index fc128a9..0000000 --- a/output.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef OUTPUT_H -#define OUTPUT_H - -#include <string> -#include "unit_test.h" - -namespace output -{ - -void header(const std::string & title); -void total_score(int32_t score); -void testname(const proxy::unit_test & curr_test, int32_t max_testname_len, int32_t max_points_len); -void warning(const std::string & message); -void detailed_info(const proxy::unit_test & curr_test); - -} // namespace output - -#endif diff --git a/proxy.cpp b/proxy.cpp index ab2b06f..f8e619c 100755 --- a/proxy.cpp +++ b/proxy.cpp @@ -17,7 +17,7 @@ #include <iomanip> #include "memcheck.h" -#include "output.h" +#include "monad_shared.h" #include "pipestream.h" #include "proxy.h" #include "util.h" @@ -28,13 +28,12 @@ using std::vector; using std::pair; using namespace util; -using namespace output; +using namespace monad_shared; namespace proxy { vector<unit_test> * global_tests = NULL; output_check_map * global_output_checks = NULL; - const char * unit_test::pass_string = "~~PASSED~~"; } @@ -250,7 +249,7 @@ int32_t RunTests::run_single_test(unit_test & curr_test) if (error == "") error = "Unexpectedly Aborted"; - if (error == PASS_STRING) + if (curr_test.passed()) cout << environment.single_test_passed_string << endl; else cout << "Result: FAILED:" << endl << error << endl; @@ -522,7 +521,7 @@ void UnitTestContainer::child_test(pipestream & fmsg_pipe, pipestream & nums_pip fmsg_pipe.close(); // write time and valgrind flags to pipe - bool test_failed = (*error_msg != PASS_STRING); + bool test_failed = (*error_msg != unit_test::pass_string); delete error_msg; delete test.checkstream; environment.cleanup_globals(); @@ -562,7 +561,7 @@ void UnitTestContainer::test_exit(pipestream & fmsg_pipe, pipestream & nums_pipe nums_pipe.close(); // Check for output's correctness, if that was a condition of passing - if (test.errormsg == PASS_STRING) + if (test.passed()) { while (!test.checkstream->eof()) { @@ -620,7 +619,7 @@ int32_t get_valgrind_flags(bool test_failed) const char * get_valgrind_string(int32_t flags) { - if (flags == 0) return PASS_STRING; + if (flags == 0) return unit_test::pass_string; bool test_failed = bitflag(flags, 0); bool errors = bitflag(flags, 1); diff --git a/proxy.h b/proxy.h index a07fa42..965184c 100755 --- a/proxy.h +++ b/proxy.h @@ -3,8 +3,8 @@ // unit_tests.cpp. // By Jack Toole for CS 225 spring 2011 -#ifndef RUNTESTS_H -#define RUNTESTS_H +#ifndef MONAD_PROXY_H +#define MONAD_PROXY_H #include <map> #include <string> @@ -12,16 +12,17 @@ #include <iostream> #include <utility> #include "pipestream.h" +#include "monad_shared.h" -#include "unit_test.h" #define NO_MP_PART -1 #include "_mp_part_number.h" #define MP_PART(x) (MP_PART_NUMBER == (x) || MP_PART_NUMBER == NO_MP_PART) namespace proxy { + using namespace monad_shared; + class RunTests; - struct unit_test; typedef bool (*output_check)(const std::string &, const std::string &); extern std::vector<unit_test> * global_tests; @@ -177,7 +178,7 @@ using std::endl; #define FAIL(error) return std::string(__FILE__ ":" STR(__LINE__) ": ") + (error) -#define PASS return PASS_STRING +#define PASS return monad_shared::unit_test::pass_string; #define ASSERT(expr) if (!(expr)) \ FAIL("Assertion (" #expr ") failed") -- GitLab