test: Use diff -ub for tinycc tests.

* build-aux/diff.scm: Support -b.
* build-aux/test.sh: Use it.
This commit is contained in:
Jan Nieuwenhuizen 2018-05-18 18:34:58 +02:00
parent cac2ba7b06
commit 95fdfb2261
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
2 changed files with 9 additions and 6 deletions

View File

@ -66,6 +66,9 @@ exec ${GUILE-guile} -L $(dirname 0) -e '(diff)' -s "$0" "$@"
(define (safe-list-head lst n) (define (safe-list-head lst n)
(list-head lst (min n (length lst)))) (list-head lst (min n (length lst))))
(define (line-equal? a b)
(equal? (string-trim-right a) (string-trim-right b)))
;; naive diff ;; naive diff
(define (diff a b) (define (diff a b)
(let ((a-lines (string-split (with-input-from-file a read-string) #\newline)) (let ((a-lines (string-split (with-input-from-file a read-string) #\newline))
@ -77,21 +80,21 @@ exec ${GUILE-guile} -L $(dirname 0) -e '(diff)' -s "$0" "$@"
(list (make-hunk context (safe-list-head a-lines 3) '() b-lines))) (list (make-hunk context (safe-list-head a-lines 3) '() b-lines)))
((null? b-lines) ((null? b-lines)
(list (make-hunk context (safe-list-head a-lines 3) a-lines '()))) (list (make-hunk context (safe-list-head a-lines 3) a-lines '())))
((equal? (car a-lines) (car b-lines)) ((line-equal? (car a-lines) (car b-lines))
(loop `(,(1+ (car context)) (loop `(,(1+ (car context))
,(1+ (cadr context)) ,(1+ (cadr context))
,@(cdddr context) ,@(cdddr context)
,(car a-lines)) ,(car a-lines))
(cdr a-lines) (cdr b-lines))) (cdr a-lines) (cdr b-lines)))
(else (else
(cond ((and (pair? (cdr b-lines)) (equal? (car a-lines) (cadr b-lines))) (cond ((and (pair? (cdr b-lines)) (line-equal? (car a-lines) (cadr b-lines)))
(cons (make-hunk context (safe-list-head a-lines 3) '() (list (car b-lines))) (cons (make-hunk context (safe-list-head a-lines 3) '() (list (car b-lines)))
(loop `(,(+ 1 (car context)) (loop `(,(+ 1 (car context))
,(+ 2 (cadr context)) ,(+ 2 (cadr context))
,@(cdddr context) ,@(cdddr context)
,(car a-lines)) ,(car a-lines))
(cdr a-lines) (cddr b-lines)))) (cdr a-lines) (cddr b-lines))))
((and (pair? (cdr a-lines)) (equal? (cadr a-lines) (car b-lines))) ((and (pair? (cdr a-lines)) (line-equal? (cadr a-lines) (car b-lines)))
(cons (make-hunk context (safe-list-head a-lines 3) (list (car a-lines)) '()) (cons (make-hunk context (safe-list-head a-lines 3) (list (car a-lines)) '())
(loop `(,(+ 2 (car context)) (loop `(,(+ 2 (car context))
,(+ 1 (cadr context)) ,(+ 1 (cadr context))
@ -108,7 +111,7 @@ exec ${GUILE-guile} -L $(dirname 0) -e '(diff)' -s "$0" "$@"
(define (main args) (define (main args)
(let* ((files (cdr args)) (let* ((files (cdr args))
(files (if (equal? (car files) "-u") (cdr files) files)) (files (if (string-prefix? "-" (car files)) (cdr files) files))
(hunks (apply diff (list-head files 2)))) (hunks (apply diff (list-head files 2))))
(when (pair? hunks) (when (pair? hunks)
(display (string-join (append-map hunk->lines hunks) "\n")) (display (string-join (append-map hunk->lines hunks) "\n"))

View File

@ -44,7 +44,7 @@ if [ -n "$CC32" ]; then
[ $m = $r ] [ $m = $r ]
if [ -f "$t".expect ]; then if [ -f "$t".expect ]; then
$DIFF -u "$t".expect "$t".mlibc-stdout; $DIFF -ub "$t".expect "$t".mlibc-stdout;
fi fi
fi fi
@ -61,5 +61,5 @@ set -e
[ $m = $r ] [ $m = $r ]
if [ -f "$t".expect ]; then if [ -f "$t".expect ]; then
$DIFF -u "$t".expect "$t".mes-stdout; $DIFF -ub "$t".expect "$t".mes-stdout;
fi fi