From 0d600b53df3ab20cc3b9ab84ee5c79e5afe41b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 16 Oct 2023 15:04:30 +0200 Subject: Better test diffs for strings. Previously everything was passed through pretty print, meaning that strings would be squashed to one line. Instead handle strings separately, and do a line diff on them, but still pretty print actual scheme structures. Also change display to write to be able to differentiate different forms which prints the same. --- module/hnh/test/testrunner.scm | 14 ++++++-------- module/hnh/test/util.scm | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/module/hnh/test/testrunner.scm b/module/hnh/test/testrunner.scm index b3951c34..a45bd421 100644 --- a/module/hnh/test/testrunner.scm +++ b/module/hnh/test/testrunner.scm @@ -19,7 +19,7 @@ (with-output-to-string (lambda () (pretty-print form - display?: #t + display?: #f per-line-prefix: prefix width: (- 79 (string-length indent))))) (string-append indent prefix-1)))) @@ -61,13 +61,11 @@ (begin (display (pp expected indent "Expected: ")) (display (pp actual indent "Received: ")) - (let ((d (diff (pp expected "" "") - (pp actual "" "")))) - (display - (string-join - (map (lambda (line) (string-append indent "|" line)) - (string-split d #\newline)) - "\n" 'suffix)))))))))) + (display + (string-join + (map (lambda (line) (string-append indent "|" line)) + (string-split (diff expected actual) #\newline)) + "\n" 'suffix))))))))) (format #t "~aNear ~a:~a~%" (make-indent (1+ depth)) diff --git a/module/hnh/test/util.scm b/module/hnh/test/util.scm index 3d51e162..b0f3342a 100644 --- a/module/hnh/test/util.scm +++ b/module/hnh/test/util.scm @@ -48,8 +48,18 @@ ) (define (diff s1 s2) - (let ((filename1 (call-with-tmpfile (lambda (p f) (pretty-print s1 p display?: #t) f))) - (filename2 (call-with-tmpfile (lambda (p f) (pretty-print s2 p display?: #t) f)))) + (let ((filename1 (call-with-tmpfile + (lambda (p f) + (if (and (string? s1) (string? s2)) + (display s1 p) + (pretty-print s1 p display?: #f)) + f))) + (filename2 (call-with-tmpfile + (lambda (p f) + (if (and (string? s1) (string? s2)) + (display s2 p) + (pretty-print s2 p display?: #f)) + f)))) (let ((pipe (apply open-pipe* OPEN_READ (append diff-cmd (list filename1 filename2))))) -- cgit v1.2.3