summary refs log tree commit diff stats
path: root/nimpretty/tester.nim
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 /nimpretty/tester.nim
parent85000766518bac45b712c26511cf4d39c3e845a6 (diff)
downloadNim-06a6433db7cc32e957d4f78640e388ea5d09b1a3.tar.gz
nimpretty: test for idempotence; fixes #9483
Diffstat (limited to 'nimpretty/tester.nim')
-rw-r--r--nimpretty/tester.nim16
1 files changed, 10 insertions, 6 deletions
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.")