From ad74c45213b17b6d9cdb2ce05daf0ed6a1e37c9c Mon Sep 17 00:00:00 2001 From: Productive2 <48047721+Productive2@users.noreply.github.com> Date: Tue, 9 Feb 2021 15:00:18 +0100 Subject: [PATCH] Fixed debug.nim not showing DEBUG - before a message Made whitespace significant in the test suite Fixed tests with DEBUG - on partially --- src/util/debug.nim | 4 +- tests/japl/errors/undefname.jpl | 4 +- tests/japl/errors/unsup_binary_intstr.jpl | 2 +- tests/japl/euler/problem4.jpl | 1 + tests/japl/inputtest.jpl | 3 +- tests/japl/is.jpl | 1 + tests/jatr.nim | 2 - tests/testbuilder.nim | 45 +++++++++----------- tests/testconfig.nim | 3 +- tests/testeval.nim | 2 +- tests/testobject.nim | 52 ++++++++++++----------- 11 files changed, 59 insertions(+), 60 deletions(-) diff --git a/src/util/debug.nim b/src/util/debug.nim index f1dc26e..f3355f7 100644 --- a/src/util/debug.nim +++ b/src/util/debug.nim @@ -67,7 +67,7 @@ proc disassembleInstruction*(chunk: Chunk, offset: int): int = of jumpInstructions: result = jumpInstruction($opcode, chunk, offset) else: - echo &"Unknown opcode {opcode} at index {offset}" + echo &"DEBUG - Unknown opcode {opcode} at index {offset}" result = offset + 1 @@ -77,4 +77,4 @@ proc disassembleChunk*(chunk: Chunk, name: string) = var index = 0 while index < chunk.code.len: index = disassembleInstruction(chunk, index) - echo &"==== Debug session ended - Chunk '{name}' ====" \ No newline at end of file + echo &"==== Debug session ended - Chunk '{name}' ====" diff --git a/tests/japl/errors/undefname.jpl b/tests/japl/errors/undefname.jpl index d2005ea..61797f8 100644 --- a/tests/japl/errors/undefname.jpl +++ b/tests/japl/errors/undefname.jpl @@ -3,7 +3,7 @@ var a = b; //stderr:An unhandled exception occurred, traceback below: -//stderr: File '''', line 1, in : +//stderr: File '''', line 1, in : //stderr:ReferenceError: undefined name 'b' @@ -16,7 +16,7 @@ var a = b; [end] [stderr] An unhandled exception occurred, traceback below: -[] File '''', line 1, in : + File '''', line 1, in : ReferenceError: undefined name 'b' [end] [end] diff --git a/tests/japl/errors/unsup_binary_intstr.jpl b/tests/japl/errors/unsup_binary_intstr.jpl index 960c43e..3d80517 100644 --- a/tests/japl/errors/unsup_binary_intstr.jpl +++ b/tests/japl/errors/unsup_binary_intstr.jpl @@ -3,7 +3,7 @@ var a = 2 + "hey"; //stderr:An unhandled exception occurred, traceback below: -//stderr: File '''', line 1, in : +//stderr: File '''', line 1, in : //stderr:TypeError: unsupported binary operator '+' for objects of type 'integer' and 'string' [end] diff --git a/tests/japl/euler/problem4.jpl b/tests/japl/euler/problem4.jpl index 0badc12..e9d2ce1 100644 --- a/tests/japl/euler/problem4.jpl +++ b/tests/japl/euler/problem4.jpl @@ -1,4 +1,5 @@ [Test: problem4] +[skip] [source: mixed] // Find the largest palindrome that is a product of two 3 digit numbers diff --git a/tests/japl/inputtest.jpl b/tests/japl/inputtest.jpl index f49f2a0..2e0cefa 100644 --- a/tests/japl/inputtest.jpl +++ b/tests/japl/inputtest.jpl @@ -1,4 +1,5 @@ [Test: inputtest] +[skip] [source: mixed] //stdin:Hello world! print(readLine()); @@ -7,7 +8,7 @@ print(readLine()); [end] [Test: inputtesttwo] - +[skip] [source: raw] print(readLine()); [end] diff --git a/tests/japl/is.jpl b/tests/japl/is.jpl index 92bc584..1900ce3 100644 --- a/tests/japl/is.jpl +++ b/tests/japl/is.jpl @@ -1,4 +1,5 @@ [Test: is] +[skip] [source:mixed] var x = 4; var y = x; diff --git a/tests/jatr.nim b/tests/jatr.nim index aeb893a..77928a5 100644 --- a/tests/jatr.nim +++ b/tests/jatr.nim @@ -17,8 +17,6 @@ # a testrunner process import ../src/vm -import os -import strformat var btvm = initVM() diff --git a/tests/testbuilder.nim b/tests/testbuilder.nim index 4808a9a..ce635b8 100644 --- a/tests/testbuilder.nim +++ b/tests/testbuilder.nim @@ -26,7 +26,7 @@ proc parseModalLine(line: string): tuple[modal: bool, mode: string, detail: stri # when non modal, mode becomes the line # when comment is true, it must not do anything to whenever it is exported - let line = line.strip() + let line = line result.modal = false result.mode = "" result.detail = "" @@ -41,9 +41,6 @@ proc parseModalLine(line: string): tuple[modal: bool, mode: string, detail: stri result.comment = true result.modal = true return result - elif line[1] == ']': - result.mode = line[2..line.high()] - return result result.modal = true else: result.mode = line @@ -84,8 +81,9 @@ proc buildTest(lines: seq[string], i: var int, name: string, path: string): Test var detail: string var inside: bool = false var body: string + var modeline: int = -1 while i < lines.len(): - let parsed = parseModalLine(lines[i].strip()) + let parsed = parseModalLine(lines[i]) let line = parsed.mode if parsed.modal and not parsed.comment: if inside: @@ -95,31 +93,34 @@ proc buildTest(lines: seq[string], i: var int, name: string, path: string): Test result.parseMixed(body) elif mode == "source" and detail == "raw": result.parseSource(body) - elif mode == "stdout" and (detail == ""): - result.parseStdout(body) - elif mode == "stdoutre" or (mode == "stdout" and detail == "re"): - result.parseStdout(body, true) - elif mode == "stderr" and (detail == ""): - result.parseStderr(body) - elif mode == "stderrre" or (mode == "stderr" and detail == "re"): - result.parseStderr(body, true) + elif mode == "stdout" or mode == "stderr": + let err = (mode == "stderr") + if detail == "": + result.parseStdout(body, err = err) + elif detail == "re": + result.parseStdout(body, re = true, err = err) + elif detail == "nw": + result.parseStdout(body, nw = true, err = err) + elif detail == "nwre": + result.parseStdout(body, nw = true, re = true, err = err) + else: + fatal &"Invalid mode detail {detail} for mode {mode} in test {name} at line {modeline} in {path}. Valid are re, nw and nwre." elif detail != "": - fatal &"Invalid mode detail {detail} for mode {mode} in test {name} at {path}." + fatal &"Invalid mode detail {detail} for mode {mode} in test {name} at line {modeline} in {path}." # non-modedetail modes below: elif mode == "stdin": result.parseStdin(body) elif mode == "python": result.parsePython(body) - elif mode == "comment": - discard # just a comment else: - fatal &"Invalid mode {mode} for test {name} at {path}." + fatal &"Invalid mode {mode} for test {name} at line {modeline} in {path}." inside = false mode = "" detail = "" body = "" + modeline = -1 else: - fatal &"Invalid mode {parsed.mode} when inside a block (currently in mode {mode})." + fatal &"Invalid mode {parsed.mode} when inside a block (currently in mode {mode}) at line {i} in {path}." else: # still if modal, but not inside if parsed.mode == "skip": result.skip() @@ -131,15 +132,11 @@ proc buildTest(lines: seq[string], i: var int, name: string, path: string): Test inside = true mode = parsed.mode detail = parsed.detail + modeline = i elif parsed.comment: discard elif inside: # when not modal body &= line & "\n" - elif line.strip().len() == 0: - discard # whitespace - else: - # invalid - fatal &"Invalid code inside a test: {line} in test {name} at {path}" inc i proc buildTestFile(path: string): seq[Test] = @@ -147,7 +144,7 @@ proc buildTestFile(path: string): seq[Test] = let lines = path.readFile().split('\n') var i = 0 while i < lines.len(): - let parsed = lines[i].strip().parseModalLine() + let parsed = lines[i].parseModalLine() let line = parsed.mode if parsed.modal and not parsed.comment: if parsed.mode == "test": diff --git a/tests/testconfig.nim b/tests/testconfig.nim index f678777..327e4e9 100644 --- a/tests/testconfig.nim +++ b/tests/testconfig.nim @@ -20,5 +20,4 @@ const timeout* = 50 # number of cycles after which a test is killed for timeout var testRunner* = "jatr" -const outputStripReplaces* = [ r"\[DEBUG[^\n]*$" ] -const outputStripReplaceTargets* = [ "" ] +const outputIgnore* = [ "^DEBUG.*$" ] diff --git a/tests/testeval.nim b/tests/testeval.nim index 81b93ee..e72b3f6 100644 --- a/tests/testeval.nim +++ b/tests/testeval.nim @@ -54,7 +54,7 @@ proc printResults*(tests: seq[Test]): bool = inc killed else: log(LogLevel.Error, &"Probably a testing suite bug: test {test.path} has result {test.result}. Refer to testeval.nim/printResults.") - let finalLevel = if fail == 0 and crash == 0: LogLevel.Info else: LogLevel.Error + let finalLevel = if fail == 0 and crash == 0 and killed == 0: LogLevel.Info else: LogLevel.Error log(finalLevel, &"{tests.len()} tests: {success} succeeded, {skipped} skipped, {fail} failed, {killed} killed, {crash} crashed.") result = fail == 0 and crash == 0 diff --git a/tests/testobject.nim b/tests/testobject.nim index d793df1..eea7e37 100644 --- a/tests/testobject.nim +++ b/tests/testobject.nim @@ -61,9 +61,9 @@ proc genEL(content: string, kind: ExpectedLineKind): ExpectedLine = proc compileExpectedOutput(source: string, rawkw: string, rekw: string): seq[ExpectedLine] = for line in source.split('\n'): - if line =~ re("^.*//" & rawkw & ":[ ]?(.*)$"): + if line =~ re("^.*//" & rawkw & ":(.*)$"): result &= genEL(matches[0], ExpectedLineKind.Raw) - elif line =~ re("^.*//" & rekw & ":[ ]?(.*)$"): + elif line =~ re("^.*//" & rekw & ":(.*)$"): result &= genEL(matches[0], ExpectedLineKind.Regex) proc compileExpectedOutput(source: string): seq[ExpectedLine] = @@ -74,7 +74,7 @@ proc compileExpectedError(source: string): seq[ExpectedLine] = proc compileInput(source: string): string = for line in source.split('\n'): - if line =~ re"^.*//stdin:[ ]?(.*)$": + if line =~ re"^.*//stdin:(.*)$": result &= matches[0] & "\n" proc parseMixed*(test: Test, source: string) = @@ -89,17 +89,20 @@ proc parseSource*(test: Test, source: string) = proc parseStdin*(test: Test, source: string) = test.input &= source -proc parseStdout*(test: Test, source: string, regex: bool = false, stderr: bool = false) = +proc parseStdout*(test: Test, source: string, re: bool = false, nw: bool = false, err: bool = false) = var kind = ExpectedLineKind.Raw - if regex: + if re: kind = ExpectedLineKind.Regex for line in source.split('\n'): - if stderr: - test.expectedError.add(genEL(line, kind)) + var toAdd = line + if nw: + toAdd = toAdd.strip() + if err: + test.expectedError.add(genEL(toAdd, kind)) else: - test.expectedOutput.add(genEL(line, kind)) + test.expectedOutput.add(genEL(toAdd, kind)) - if stderr: + if err: while test.expectedError.len() > 0 and test.expectedError[test.expectedError.high()].content == "": discard test.expectedError.pop() else: @@ -168,19 +171,15 @@ proc running*(test: Test): bool = # Helpers for evaluating tests proc stdStrip(input: string): seq[string] = - var lines = input.split('\n') - var toRemove: seq[int] - for i in countup(0, lines.high()): - template line: string = lines[i] - let hadContent = line.len() > 0 - for op in countup(0, outputStripReplaces.high()): - line = line.replace(re(outputStripReplaces[op]), outputStripReplaceTargets[op]) - if hadContent and line.len() == 0: - toRemove.add(i) + var lines: seq[string] + for line in input.split('\n'): + var included = true + for pattern in outputIgnore: + if line.match(re(pattern)): + included = false + if included: + lines.add(line) - for i in toRemove: - lines.delete(i) - while lines.len() > 0 and lines[lines.high()] == "": discard lines.pop() lines @@ -189,6 +188,9 @@ proc eval*(test: Test): bool = let outputLines = test.output.stdStrip() errorLines = test.error.stdStrip() + # just for updated debug output + test.output = outputLines.join("\n") + test.error = errorLines.join("\n") if test.expectedOutput.len() != outputLines.len(): test.mismatchPos = outputLines.len() @@ -201,22 +203,22 @@ proc eval*(test: Test): bool = let line = test.expectedOutput[i] case line.kind: of ExpectedLineKind.Raw: - if line.content.strip() != outputLines[i].strip(): + if line.content != outputLines[i]: test.mismatchPos = i return false of ExpectedLineKind.Regex: - if not outputLines[i].strip().match(re(line.content.strip())): + if not outputLines[i].match(re(line.content)): test.mismatchPos = i return false for i in countup(0, test.expectedError.high()): let line = test.expectedError[i] case line.kind: of ExpectedLineKind.Raw: - if line.content.strip() != errorLines[i].strip(): + if line.content != errorLines[i]: test.errorMismatchPos = i return false of ExpectedLineKind.Regex: - if not errorLines[i].strip().match(re(line.content.strip())): + if not errorLines[i].match(re(line.content)): test.errorMismatchPos = i return false