|
@@ -1,5 +1,6 @@
|
|
|
#include <dirent.h>
|
|
|
#include <errno.h>
|
|
|
+#include <stdarg.h>
|
|
|
#include <stdbool.h>
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
@@ -18,21 +19,24 @@ static int pathIndex = 0;
|
|
|
static char testBuffer[TEST_BUFFER_LENGTH];
|
|
|
static int testBufferIndex = 0;
|
|
|
|
|
|
-static void tsAddBufferIndex(int length) {
|
|
|
- testBufferIndex += length;
|
|
|
+static void tsPrintToBuffer(const char* format, ...) {
|
|
|
+ va_list args;
|
|
|
+ va_start(args, format);
|
|
|
+ int leftBytes = TEST_BUFFER_LENGTH - testBufferIndex;
|
|
|
+ testBufferIndex += vsnprintf(testBuffer + testBufferIndex, leftBytes, format, args);
|
|
|
if(testBufferIndex > TEST_BUFFER_LENGTH) {
|
|
|
testBufferIndex = TEST_BUFFER_LENGTH;
|
|
|
}
|
|
|
+ va_end(args);
|
|
|
}
|
|
|
|
|
|
static bool tsPrinter(Object* o) {
|
|
|
if(testBufferIndex >= TEST_BUFFER_LENGTH) {
|
|
|
return true;
|
|
|
}
|
|
|
- if(o->type == OT_INT) {
|
|
|
- int leftBytes = TEST_BUFFER_LENGTH - testBufferIndex;
|
|
|
- tsAddBufferIndex(snprintf(testBuffer + testBufferIndex, leftBytes, "%d\n", o->data.intValue));
|
|
|
- return false;
|
|
|
+ switch(o->type) {
|
|
|
+ case OT_INT: tsPrintToBuffer("%d\n", o->data.intValue); return false;
|
|
|
+ case OT_NULL: tsPrintToBuffer("null\n"); return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -89,12 +93,14 @@ static void tsCheckScript(Script* sc) {
|
|
|
static void tsCheckFile() {
|
|
|
allTests++;
|
|
|
if(tTokenize(path)) {
|
|
|
+ puts(path);
|
|
|
puts(tGetError());
|
|
|
return;
|
|
|
}
|
|
|
int codeLength;
|
|
|
unsigned char* code = cCompile(&codeLength);
|
|
|
if(code == NULL) {
|
|
|
+ puts(path);
|
|
|
puts(cGetError());
|
|
|
return;
|
|
|
}
|
|
@@ -130,52 +136,6 @@ static void tsScanDirectory() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- String s;
|
|
|
- while(true) {
|
|
|
- char c = f.get();
|
|
|
- if(!f.good() || c == '\n') {
|
|
|
- break;
|
|
|
- }
|
|
|
- s += c;
|
|
|
- }
|
|
|
- return s;
|
|
|
-}
|
|
|
-
|
|
|
-static bool testTokenizer(const String& input, const String& output) {
|
|
|
- tests++;
|
|
|
- std::ifstream oStream;
|
|
|
- oStream.open(output);
|
|
|
- if(!oStream.good()) {
|
|
|
- std::cout << "cannot open file '" << output << "'\n";
|
|
|
- return true;
|
|
|
- }
|
|
|
- TokenStream tokenStream;
|
|
|
- if(Tokenizer::tokenize(tokenStream, input)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- while(true) {
|
|
|
- String expected = readLine(oStream);
|
|
|
- if(expected.getLength() == 0) {
|
|
|
- break;
|
|
|
- } else if(!tokenStream.hasToken()) {
|
|
|
- std::cout << "error in '" << input << "\n'out of tokens\n";
|
|
|
- return false;
|
|
|
- }
|
|
|
- String buffer = tokenStream.nextTokenString();
|
|
|
- if(strchr(buffer, '\n') != nullptr) {
|
|
|
- expected += '\n';
|
|
|
- expected += readLine(oStream);
|
|
|
- }
|
|
|
- if(strcmp(buffer, expected) != 0) {
|
|
|
- std::cout << "error in '" << input << "\n'" << buffer << "' should be '" << expected << "'\n";
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- done++;
|
|
|
- return false;
|
|
|
-}*/
|
|
|
-
|
|
|
void tsStart(const char* path) {
|
|
|
sSetPrinter(tsPrinter);
|
|
|
doneTests = 0;
|