From 06a6433db7cc32e957d4f78640e388ea5d09b1a3 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 24 Oct 2018 15:19:29 +0200 Subject: nimpretty: test for idempotence; fixes #9483 --- nimpretty/tester.nim | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'nimpretty/tester.nim') 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.") -- cgit 1.4.1-2-gfad0