mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-28 02:03:59 +00:00
activated more tests, allow input in test spec
This commit is contained in:
@@ -1323,6 +1323,12 @@ proc execCmdEx*(command: string, options: set[ProcessOption] = {
|
||||
## let (outp, errC) = execCmdEx("nim c -r mytestfile.nim")
|
||||
var p = startProcess(command, options=options + {poEvalCommand})
|
||||
var outp = outputStream(p)
|
||||
|
||||
# There is no way to provide input for the child process
|
||||
# anymore. Closing it will create EOF on stdin instead of eternal
|
||||
# blocking.
|
||||
close inputStream(p)
|
||||
|
||||
result = (TaintedString"", -1)
|
||||
var line = newStringOfCap(120).TaintedString
|
||||
while true:
|
||||
|
||||
@@ -48,6 +48,7 @@ type
|
||||
TSpec* = object
|
||||
action*: TTestAction
|
||||
file*, cmd*: string
|
||||
input*: string
|
||||
outp*: string
|
||||
line*, column*: int
|
||||
tfile*: string
|
||||
@@ -144,6 +145,8 @@ proc parseSpec*(filename: string): TSpec =
|
||||
of "output":
|
||||
result.action = actionRun
|
||||
result.outp = e.value
|
||||
of "input":
|
||||
result.input = e.value
|
||||
of "outputsub":
|
||||
result.action = actionRun
|
||||
result.outp = e.value
|
||||
|
||||
@@ -74,6 +74,33 @@ proc getFileDir(filename: string): string =
|
||||
if not result.isAbsolute():
|
||||
result = getCurrentDir() / result
|
||||
|
||||
proc execCmdEx2*(command: string, options: set[ProcessOption], input: string): tuple[
|
||||
output: TaintedString,
|
||||
exitCode: int] {.tags:
|
||||
[ExecIOEffect, ReadIOEffect, RootEffect], gcsafe.} =
|
||||
var p = startProcess(command, options=options + {poEvalCommand})
|
||||
var outp = outputStream(p)
|
||||
|
||||
# There is no way to provide input for the child process
|
||||
# anymore. Closing it will create EOF on stdin instead of eternal
|
||||
# blocking.
|
||||
let instream = inputStream(p)
|
||||
instream.write(input)
|
||||
close instream
|
||||
|
||||
result = (TaintedString"", -1)
|
||||
var line = newStringOfCap(120).TaintedString
|
||||
while true:
|
||||
if outp.readLine(line):
|
||||
result[0].string.add(line.string)
|
||||
result[0].string.add("\n")
|
||||
else:
|
||||
result[1] = peekExitCode(p)
|
||||
if result[1] != -1: break
|
||||
close(p)
|
||||
|
||||
|
||||
|
||||
proc nimcacheDir(filename, options: string, target: TTarget): string =
|
||||
## Give each test a private nimcache dir so they don't clobber each other's.
|
||||
let hashInput = options & $target
|
||||
@@ -359,7 +386,7 @@ proc testSpec(r: var TResults, test: TTest, target = targetC) =
|
||||
continue
|
||||
|
||||
let exeCmd = nodejs & " " & quoteShell(exeFile)
|
||||
var (buf, exitCode) = execCmdEx(exeCmd, options = {poStdErrToStdOut})
|
||||
var (buf, exitCode) = execCmdEx2(exeCmd, options = {poStdErrToStdOut}, input = expected.input)
|
||||
|
||||
# Treat all failure codes from nodejs as 1. Older versions of nodejs used
|
||||
# to return other codes, but for us it is sufficient to know that it's not 0.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
discard """
|
||||
targets: "cpp"
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
import nativesockets
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
discard """
|
||||
action: compile
|
||||
cmd: "nim $target --debuginfo --hints:on --define:useNimRtl --app:lib $options $file"
|
||||
"""
|
||||
|
||||
@@ -25,10 +26,3 @@ proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
|
||||
|
||||
proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} =
|
||||
result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x))
|
||||
|
||||
when false:
|
||||
# Test the GC:
|
||||
for i in 0..100_000:
|
||||
discard buildTree(2)
|
||||
|
||||
echo "Done"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
discard """
|
||||
msg: "Warning: 'y' might not have been initialized [Uninit]"
|
||||
nimout: "Warning: 'y' might not have been initialized [Uninit]"
|
||||
line:34
|
||||
action: compile
|
||||
"""
|
||||
|
||||
import strutils
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
discard """
|
||||
output: '''HELLO WORLD
|
||||
output: '''
|
||||
HELLO WORLD
|
||||
c_func
|
||||
12'''
|
||||
12
|
||||
'''
|
||||
"""
|
||||
|
||||
import macros, strutils
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
discard """
|
||||
action: run
|
||||
input: '''
|
||||
Andreas
|
||||
Rumpf
|
||||
'''
|
||||
outputsub: "Hallo Meister!"
|
||||
"""
|
||||
|
||||
type
|
||||
TBase = object of RootObj
|
||||
x, y: int
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
discard """
|
||||
output: '''
|
||||
to stdout
|
||||
to stdout
|
||||
to stderr
|
||||
to stderr
|
||||
to stdout
|
||||
to stdout
|
||||
'''
|
||||
"""
|
||||
|
||||
# This file is prefixed with an "a", because other tests
|
||||
# depend on it and it must be compiled first.
|
||||
stdout.writeLine("to stdout")
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
discard """
|
||||
exitcode: 1
|
||||
"""
|
||||
|
||||
# 'tafalse.nim' to ensure it is compiled before texitcode.nim
|
||||
import system
|
||||
quit(QuitFailure)
|
||||
|
||||
@@ -2,6 +2,7 @@ discard """
|
||||
file: "texitcode.nim"
|
||||
output: ""
|
||||
"""
|
||||
|
||||
import osproc, os
|
||||
|
||||
const filename = when defined(Windows): "tafalse.exe" else: "tafalse"
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
# tests for the interpreter
|
||||
|
||||
proc loops(a: var int) =
|
||||
discard
|
||||
#var
|
||||
# b: int
|
||||
#b = glob
|
||||
#while b != 0:
|
||||
# b = b + 1
|
||||
#a = b
|
||||
|
||||
proc mymax(a, b: int): int =
|
||||
#loops(result)
|
||||
result = a
|
||||
if b > a: result = b
|
||||
|
||||
proc test(a, b: int) =
|
||||
var
|
||||
x, y: int
|
||||
x = 0
|
||||
y = 7
|
||||
if x == a + b * 3 - 7 or
|
||||
x == 8 or
|
||||
x == y and y > -56 and y < 699:
|
||||
y = 0
|
||||
elif y == 78 and x == 0:
|
||||
y = 1
|
||||
elif y == 0 and x == 0:
|
||||
y = 2
|
||||
else:
|
||||
y = 3
|
||||
|
||||
type
|
||||
TTokType = enum
|
||||
tkNil, tkType, tkConst, tkVar, tkSymbol, tkIf,
|
||||
tkWhile, tkFor, tkLoop, tkCase, tkLabel, tkGoto
|
||||
|
||||
proc testCase(t: TTokType): int =
|
||||
case t
|
||||
of tkNil, tkType, tkConst: result = 0
|
||||
of tkVar: result = 1
|
||||
of tkSymbol: result = 2
|
||||
of tkIf..tkFor: result = 3
|
||||
of tkLoop: result = 56
|
||||
else: result = -1
|
||||
test(0, 9) # test the call
|
||||
|
||||
proc TestLoops() =
|
||||
var
|
||||
i, j: int
|
||||
|
||||
while i >= 0:
|
||||
if i mod 3 == 0:
|
||||
break
|
||||
i = i + 1
|
||||
while j == 13:
|
||||
j = 13
|
||||
break
|
||||
break
|
||||
|
||||
while true:
|
||||
break
|
||||
|
||||
|
||||
var
|
||||
glob: int
|
||||
a: array[0..5, int]
|
||||
|
||||
proc main() =
|
||||
#glob = 0
|
||||
#loops( glob )
|
||||
var
|
||||
res: int
|
||||
s: string
|
||||
#write(stdout, mymax(23, 45))
|
||||
write(stdout, "Hallo! Wie heisst du? ")
|
||||
s = readLine(stdin)
|
||||
# test the case statement
|
||||
case s
|
||||
of "Andreas": write(stdout, "Du bist mein Meister!\n")
|
||||
of "Rumpf": write(stdout, "Du bist in der Familie meines Meisters!\n")
|
||||
else: write(stdout, "ich kenne dich nicht!\n")
|
||||
write(stdout, "Du heisst " & s & "\n")
|
||||
|
||||
main()
|
||||
@@ -1,5 +1,6 @@
|
||||
discard """
|
||||
file: "tmemfiles1.nim"
|
||||
outputsub: ""
|
||||
"""
|
||||
import memfiles, os
|
||||
var
|
||||
@@ -8,5 +9,5 @@ var
|
||||
# Create a new file
|
||||
mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 20)
|
||||
mm.close()
|
||||
mm.close()
|
||||
# mm.close()
|
||||
if fileExists(fn): removeFile(fn)
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
import memfiles
|
||||
var inp = memfiles.open("tests/stdlib/tmemlines.nim")
|
||||
for line in lines(inp):
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
discard """
|
||||
outputsub: "rlwuiadtrnzb"
|
||||
"""
|
||||
|
||||
# chatever the sub pattern it will find itself
|
||||
|
||||
import memfiles
|
||||
var inp = memfiles.open("tests/stdlib/tmemslices.nim")
|
||||
for mem in memSlices(inp):
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
import net, nativesockets
|
||||
import unittest
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
discard """
|
||||
outputsub: "SUCCESS"
|
||||
"""
|
||||
|
||||
import os, osproc
|
||||
|
||||
when defined(Windows):
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
# Test Posix interface
|
||||
|
||||
when not defined(windows):
|
||||
@@ -13,4 +17,3 @@ when not defined(windows):
|
||||
writeLine(stdout, u.nodename)
|
||||
writeLine(stdout, u.release)
|
||||
writeLine(stdout, u.machine)
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
discard """
|
||||
output: '''
|
||||
just exiting...
|
||||
'''
|
||||
"""
|
||||
|
||||
# Test the new beforeQuit variable:
|
||||
|
||||
proc myExit() {.noconv.} =
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
# output not testable because repr prints pointer adresses
|
||||
# test the new "repr" built-in proc
|
||||
|
||||
type
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
# tests for rstgen module.
|
||||
|
||||
import ../../lib/packages/docutils/rstgen
|
||||
@@ -27,7 +31,7 @@ suite "YAML syntax highlighting":
|
||||
<span class="Punctuation">?</span> <span class="StringLit">key</span>
|
||||
<span class="Punctuation">:</span> <span class="StringLit">value</span>
|
||||
<span class="Keyword">...</span></pre>"""
|
||||
|
||||
|
||||
test "Block scalars":
|
||||
let input = """.. code-block:: yaml
|
||||
a literal block scalar: |
|
||||
@@ -55,7 +59,7 @@ suite "YAML syntax highlighting":
|
||||
<span class="StringLit">another literal block scalar</span><span class="Punctuation">:</span>
|
||||
<span class="Command">|+</span> <span class="Comment"># comment after header</span><span class="LongStringLit">
|
||||
allowed, since more indented than parent</span></pre>"""
|
||||
|
||||
|
||||
test "Directives":
|
||||
let input = """.. code-block:: yaml
|
||||
%YAML 1.2
|
||||
@@ -97,7 +101,7 @@ suite "YAML syntax highlighting":
|
||||
<span class="StringLit">more numbers</span><span class="Punctuation">:</span> <span class="Punctuation">[</span><span class="DecNumber">-783</span><span class="Punctuation">,</span> <span class="FloatNumber">11e78</span><span class="Punctuation">]</span><span class="Punctuation">,</span>
|
||||
<span class="StringLit">not numbers</span><span class="Punctuation">:</span> <span class="Punctuation">[</span> <span class="StringLit">42e</span><span class="Punctuation">,</span> <span class="StringLit">0023</span><span class="Punctuation">,</span> <span class="StringLit">+32.37</span><span class="Punctuation">,</span> <span class="StringLit">8 ball</span><span class="Punctuation">]</span>
|
||||
<span class="Punctuation">}</span></pre>"""
|
||||
|
||||
|
||||
test "Anchors, Aliases, Tags":
|
||||
let input = """.. code-block:: yaml
|
||||
--- !!map
|
||||
@@ -136,4 +140,4 @@ suite "YAML syntax highlighting":
|
||||
<span class="DecNumber">-3</span>
|
||||
<span class="DecNumber">-4</span>
|
||||
<span class="StringLit">example.com/not/a#comment</span><span class="Punctuation">:</span>
|
||||
<span class="StringLit">?not a map key</span></pre>"""
|
||||
<span class="StringLit">?not a map key</span></pre>"""
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
import algorithm
|
||||
import unittest
|
||||
|
||||
@@ -40,7 +44,7 @@ suite "test sort, sorted, and isSorted procs":
|
||||
test "test the shortcut versions with descending sort order":
|
||||
check(not unSortedIntSeq.isSorted(SortOrder.Descending))
|
||||
check sorted(unSortedIntSeq, SortOrder.Descending) == reversed sortedIntSeq
|
||||
check sorted(unSortedIntSeq).isSorted(SortOrder.Descending)
|
||||
check sorted(unSortedIntSeq).isSorted(SortOrder.Ascending)
|
||||
|
||||
unSortedIntSeq.sort(SortOrder.Descending)
|
||||
check unSortedIntSeq == reversed sortedIntSeq
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
discard """
|
||||
input: "Arne"
|
||||
output: '''
|
||||
Hello! What is your name?
|
||||
Nice name: Arne
|
||||
fs is: nil
|
||||
|
||||
threw exception
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
import streams
|
||||
|
||||
|
||||
block tstreams:
|
||||
var outp = newFileStream(stdout)
|
||||
var inp = newFileStream(stdin)
|
||||
write(outp, "Hello! What is your name?")
|
||||
writeLine(outp, "Hello! What is your name?")
|
||||
var line = readLine(inp)
|
||||
write(outp, "Nice name: " & line)
|
||||
writeLine(outp, "Nice name: " & line)
|
||||
|
||||
|
||||
block tstreams2:
|
||||
|
||||
@@ -1,3 +1,92 @@
|
||||
discard """
|
||||
sortoutput: true
|
||||
output: '''
|
||||
key1: value1
|
||||
key2: value2
|
||||
key_0: value0
|
||||
key_10: value10
|
||||
key_11: value11
|
||||
key_12: value12
|
||||
key_13: value13
|
||||
key_14: value14
|
||||
key_15: value15
|
||||
key_16: value16
|
||||
key_17: value17
|
||||
key_18: value18
|
||||
key_19: value19
|
||||
key_20: value20
|
||||
key_21: value21
|
||||
key_22: value22
|
||||
key_23: value23
|
||||
key_24: value24
|
||||
key_25: value25
|
||||
key_26: value26
|
||||
key_27: value27
|
||||
key_28: value28
|
||||
key_29: value29
|
||||
key_30: value30
|
||||
key_31: value31
|
||||
key_32: value32
|
||||
key_33: value33
|
||||
key_34: value34
|
||||
key_35: value35
|
||||
key_36: value36
|
||||
key_37: value37
|
||||
key_38: value38
|
||||
key_39: value39
|
||||
key_3: value3
|
||||
key_40: value40
|
||||
key_41: value41
|
||||
key_42: value42
|
||||
key_43: value43
|
||||
key_44: value44
|
||||
key_45: value45
|
||||
key_46: value46
|
||||
key_47: value47
|
||||
key_48: value48
|
||||
key_49: value49
|
||||
key_4: value4
|
||||
key_50: value50
|
||||
key_51: value51
|
||||
key_52: value52
|
||||
key_53: value53
|
||||
key_54: value54
|
||||
key_55: value55
|
||||
key_56: value56
|
||||
key_57: value57
|
||||
key_58: value58
|
||||
key_59: value59
|
||||
key_5: value5
|
||||
key_60: value60
|
||||
key_61: value61
|
||||
key_62: value62
|
||||
key_63: value63
|
||||
key_64: value64
|
||||
key_65: value65
|
||||
key_66: value66
|
||||
key_67: value67
|
||||
key_68: value68
|
||||
key_69: value69
|
||||
key_6: value6
|
||||
key_70: value70
|
||||
key_71: value71
|
||||
key_72: value72
|
||||
key_73: value73
|
||||
key_74: value74
|
||||
key_75: value75
|
||||
key_76: value76
|
||||
key_77: value77
|
||||
key_78: value78
|
||||
key_79: value79
|
||||
key_7: value7
|
||||
key_80: value80
|
||||
key_8: value8
|
||||
key_9: value9
|
||||
length of table 81
|
||||
value1 = value2
|
||||
'''
|
||||
"""
|
||||
|
||||
import strtabs
|
||||
|
||||
var tab = newStringTable({"key1": "val1", "key2": "val2"},
|
||||
@@ -9,4 +98,4 @@ for key, val in pairs(tab):
|
||||
writeLine(stdout, key, ": ", val)
|
||||
writeLine(stdout, "length of table ", $tab.len)
|
||||
|
||||
writeLine(stdout, `%`("$key1 = $key2; ${PATH}", tab, {useEnvironment}))
|
||||
writeLine(stdout, `%`("$key1 = $key2", tab, {useEnvironment}))
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
# iterate over all files with a given filter:
|
||||
|
||||
import
|
||||
"../../lib/pure/os.nim", ../../ lib / pure / times
|
||||
|
||||
proc main(filter: string) =
|
||||
for filename in walkFiles(filter):
|
||||
writeLine(stdout, filename)
|
||||
|
||||
for key, val in envPairs():
|
||||
writeLine(stdout, key & '=' & val)
|
||||
|
||||
main("*.nim")
|
||||
@@ -1,9 +1,5 @@
|
||||
discard """
|
||||
output: '''
|
||||
1
|
||||
yay
|
||||
12
|
||||
'''
|
||||
action: compile
|
||||
"""
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user