mirror of https://github.com/japl-lang/japl.git
Removed unused/dead code + improved test suite code quality
This commit is contained in:
parent
97b7c5d91e
commit
a58b8a9ef0
|
@ -1,7 +1,28 @@
|
|||
# Copyright 2020 Mattia Giambirtone
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Makes our short integers platform-independent (big vs little endian)
|
||||
|
||||
|
||||
proc toDouble*(input: int | uint | uint16): array[2, uint8] =
|
||||
cast[array[2, uint8]](uint16(input))
|
||||
## Converts an int (either int, uint or uint16)
|
||||
## to an array[2, uint8]
|
||||
result = cast[array[2, uint8]](uint16(input))
|
||||
|
||||
|
||||
proc fromDouble*(input: array[2, uint8]): uint16 =
|
||||
## Rebuilds the output of toDouble into
|
||||
## an uint16
|
||||
copyMem(result.addr, unsafeAddr(input), sizeof(uint16))
|
||||
|
||||
|
|
|
@ -599,13 +599,8 @@ proc run(self: var VM, repl: bool): InterpretResult =
|
|||
if self.frameCount == 0:
|
||||
discard self.pop()
|
||||
return OK
|
||||
|
||||
self.stackTop -= frame.clear()
|
||||
# frame.clear() clears the stack and returns the amount cleared
|
||||
|
||||
self.push(retResult)
|
||||
# self.stackTop = len(frame.getView()) - 1 # TODO
|
||||
|
||||
frame = self.frames[self.frameCount - 1]
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
# Copyright 2020 Mattia Giambirtone
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# Tests that our multibyte module works
|
||||
|
||||
import ../src/multibyte
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
# Copyright 2020 Mattia Giambirtone
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
|
||||
# Common entry point to run JAPL's tests
|
||||
#
|
||||
# - Assumes "japl" binary in ../src/japl built with all debugging off
|
||||
|
@ -5,19 +21,16 @@
|
|||
# - Runs all tests in (/tests/)japl/ and checks their output (marked by `//output:{output}`)
|
||||
#
|
||||
|
||||
# go through all nim tests
|
||||
import multibyte
|
||||
testMultibyte()
|
||||
# Imports nim tests as well
|
||||
import multibyte, os, strformat, times, re
|
||||
|
||||
|
||||
# go through all japl tests
|
||||
import os, strformat, times, re
|
||||
|
||||
proc compileExpectedOutput(path: string): string =
|
||||
for line in path.lines():
|
||||
if line =~ re"^.*//output:(.*)$":
|
||||
result &= matches[0] & "\n"
|
||||
|
||||
|
||||
proc deepComp(left, right: string): tuple[same: bool, place: int] =
|
||||
result.same = true
|
||||
if left.high() != right.high():
|
||||
|
@ -33,50 +46,48 @@ proc deepComp(left, right: string): tuple[same: bool, place: int] =
|
|||
return
|
||||
|
||||
|
||||
# Quick logging levels using procs
|
||||
|
||||
proc log(file: File, msg: string) =
|
||||
file.writeLine(&"[LOG] {msg}")
|
||||
echo msg
|
||||
|
||||
|
||||
proc detail(file: File, msg: string) =
|
||||
file.writeLine(&"[DETAIL] {msg}")
|
||||
|
||||
|
||||
when isMainModule:
|
||||
try:
|
||||
testMultibyte()
|
||||
var testsDir = "tests" / "japl"
|
||||
var japlExec = "src" / "japl"
|
||||
|
||||
# support running from both the japl root and the tests dir where it
|
||||
# resides
|
||||
var currentDir = getCurrentDir()
|
||||
if currentDir.lastPathPart() == "tests":
|
||||
testsDir = "japl"
|
||||
japlExec = ".." / japlExec
|
||||
|
||||
|
||||
let testResultsFile = open("testresults.txt", fmAppend)
|
||||
testResultsFile.writeLine(&"Executing tests at {$getTime()}")
|
||||
|
||||
# quick logging levels using procs
|
||||
proc log(msg: string) =
|
||||
testResultsFile.File.writeLine(&"[LOG] {msg}")
|
||||
echo msg
|
||||
|
||||
proc detail(msg: string) =
|
||||
testResultsFile.writeLine(&"[DETAIL] {msg}")
|
||||
|
||||
# Exceptions for tests that represent not-yet implemented behaviour
|
||||
var exceptions = @["all.jpl"]
|
||||
|
||||
log &"Running JAPL tests"
|
||||
log &"Looking for JAPL tests in {testsDir}"
|
||||
log &"Looking for JAPL executable at {japlExec}"
|
||||
log(testResultsFile, "Running JAPL tests")
|
||||
log(testResultsFile, &"Looking for JAPL tests in {testsDir}")
|
||||
log(testResultsFile, &"Looking for JAPL executable at {japlExec}")
|
||||
if not fileExists(japlExec):
|
||||
log &"JAPL executable not found"
|
||||
log(testResultsFile, "JAPL executable not found")
|
||||
quit(1)
|
||||
if not dirExists(testsDir):
|
||||
log &"Tests dir not found"
|
||||
log(testResultsFile, "Tests dir not found")
|
||||
quit(1)
|
||||
|
||||
|
||||
for file in walkDir(testsDir):
|
||||
block singularTest:
|
||||
block singleTest:
|
||||
for exc in exceptions:
|
||||
if exc == file.path.extractFilename:
|
||||
log &"Skipping {file.path} because it's on the exceptions list"
|
||||
break singularTest
|
||||
|
||||
log &"Running test {file.path}"
|
||||
log(testResultsFile, &"Skipping {file.path} because it's on the exceptions list")
|
||||
break singleTest
|
||||
log(testResultsFile, &"Running test {file.path}")
|
||||
if fileExists("testoutput.txt"):
|
||||
removeFile("testoutput.txt") # in case this crashed
|
||||
discard execShellCmd(&"{japlExec} {file.path} >>testoutput.txt")
|
||||
|
@ -87,16 +98,18 @@ for file in walkDir(testsDir):
|
|||
removeFile("testoutput.txt")
|
||||
let comparison = deepComp(expectedOutput, realOutput)
|
||||
if comparison.same:
|
||||
log &"Successful test {file.path}"
|
||||
log(testResultsFile, &"Successful test {file.path}")
|
||||
else:
|
||||
detail &"Expected output:\n{expectedOutput}\n"
|
||||
detail &"Received output:\n{realOutput}\n"
|
||||
detail &"Mismatch at pos {comparison.place}"
|
||||
detail(testResultsFile, &"Expected output:\n{expectedOutput}\n")
|
||||
detail(testResultsFile, &"Received output:\n{realOutput}\n")
|
||||
detail(testResultsFile, &"Mismatch at pos {comparison.place}")
|
||||
if comparison.place > expectedOutput.high() or
|
||||
comparison.place > realOutput.high():
|
||||
detail &"Length mismatch"
|
||||
detail(testResultsFile, &"Length mismatch")
|
||||
else:
|
||||
detail &"Expected is '{expectedOutput[comparison.place]}' while received '{realOutput[comparison.place]}'"
|
||||
log &"Test failed {file.path}, check 'testresults.txt' for details"
|
||||
detail(testResultsFile, &"Expected is '{expectedOutput[comparison.place]}' while received '{realOutput[comparison.place]}'")
|
||||
log(testResultsFile, &"Test failed {file.path}, check 'testresults.txt' for details")
|
||||
|
||||
testResultsFile.close()
|
||||
except IOError:
|
||||
stderr.write(&"Fatal IO error encountered while running tesrs -> {getCurrentExceptionMsg()}")
|
||||
|
|
Loading…
Reference in New Issue