nimpretty: test for idempotence; fixes #9483
This commit is contained in:
parent
8500076651
commit
06a6433db7
4 changed files with 28 additions and 8 deletions
|
|
@ -1140,7 +1140,10 @@ proc skip(L: var TLexer, tok: var TToken) =
|
||||||
inc(pos)
|
inc(pos)
|
||||||
inc(indent)
|
inc(indent)
|
||||||
elif buf[pos] == '#' and buf[pos+1] == '[':
|
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)
|
skipMultiLineComment(L, tok, pos+2, false)
|
||||||
pos = L.bufpos
|
pos = L.bufpos
|
||||||
buf = L.buf
|
buf = L.buf
|
||||||
|
|
@ -1160,7 +1163,6 @@ proc skip(L: var TLexer, tok: var TToken) =
|
||||||
hasComment = true
|
hasComment = true
|
||||||
if tok.line < 0:
|
if tok.line < 0:
|
||||||
tok.line = L.lineNumber
|
tok.line = L.lineNumber
|
||||||
#commentIndent = L.currLineIndent # if tok.strongSpaceA == 0: -1 else: tok.strongSpaceA
|
|
||||||
|
|
||||||
if buf[pos+1] == '[':
|
if buf[pos+1] == '[':
|
||||||
skipMultiLineComment(L, tok, pos+2, false)
|
skipMultiLineComment(L, tok, pos+2, false)
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,12 @@ when defined(develop):
|
||||||
else:
|
else:
|
||||||
const nimp = "nimpretty"
|
const nimp = "nimpretty"
|
||||||
|
|
||||||
proc test(infile, outfile: string) =
|
proc test(infile, ext: string) =
|
||||||
if execShellCmd("$# -o:$# --backup:off $#" % [nimp, outfile, infile]) != 0:
|
if execShellCmd("$# -o:$# --backup:off $#" % [nimp, infile.changeFileExt(ext), infile]) != 0:
|
||||||
quit("FAILURE")
|
quit("FAILURE")
|
||||||
let nimFile = splitFile(infile).name
|
let nimFile = splitFile(infile).name
|
||||||
let expected = dir / "expected" / nimFile & ".nim"
|
let expected = dir / "expected" / nimFile & ".nim"
|
||||||
let produced = dir / nimFile & ".pretty"
|
let produced = dir / nimFile.changeFileExt(ext)
|
||||||
if strip(readFile(expected)) != strip(readFile(produced)):
|
if strip(readFile(expected)) != strip(readFile(produced)):
|
||||||
echo "FAILURE: files differ: ", nimFile
|
echo "FAILURE: files differ: ", nimFile
|
||||||
discard execShellCmd("diff -uNdr " & expected & " " & produced)
|
discard execShellCmd("diff -uNdr " & expected & " " & produced)
|
||||||
|
|
@ -29,8 +29,12 @@ proc test(infile, outfile: string) =
|
||||||
echo "SUCCESS: files identical: ", nimFile
|
echo "SUCCESS: files identical: ", nimFile
|
||||||
|
|
||||||
for t in walkFiles(dir / "*.nim"):
|
for t in walkFiles(dir / "*.nim"):
|
||||||
let res = t.changeFileExt("pretty")
|
test(t, "pretty")
|
||||||
test(t, res)
|
# also test that pretty(pretty(x)) == pretty(x)
|
||||||
removeFile(res)
|
test(t.changeFileExt("pretty"), "pretty2")
|
||||||
|
|
||||||
|
removeFile(t.changeFileExt("pretty"))
|
||||||
|
removeFile(t.changeFileExt("pretty2"))
|
||||||
|
|
||||||
|
|
||||||
if failures > 0: quit($failures & " failures occurred.")
|
if failures > 0: quit($failures & " failures occurred.")
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,10 @@ proc funB() =
|
||||||
# echo "ok2"
|
# echo "ok2"
|
||||||
|
|
||||||
fun()
|
fun()
|
||||||
|
|
||||||
|
#[
|
||||||
|
bug #9483
|
||||||
|
]#
|
||||||
|
|
||||||
|
proc funE() =
|
||||||
|
echo "ok1"
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,10 @@ proc funB() =
|
||||||
# echo "ok2"
|
# echo "ok2"
|
||||||
|
|
||||||
fun()
|
fun()
|
||||||
|
|
||||||
|
#[
|
||||||
|
bug #9483
|
||||||
|
]#
|
||||||
|
|
||||||
|
proc funE() =
|
||||||
|
echo "ok1"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue