Newer
Older
#include <iostream>
#include "monad_shared.h"
#include "util.h"
using namespace monad_shared;
using namespace util;
using std::cout;
using std::cerr;
using std::endl;
namespace monad_shared
{
namespace versioninfo
{
const char * official_name = "Monad Autograder";
const char * version_name = "Leap Into the Void";
const Version version_num = Version(3, 1, 0);
const char * date = "27 Jun 2012";
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
}
const char * unit_test_result::pass_string = "~~PASSED~~";
const size_t header_length = 64;
void printInfo()
{
cout << endl
<< versioninfo::official_name << endl
<< "Version " << versioninfo::version_num << ": " << versioninfo::version_name << endl
<< "Released " << versioninfo::date << endl
<< "Developed by Jack Toole 2011-2012" << endl
<< "Copyright 2011-2012 Jack Toole" << endl
<< "Run monad --license to see licensing information" << endl
<< endl;
}
namespace output
{
// Set EXIT_IF_ERROR message
void set_error_message()
{
SET_ERROR_MESSAGE("Oops! Something went wrong inside of me.\n"
"Please contact course staff with the following error details, and they'll figure it out:\n");
}
void header(const string & title)
{
cout << title << "..." << endl
<< string(header_length, '=') << endl;
}
void warning(const string & message)
{
cerr << endl
<< string(header_length, '*') << endl
<< "WARNING!" << endl
<< message << endl
<< string(header_length, '*') << endl << endl;
}
void total_score(int32_t score, int32_t outof)
{
if (outof < 0)
output::header("Total score");
else
output::header("Total score (out of " + to_string(outof) + ")");
cout << "TOTAL SCORE: " << score << endl << endl;
}
void testname(const unit_test_input & curr_test, int32_t max_testname_len, int32_t max_points_len)
{
// Output test name
int32_t pos = 0; // keep track of cursor position
std::cout << curr_test.name() << ' ';
pos += strlen(curr_test.name()) + 1;
if (curr_test.is_valgrind())
{
cout << "(valgrind) ";
pos += 11;
}
if (pos % 2 == max_testname_len % 2)
{
cout << ' ';
pos++;
}
while (pos < max_testname_len + 1)
{
cout << ". ";
pos += 2;
}
pos = 0; // reset column
std::cout << "[" << curr_test.points() << " pts] ";
pos += intlen(curr_test.points()) + 7;
while (pos < max_points_len + 7)
{
cout << ' ';
pos++;
}
cout << "- ";
}
void detailed_info(const unit_test_result & curr_test)
{
std::cout << string(header_length, '-') << endl
<< curr_test.name();
if (curr_test.is_valgrind()) std::cout << " (run under valgrind)";
std::cout << " [" << curr_test.points() << " points]" << endl;
const string & error = curr_test.errormsg();
const string & output = curr_test.output();
if (curr_test.passed())
std::cout << "Result: " << passed_string() << endl;
else
std::cout << "Result: " << failed_string() << ": " << error << endl;
if (curr_test.time() < 0)
cout << "Took unknown time (";
else
cout << "Took " << curr_test.time() << "ms (";
cout << curr_test.timeout() << "ms timeout)" << endl;
std::cout << "Output:" << endl
<< string(header_length, '-') << endl;
// Tab the output over to distinguish it from the test case
if (output != "")
{
//std::cout << " ";
//replaceAllInternal(output,"\n","\n ");
std::cout << output;
if (output[output.length() - 1] != '\n') std::cout << endl;
}
cout << endl;
}
string passed_string()
{
return colorize::make_color(colorize::GREEN, "passed");
}
string failed_string()
{
return colorize::make_color(colorize::RED , "FAILED");
}
} // namespace output
} // namespace monad_shared