mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
nimpretty: test for idempotence; fixes #9483
This commit is contained in:
@@ -1140,7 +1140,10 @@ proc skip(L: var TLexer, tok: var TToken) =
|
||||
inc(pos)
|
||||
inc(indent)
|
||||
elif buf[pos] == '#' and buf[pos+1] == '[':
|
||||
when defined(nimpretty): hasComment = true
|
||||
when defined(nimpretty):
|
||||
hasComment = true
|
||||
if tok.line < 0:
|
||||
tok.line = L.lineNumber
|
||||
skipMultiLineComment(L, tok, pos+2, false)
|
||||
pos = L.bufpos
|
||||
buf = L.buf
|
||||
@@ -1160,7 +1163,6 @@ proc skip(L: var TLexer, tok: var TToken) =
|
||||
hasComment = true
|
||||
if tok.line < 0:
|
||||
tok.line = L.lineNumber
|
||||
#commentIndent = L.currLineIndent # if tok.strongSpaceA == 0: -1 else: tok.strongSpaceA
|
||||
|
||||
if buf[pos+1] == '[':
|
||||
skipMultiLineComment(L, tok, pos+2, false)
|
||||
|
||||
@@ -15,12 +15,12 @@ when defined(develop):
|
||||
else:
|
||||
const nimp = "nimpretty"
|
||||
|
||||
proc test(infile, outfile: string) =
|
||||
if execShellCmd("$# -o:$# --backup:off $#" % [nimp, outfile, infile]) != 0:
|
||||
proc test(infile, ext: string) =
|
||||
if execShellCmd("$# -o:$# --backup:off $#" % [nimp, infile.changeFileExt(ext), infile]) != 0:
|
||||
quit("FAILURE")
|
||||
let nimFile = splitFile(infile).name
|
||||
let expected = dir / "expected" / nimFile & ".nim"
|
||||
let produced = dir / nimFile & ".pretty"
|
||||
let produced = dir / nimFile.changeFileExt(ext)
|
||||
if strip(readFile(expected)) != strip(readFile(produced)):
|
||||
echo "FAILURE: files differ: ", nimFile
|
||||
discard execShellCmd("diff -uNdr " & expected & " " & produced)
|
||||
@@ -29,8 +29,12 @@ proc test(infile, outfile: string) =
|
||||
echo "SUCCESS: files identical: ", nimFile
|
||||
|
||||
for t in walkFiles(dir / "*.nim"):
|
||||
let res = t.changeFileExt("pretty")
|
||||
test(t, res)
|
||||
removeFile(res)
|
||||
test(t, "pretty")
|
||||
# also test that pretty(pretty(x)) == pretty(x)
|
||||
test(t.changeFileExt("pretty"), "pretty2")
|
||||
|
||||
removeFile(t.changeFileExt("pretty"))
|
||||
removeFile(t.changeFileExt("pretty2"))
|
||||
|
||||
|
||||
if failures > 0: quit($failures & " failures occurred.")
|
||||
|
||||
@@ -13,3 +13,10 @@ proc funB() =
|
||||
# echo "ok2"
|
||||
|
||||
fun()
|
||||
|
||||
#[
|
||||
bug #9483
|
||||
]#
|
||||
|
||||
proc funE() =
|
||||
echo "ok1"
|
||||
|
||||
@@ -13,3 +13,10 @@ proc funB() =
|
||||
# echo "ok2"
|
||||
|
||||
fun()
|
||||
|
||||
#[
|
||||
bug #9483
|
||||
]#
|
||||
|
||||
proc funE() =
|
||||
echo "ok1"
|
||||
|
||||
Reference in New Issue
Block a user