Add pre-commit hook and add missing test files
This commit is contained in:
9
.pre-commit-config.yaml
Normal file
9
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: nimble-test-src-nim
|
||||
name: Run nimble test for src Nim changes
|
||||
entry: nimble test
|
||||
language: system
|
||||
pass_filenames: false
|
||||
files: ^src/.*\.nim$
|
||||
74
tests/cli_flags.nim
Normal file
74
tests/cli_flags.nim
Normal file
@@ -0,0 +1,74 @@
|
||||
import std/unittest
|
||||
import std/os
|
||||
import std/osproc
|
||||
import std/streams
|
||||
import std/strutils
|
||||
import std/times
|
||||
|
||||
|
||||
proc freshTempDir(prefix: string): string =
|
||||
result = joinPath(getTempDir(), prefix & "-" & $getTime().toUnixFloat())
|
||||
createDir(result)
|
||||
|
||||
|
||||
proc runCmd(cmd: string, args: openArray[string], workingDir: string): tuple[output: string, exitCode: int] =
|
||||
var process = startProcess(cmd, workingDir = workingDir, args = @args,
|
||||
options = {poUsePath, poStdErrToStdOut})
|
||||
defer:
|
||||
close(process)
|
||||
result.output = process.outputStream.readAll()
|
||||
result.exitCode = waitForExit(process)
|
||||
|
||||
|
||||
let
|
||||
projectDir = parentDir(parentDir(currentSourcePath()))
|
||||
binDir = freshTempDir("peon-cli-bin")
|
||||
peonBinary = joinPath(binDir, "peon-cli-test")
|
||||
|
||||
let compile = runCmd("nim", ["c", "--hints:off", "--verbosity:0", "-o:" & peonBinary, "src/peon.nim"], projectDir)
|
||||
doAssert compile.exitCode == 0, compile.output
|
||||
|
||||
|
||||
suite "cli stage flags":
|
||||
test "--noParse stops after lexing":
|
||||
let tempDir = freshTempDir("peon-cli-no-parse")
|
||||
defer:
|
||||
removeDir(tempDir)
|
||||
|
||||
let depPath = joinPath(tempDir, "dep.pn")
|
||||
let mainPath = joinPath(tempDir, "main.pn")
|
||||
writeFile(depPath, "var value = ;\n")
|
||||
writeFile(mainPath, "import dep;\n")
|
||||
|
||||
let execution = runCmd(peonBinary, ["--noParse", mainPath], tempDir)
|
||||
|
||||
check execution.exitCode == 0
|
||||
check "Error" notin execution.output
|
||||
|
||||
test "--noTypeCheck skips semantic validation":
|
||||
let tempDir = freshTempDir("peon-cli-no-typecheck")
|
||||
defer:
|
||||
removeDir(tempDir)
|
||||
|
||||
let sourcePath = joinPath(tempDir, "main.pn")
|
||||
writeFile(sourcePath, """var value: int64 = "hello";""")
|
||||
|
||||
let execution = runCmd(peonBinary, ["--noTypeCheck", sourcePath], tempDir)
|
||||
|
||||
check execution.exitCode == 0
|
||||
check "TypeCheckError" notin execution.output
|
||||
check "Error" notin execution.output
|
||||
|
||||
test "--noGen skips artifact generation":
|
||||
let tempDir = freshTempDir("peon-cli-no-gen")
|
||||
defer:
|
||||
removeDir(tempDir)
|
||||
|
||||
let sourcePath = joinPath(tempDir, "main.pn")
|
||||
let outputPath = joinPath(tempDir, "main-out.pbc")
|
||||
writeFile(sourcePath, "var value = 1;\n")
|
||||
|
||||
let execution = runCmd(peonBinary, ["--noGen", "--output", outputPath, sourcePath], tempDir)
|
||||
|
||||
check execution.exitCode == 0
|
||||
check not fileExists(outputPath)
|
||||
4
tests/hello.pn
Normal file
4
tests/hello.pn
Normal file
@@ -0,0 +1,4 @@
|
||||
import std;
|
||||
|
||||
|
||||
print("Hello, world!");
|
||||
Reference in New Issue
Block a user