45
45
using namespace std ;
46
46
47
47
/* *
48
- * Generic
48
+ * Generic JSON format logger.
49
+ * It is used to generate call log.
49
50
*/
50
51
class JsonLogger
51
52
{
@@ -86,6 +87,27 @@ class JsonLogger
86
87
bool m_first;
87
88
};
88
89
90
+
91
+ /* *
92
+ * Assertion function exported to tests
93
+ * @param pScope
94
+ * @return
95
+ */
96
+ Ref<JSValue> assertFunction (FunctionScope* pScope)
97
+ {
98
+ auto value = pScope->getParam (" value" );
99
+
100
+ if (!value->toBoolean ())
101
+ {
102
+ auto text = pScope->getParam (" text" )->toString ();
103
+
104
+ error (" Assertion failed: %s" , text.c_str ());
105
+ }
106
+
107
+ return undefined ();
108
+ }
109
+
110
+
89
111
JsonLogger* s_curFunctionLogger = NULL ;
90
112
91
113
bool run_test (const std::string& szFile, const string &testDir, const string& resultsDir)
@@ -107,12 +129,13 @@ bool run_test(const std::string& szFile, const string &testDir, const string& re
107
129
Ref<IScope> globals = ObjectScope::create (globalsObj);
108
130
109
131
globals->set (" result" , jsInt (0 ));
132
+ addNative (" function assert(value, text)" , assertFunction, globals);
110
133
try
111
134
{
112
135
// This code is copied from 'evaluate', to log the intermediate results
113
136
// generated from each state
114
137
CScriptToken token (script.c_str ());
115
- StatementList statements;
138
+ AstNodeList statements;
116
139
117
140
// Parsing loop
118
141
token = token.next ();
@@ -144,7 +167,7 @@ bool run_test(const std::string& szFile, const string &testDir, const string& re
144
167
s_curFunctionLogger->log (entry->getJSON (0 ));
145
168
return undefined ();
146
169
};
147
- addNative (" function callLogger(x)" , logFn, globals);
170
+ // addNative("function callLogger(x)", logFn, globals);
148
171
149
172
// Execution
150
173
mvmExecute (code, globals);
0 commit comments