summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-10-24 15:19:29 +0200
committerAraq <rumpf_a@web.de>2018-10-24 15:19:29 +0200
commit06a6433db7cc32e957d4f78640e388ea5d09b1a3 (patch)
tree525bd165709f1f0c952b6b1d5209b6c98354b803
parent85000766518bac45b712c26511cf4d39c3e845a6 (diff)
downloadNim-06a6433db7cc32e957d4f78640e388ea5d09b1a3.tar.gz
nimpretty: test for idempotence; fixes #9483
-rw-r--r--compiler/lexer.nim6
-rw-r--r--nimpretty/tester.nim16
-rw-r--r--nimpretty/tests/expected/simple2.nim7
-rw-r--r--nimpretty/tests/simple2.nim7
4 files changed, 28 insertions, 8 deletions
diff --git a/compiler/lexer.nim b/compiler/lexer.nim
index f9fa10a0b..47083216a 100644
--- a/compiler/lexer.nim
+++ b/compiler/lexer.nim
@@ -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)
diff --git a/nimpretty/tester.nim b/nimpretty/tester.nim
index c4e364752..d94071491 100644
--- a/nimpretty/tester.nim
+++ b/nimpretty/tester.nim
@@ -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.")
diff --git a/nimpretty/tests/expected/simple2.nim b/nimpretty/tests/expected/simple2.nim
index f26a2f2ed..909ac48c3 100644
--- a/nimpretty/tests/expected/simple2.nim
+++ b/nimpretty/tests/expected/simple2.nim
@@ -13,3 +13,10 @@ proc funB() =
   # echo "ok2"
 
 fun()
+
+#[
+bug #9483
+]#
+
+proc funE() =
+  echo "ok1"
diff --git a/nimpretty/tests/simple2.nim b/nimpretty/tests/simple2.nim
index 6cf9573df..4ef2ddd70 100644
--- a/nimpretty/tests/simple2.nim
+++ b/nimpretty/tests/simple2.nim
@@ -13,3 +13,10 @@ proc funB() =
   # echo "ok2"
 
 fun()
+
+#[
+bug #9483
+]#
+
+proc funE() =
+  echo "ok1"