nimpretty: test for idempotence; fixes #9483

This commit is contained in:
Araq
2018-10-24 15:19:29 +02:00
parent 8500076651
commit 06a6433db7
4 changed files with 28 additions and 8 deletions

View File

@@ -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)

View File

@@ -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.")

View File

@@ -13,3 +13,10 @@ proc funB() =
# echo "ok2"
fun()
#[
bug #9483
]#
proc funE() =
echo "ok1"

View File

@@ -13,3 +13,10 @@ proc funB() =
# echo "ok2"
fun()
#[
bug #9483
]#
proc funE() =
echo "ok1"