Skip to content
Snippets Groups Projects
Commit fd6802b5 authored by toole1's avatar toole1
Browse files

jack

git-svn-id: https://subversion.cs.illinois.edu/svn/cs225@3369 6fbd10e7-183d-0410-a318-cb416676e4f2
parent c36c4244
No related branches found
No related tags found
No related merge requests found
CC = g++ CC = g++
CFLAGS = -Wall CFLAGS = -Wall
EXENAME = monad EXENAME = monad
OBJS = $(EXENAME).o util.o output.o OBJS = $(EXENAME).o util.o monad_shared.o
IDFILE = .monadid IDFILE = .monadid
OPTIMIZE = off OPTIMIZE = off
......
CC = g++ CC = g++
CFLAGS += -Wall CFLAGS += -Wall
TESTEXE = proxy 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 OPTIMIZE = off
ifeq ($(strip $(OPTIMIZE)),on) ifeq ($(strip $(OPTIMIZE)),on)
......
...@@ -7,11 +7,10 @@ ...@@ -7,11 +7,10 @@
[Monad Files] [Monad Files]
Makefile.proxy Makefile.proxy
memcheck.h memcheck.h
output.cpp monad_shared.h
output.h monad_shared.cpp
proxy.cpp
proxy.h proxy.h
unit_test.h proxy.cpp
valgrind.h valgrind.h
[Libraries] [Libraries]
......
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
#include <vector> #include <vector>
#include "util.h" #include "util.h"
#include "output.h" #include "proxy.h"
using namespace std; using namespace std;
using namespace util; using namespace util;
using namespace output; using namespace monad_shared;
namespace monad namespace monad
{ {
......
#include <iostream> #include <iostream>
#include "output.h" #include "monad_shared.h"
#include "util.h" #include "util.h"
using namespace proxy; using namespace monad_shared;
using namespace util; using namespace util;
using std::cout; using std::cout;
using std::cerr; using std::cerr;
using std::endl; using std::endl;
namespace monad_shared
{
const char * unit_test::pass_string = "~~PASSED~~";
namespace output namespace output
{ {
...@@ -17,6 +21,24 @@ void header(const string & title) ...@@ -17,6 +21,24 @@ void header(const string & title)
<< "================================" << endl; << "================================" << 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) void testname(const unit_test & curr_test, int32_t max_testname_len, int32_t max_points_len)
{ {
// Output test name // Output test name
...@@ -56,25 +78,6 @@ void testname(const unit_test & curr_test, int32_t max_testname_len, int32_t max ...@@ -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) void detailed_info(const unit_test & curr_test)
{ {
std::cout << "--------------------------------" << endl std::cout << "--------------------------------" << endl
...@@ -85,7 +88,7 @@ void detailed_info(const unit_test & curr_test) ...@@ -85,7 +88,7 @@ void detailed_info(const unit_test & curr_test)
const string & error = curr_test.errormsg; const string & error = curr_test.errormsg;
const string & output = curr_test.output; const string & output = curr_test.output;
if (error == PASS_STRING) if (curr_test.passed())
std::cout << "Result: passed" << endl; std::cout << "Result: passed" << endl;
else else
std::cout << "Result: FAILED: " << error << endl; std::cout << "Result: FAILED: " << error << endl;
...@@ -112,5 +115,6 @@ void detailed_info(const unit_test & curr_test) ...@@ -112,5 +115,6 @@ void detailed_info(const unit_test & curr_test)
} }
} // namespace testoutput } // namespace output
} // namespace monad_shared
#ifndef UNIT_TEST_H #ifndef MONAD_SHARED
#define UNIT_TEST_H #define MONAD_SHARED
#include <string> #include "util.h"
#include "pipestream.h" #include "pipestream.h"
namespace proxy namespace monad_shared
{ {
class RunTests;
struct unit_test struct unit_test
{ {
typedef std::string return_type; typedef std::string return_type;
...@@ -48,8 +46,15 @@ namespace proxy ...@@ -48,8 +46,15 @@ namespace proxy
return errormsg == pass_string; 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
#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
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <iomanip> #include <iomanip>
#include "memcheck.h" #include "memcheck.h"
#include "output.h" #include "monad_shared.h"
#include "pipestream.h" #include "pipestream.h"
#include "proxy.h" #include "proxy.h"
#include "util.h" #include "util.h"
...@@ -28,13 +28,12 @@ using std::vector; ...@@ -28,13 +28,12 @@ using std::vector;
using std::pair; using std::pair;
using namespace util; using namespace util;
using namespace output; using namespace monad_shared;
namespace proxy namespace proxy
{ {
vector<unit_test> * global_tests = NULL; vector<unit_test> * global_tests = NULL;
output_check_map * global_output_checks = 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) ...@@ -250,7 +249,7 @@ int32_t RunTests::run_single_test(unit_test & curr_test)
if (error == "") if (error == "")
error = "Unexpectedly Aborted"; error = "Unexpectedly Aborted";
if (error == PASS_STRING) if (curr_test.passed())
cout << environment.single_test_passed_string << endl; cout << environment.single_test_passed_string << endl;
else else
cout << "Result: FAILED:" << endl << error << endl; cout << "Result: FAILED:" << endl << error << endl;
...@@ -522,7 +521,7 @@ void UnitTestContainer::child_test(pipestream & fmsg_pipe, pipestream & nums_pip ...@@ -522,7 +521,7 @@ void UnitTestContainer::child_test(pipestream & fmsg_pipe, pipestream & nums_pip
fmsg_pipe.close(); fmsg_pipe.close();
// write time and valgrind flags to pipe // 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 error_msg;
delete test.checkstream; delete test.checkstream;
environment.cleanup_globals(); environment.cleanup_globals();
...@@ -562,7 +561,7 @@ void UnitTestContainer::test_exit(pipestream & fmsg_pipe, pipestream & nums_pipe ...@@ -562,7 +561,7 @@ void UnitTestContainer::test_exit(pipestream & fmsg_pipe, pipestream & nums_pipe
nums_pipe.close(); nums_pipe.close();
// Check for output's correctness, if that was a condition of passing // Check for output's correctness, if that was a condition of passing
if (test.errormsg == PASS_STRING) if (test.passed())
{ {
while (!test.checkstream->eof()) while (!test.checkstream->eof())
{ {
...@@ -620,7 +619,7 @@ int32_t get_valgrind_flags(bool test_failed) ...@@ -620,7 +619,7 @@ int32_t get_valgrind_flags(bool test_failed)
const char * get_valgrind_string(int32_t flags) 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 test_failed = bitflag(flags, 0);
bool errors = bitflag(flags, 1); bool errors = bitflag(flags, 1);
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
// unit_tests.cpp. // unit_tests.cpp.
// By Jack Toole for CS 225 spring 2011 // By Jack Toole for CS 225 spring 2011
#ifndef RUNTESTS_H #ifndef MONAD_PROXY_H
#define RUNTESTS_H #define MONAD_PROXY_H
#include <map> #include <map>
#include <string> #include <string>
...@@ -12,16 +12,17 @@ ...@@ -12,16 +12,17 @@
#include <iostream> #include <iostream>
#include <utility> #include <utility>
#include "pipestream.h" #include "pipestream.h"
#include "monad_shared.h"
#include "unit_test.h"
#define NO_MP_PART -1 #define NO_MP_PART -1
#include "_mp_part_number.h" #include "_mp_part_number.h"
#define MP_PART(x) (MP_PART_NUMBER == (x) || MP_PART_NUMBER == NO_MP_PART) #define MP_PART(x) (MP_PART_NUMBER == (x) || MP_PART_NUMBER == NO_MP_PART)
namespace proxy namespace proxy
{ {
using namespace monad_shared;
class RunTests; class RunTests;
struct unit_test;
typedef bool (*output_check)(const std::string &, const std::string &); typedef bool (*output_check)(const std::string &, const std::string &);
extern std::vector<unit_test> * global_tests; extern std::vector<unit_test> * global_tests;
...@@ -177,7 +178,7 @@ using std::endl; ...@@ -177,7 +178,7 @@ using std::endl;
#define FAIL(error) return std::string(__FILE__ ":" STR(__LINE__) ": ") + (error) #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)) \ #define ASSERT(expr) if (!(expr)) \
FAIL("Assertion (" #expr ") failed") FAIL("Assertion (" #expr ") failed")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment