mes/tests/scm.test

168 lines
5.9 KiB
Plaintext
Raw Normal View History

#! /bin/sh
# -*-scheme-*-
if [ "$MES" != guile ]; then
MES_BOOT=boot-03.scm exec ${MES-bin/mes} < $0
fi
exec ${MES-bin/mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests boot)' -s "$0" "$@"
!#
;;; -*-scheme-*-
;;; GNU Mes --- Maxwell Equations of Software
;;; Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2023 Ekaitz Zarraga <ekaitz@elenq.tech>
;;;
;;; This file is part of GNU Mes.
;;;
;;; GNU Mes is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Mes is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
build: Refactor mes tests. * build-aux/check-mes.sh: New file. * check.sh: Invoke it for Guile and Mes. * .gitignore: Ignore new guile logs. * mes/module/mes/boot-0.scm: Ignore some standard Guile options. * module/mes/test.scm: Make a module. * tests/base.test: Use it. Make a module, support invoking with Guile or Mes alike. * tests/boot.test: Likewise. * tests/catch.test: Likewise. * tests/closure.test: Likewise. * tests/cwv.test: Likewise. * tests/display.test: Likewise. * tests/fluids.test: Likewise. * tests/getopt-long.test: Likewise. * tests/guile.test: Likewise. * tests/let-syntax.test: Likewise. * tests/let.test: Likewise. * tests/match.test: Likewise. * tests/math.test: Likewise. * tests/module.test: Likewise. * tests/optargs.test: Likewise. * tests/peg.test: Likewise. * tests/pmatch.test: Likewise. * tests/psyntax.test: Likewise. * tests/quasiquote.test: Likewise. * tests/read.test: Likewise. * tests/scm.test: Likewise. * tests/srfi-13.test: Likewise. * tests/srfi-14.test: Likewise. * tests/srfi-16.test: Likewise. * tests/srfi-1.test: Likewise. * tests/srfi-43.test: Likewise. * tests/srfi-9.test: Likewise. * tests/syntax.test: Likewise. * tests/vector.test: Likewise. * tests/base.test-guile: Remove. * tests/boot.test-guile: Remove. * tests/catch.test-guile: Remove. * tests/closure.test-guile: Remove. * tests/cwv.test-guile: Remove. * tests/display.test-guile: Remove. * tests/fluids.test-guile: Remove. * tests/getopt-long.test-guile: Remove. * tests/guile.test-guile: Remove. * tests/let-syntax.test-guile: Remove. * tests/let.test-guile: Remove. * tests/match.test-guile: Remove. * tests/math.test-guile: Remove. * tests/module.test-guile: Remove. * tests/optargs.test-guile: Remove. * tests/peg.test-guile: Remove. * tests/pmatch.test-guile: Remove. * tests/psyntax.test-guile: Remove. * tests/quasiquote.test-guile: Remove. * tests/read.test-guile: Remove. * tests/scm.test-guile: Remove. * tests/srfi-13.test-guile: Remove. * tests/srfi-14.test-guile: Remove. * tests/srfi-16.test-guile: Remove. * tests/srfi-1.test-guile: Remove. * tests/srfi-43.test-guile: Remove. * tests/srfi-9.test-guile: Remove. * tests/syntax.test-guile: Remove. * tests/vector.test-guile: Remove.
2018-07-21 11:48:50 +00:00
(define-module (tests scm)
#:use-module (mes mes-0)
#:use-module (mes test))
(mes-use-module (mes catch))
(cond-expand
(mes
(primitive-load "module/mes/test.scm"))
(guile-2)
(guile
(use-modules (ice-9 syncase))))
Prepare for 0.1 release: new directory structure. * scripts/elf.mes: New file. * scripts/include.mes: New file. * scripts/mescc.mes: New file. * scripts/paren.mes: New file. * scripts/repl.mes: New file. * doc/examples/main.c: Move from ./main.c. * module/mes/base-0.mes: Move from ./base0.mes. * module/mes/base.mes: Move from top. * module/mes/elf.mes: Likewise. * module/mes/let-syntax.mes: Likewise. * module/mes/let.mes: Likewise. * module/mes/mes.mes: Likewise. * module/mes/quasiquote.mes: Likewise. * module/mes/repl.mes: Likewise. * module/mes/scm.mes: Likewise. * module/mes/syntax.mes: Likewise. * module/mes/lalr-0.mes: Move from lib/lalr.mes. * module/mes/lalr.mes: Move from lib/lalr.scm. * module/mes/match.mes: Move from lib/match.scm. * module/mes/record-0.mes: Move from lib/record.mes. * module/mes/record.mes: Move from lib/record.scm. * module/mes/test.mes: Move flom lib/. * module/rnrs/bytevectors.mes: Move from lib/rnrs. * module/srfi/srfi-0.mes: Move from lib/srfi. * module/srfi/srfi-1.mes: Likewise. * module/srfi/srfi-9.mes: Likewise. * module/language/c/lexer.mes: Move from ./c-lexer.scm. * module/language/c/parser.mes: Move from ./mescc.scm. * module/language/c/compiler.mes: New file, split from parser.mes. * module/language/paren.mes: Move from ./paren.scm. * module/mes/libc-i386.mes: New file, split from elf.mes. * tests/base.test: Move from test/. * tests/closure.test: Likewise. * tests/let-syntax.test: Likewise. * tests/let.test: Likewise. * tests/match.test: Likewise. * tests/quasiquote.test: Likewise. * tests/record.test: Likewise. * tests/scm.test: Likewise. * hello.S: Remove. * hello.c: Remove. * loop2.mes: Remove. * test/foo.test: Remove.
2016-10-12 21:40:11 +00:00
(pass-if "first dummy" #t)
(pass-if-not "second dummy" #f)
(pass-if "when" (seq? (when #t 'true) 'true))
(pass-if "when 2" (seq? (when #f 'true) *unspecified*))
2016-07-18 20:52:12 +00:00
(pass-if "map" (sequal? (map identity '(1 2 3 4)) '(1 2 3 4)))
(pass-if "map 2 " (sequal? (map (lambda (i a) (cons i a)) '(1 2 3 4) '(a b c d))
2016-07-24 10:40:44 +00:00
'((1 . a) (2 . b) (3 . c) (4 . d))))
2016-07-24 10:40:44 +00:00
(pass-if "for-each" (sequal? (let ((acc '())) (for-each (lambda (x) (set! acc (cons x acc))) '(1 2 3 4)) acc) '(4 3 2 1)))
(define xxxa 0)
2016-07-18 20:52:12 +00:00
(pass-if "set! " (seq? (begin (set! xxxa 1) xxxa) 1))
(pass-if "set! 2" (seq? (let ((a 0)) (set! a 1) a) 1))
(pass-if "list-ref" (seq? (list-ref '(0 1 2) 1) 1))
(pass-if "do" (sequal? (let ((acc '())) (do ((i 0 (+ i 1))) ((>= i 3)) (set! acc (cons i acc))) acc) '(2 1 0)))
mes: Add incremental test suite. * check-boot.sh: New file. * check.sh: Invoke it. * module/srfi/srfi-16.mes: New file. * scaffold/boot/00-zero.scm: New file. * scaffold/boot/01-true.scm: New file. * scaffold/boot/02-symbol.scm: New file. * scaffold/boot/03-string.scm: New file. * scaffold/boot/04-cons.scm: New file. * scaffold/boot/04-quote.scm: New file. * scaffold/boot/05-list.scm: New file. * scaffold/boot/06-tick.scm: New file. * scaffold/boot/07-if.scm: New file. * scaffold/boot/08-if-if.scm: New file. * scaffold/boot/10-cons.scm: New file. * scaffold/boot/11-list.scm: New file. * scaffold/boot/12-car.scm: New file. * scaffold/boot/13-cdr.scm: New file. * scaffold/boot/14-exit.scm: New file. * scaffold/boot/15-display.scm: New file. * scaffold/boot/16-if-eq-quote.scm: New file. * scaffold/boot/20-define-quote.scm: New file. * scaffold/boot/20-define-quoted.scm: New file. * scaffold/boot/20-define.scm: New file. * scaffold/boot/21-define-procedure.scm: New file. * scaffold/boot/22-define-procedure-2.scm: New file. * scaffold/boot/23-begin.scm: New file. * scaffold/boot/24-begin-define.scm: New file. * scaffold/boot/25-begin-define-2.scm: New file. * scaffold/boot/26-begin-define-later.scm: New file. * scaffold/boot/26-define-define.scm: New file. * scaffold/boot/27-lambda-define.scm: New file. * scaffold/boot/28-define-define.scm: New file. * scaffold/boot/29-lambda-define.scm: New file. * scaffold/boot/2a-lambda-lambda.scm: New file. * scaffold/boot/2b-define-lambda.scm: New file. * scaffold/boot/2c-define-lambda-recurse.scm: New file. * scaffold/boot/2d-define-lambda-set.scm: New file. * scaffold/boot/2e-define-second.scm: New file. * scaffold/boot/30-capture.scm: New file. * scaffold/boot/31-capture-define.scm: New file. * scaffold/boot/32-capture-modify-close.scm: New file. * scaffold/boot/33-procedure-override-close.scm: New file. * scaffold/boot/34-cdr-override-close.scm: New file. * scaffold/boot/35-closure-modify.scm: New file. * scaffold/boot/36-closure-override.scm: New file. * scaffold/boot/37-closure-lambda.scm: New file. * scaffold/boot/38-simple-format.scm: New file. * scaffold/boot/40-define-macro.scm: New file. * scaffold/boot/41-when.scm: New file. * scaffold/boot/42-if-when.scm: New file. * scaffold/boot/43-or.scm: New file. * scaffold/boot/44-or-if.scm: New file. * scaffold/boot/45-pass-if.scm: New file. * scaffold/boot/46-report.scm: New file. * scaffold/boot/47-pass-if-eq.scm: New file. * scaffold/boot/48-let.scm: New file. * scaffold/boot/49-macro-override.scm: New file. * scaffold/boot/4a-define-macro-define-macro.scm: New file. * scaffold/boot/4b-define-macro-define.scm: New file. * scaffold/boot/4c-quasiquote.scm: New file. * scaffold/boot/50-primitive-load.scm: New file. * scaffold/boot/51-module.scm: New file. * scaffold/boot/52-define-module.scm: New file. * scaffold/boot/53-closure-display.scm: New file. * scaffold/boot/60-let-syntax.scm: New file. * scaffold/boot/closure.scm: New file. * scaffold/boot/compose.scm: New file. * scaffold/boot/data/bar.mes: New file. * scaffold/boot/data/i.scm: New file. * scaffold/boot/data/module.mes: New file. * scaffold/boot/foo.scm: New file. * scaffold/boot/lambda-star.scm: New file. * scaffold/boot/vector.scm: New file. * tests/boot.test: New file. * tests/boot.test-guile: New file. * tests/srfi-16.test: New file. * tests/srfi-16.test-guile: New file.
2018-01-25 05:58:44 +00:00
(pass-if ">=" (>= 3 2 1))
(pass-if-equal "string-length"
0
(string-length ""))
(pass-if-equal "string-length 2"
3
(string-length (string-append "a" "b" "c")))
(pass-if-equal "string->list"
'()
(string->list ""))
(pass-if-equal "string->list 2"
'(#\a #\b #\c #\newline)
(string->list "abc\n"))
2016-07-18 20:52:12 +00:00
(pass-if "string-append" (sequal? (string-append "a" "b" "c") "abc"))
(pass-if "substring" (sequal? (substring "hello world" 6) "world"))
(pass-if "substring 2" (sequal? (substring "hello world" 4 7) "o w"))
(pass-if "string-ref" (seq? (string-ref "hello world" 4) #\o))
2016-07-18 20:59:33 +00:00
(pass-if "eq?" (not (eq? (string-append "a" "b" "c") "abc")))
2016-07-18 20:52:12 +00:00
(pass-if "char" (seq? (char->integer #\A) 65))
(pass-if "char 2" (seq? (char->integer #\101) (char->integer #\A)))
(pass-if "char 3" (seq? (integer->char 10) #\newline))
(pass-if "char 4" (seq? (integer->char 32) #\space))
(pass-if "string " (sequal? (string #\a #\space #\s #\t #\r #\i #\n #\g) "a string"))
(pass-if "length" (seq? (length '()) 0))
(pass-if "length 2" (seq? (length '(a b c)) 3))
(pass-if "make-list" (seq? (make-list 0) '()))
(pass-if "make-list 1" (sequal? (make-list 1 0) '(0)))
2016-07-18 20:52:12 +00:00
(pass-if "memq" (sequal? (memq 'a '(a b c)) '(a b c)))
(pass-if "memq" (sequal? (memq 'b '(a b c)) '(b c)))
(pass-if "memq" (seq? (memq 'd '(a b c)) #f))
(pass-if "member" (sequal? (member '(a) '((a) b c)) '((a) b c)))
2016-07-22 23:38:25 +00:00
(pass-if "assq-ref" (seq? (assq-ref '((b . 1) (c . 2)) 'c) 2))
(pass-if "assq-ref 2" (seq? (assq-ref '((b . 1) (c . 2)) 'a) #f))
(pass-if "assq-set!" (sequal? (assq-set! '((b . 1)) 'a 0) '((a . 0) (b . 1))))
(pass-if "assq-set! 2" (sequal? (assq-set! '((a . 0)) 'a 1) '((a . 1))))
2016-07-24 10:08:21 +00:00
(pass-if "assoc" (sequal? (assoc '(a . 0) '((a . 0) (b . 1) ((a . 0) aa))) '((a . 0) aa)))
(pass-if-equal "assoc-set!" '((a . 0) (b . 2)) (assoc-set! '((a . 0) (b . 1)) 'b 2))
(pass-if-equal "assoc-set! new" '((b . 2) (a . 0)) (assoc-set! '((a . 0)) 'b 2))
2016-07-11 18:58:30 +00:00
(pass-if "builtin? car" (builtin? car))
(pass-if "builtin? cdr" (builtin? cdr))
(pass-if "builtin? cons" (builtin? cons))
(pass-if "builtin? eq?" (builtin? eq?))
(pass-if "builtin? if" (builtin? eq?))
(when (not guile?)
(pass-if "builtin? eval" (not (builtin? not))))
(pass-if "procedure?" (procedure? builtin?))
(pass-if "procedure?" (procedure? procedure?))
(pass-if "gensym"
(symbol? (gensym)))
(pass-if "gensym 1"
(not (eq? (gensym) (gensym))))
(pass-if "gensym 2"
(not (eq? (gensym) (gensym))))
2016-07-22 07:00:32 +00:00
2016-07-23 06:17:49 +00:00
(pass-if "last-pair " (sequal? (last-pair '(1 2 3 4)) '(4)))
2016-07-24 10:08:21 +00:00
(pass-if "last-pair 2" (seq? (last-pair '()) '()))
2016-07-23 06:17:49 +00:00
;; (pass-if "circular-list? "
;; (seq?
;; (let ((x (list 1 2 3 4)))
;; (set-cdr! (last-pair x) (cddr x))
;; (circular-list? x))
;; #t))
(pass-if-equal "iota"
'(0 1 2) (iota 3))
(pass-if-equal "iota 0"
'() (iota 0))
(pass-if-equal "iota -1"
'iota-negative-length
(catch 'wrong-type-arg
(lambda ()
(iota -1))
(lambda (key . args)
'iota-negative-length)))
2016-07-23 13:17:03 +00:00
(pass-if "cond-expand" (sequal? (cond-expand (foobar #f) (mes (display ": pass: *YAY*") 'mes) (guile (display ": pass: *GUILE*") 'mes)) 'mes))
2016-07-23 10:54:34 +00:00
2016-07-24 11:27:05 +00:00
(pass-if "apply identity" (seq? (apply identity '(0)) 0))
(pass-if "apply identity 2" (sequal? (apply identity '((0 1))) '(0 1)))
(pass-if "apply append" (sequal? (apply append '((1 2) (3 4))) '(1 2 3 4)))
(pass-if "char-alphabetic?" (seq? (char-alphabetic? #\a) #t))
(pass-if "char-alphabetic? 2" (seq? (char-alphabetic? #\[) #f))
(pass-if-equal "compose" 1 ((compose car cdr car) '((0 1 2))))
mes: Add incremental test suite. * check-boot.sh: New file. * check.sh: Invoke it. * module/srfi/srfi-16.mes: New file. * scaffold/boot/00-zero.scm: New file. * scaffold/boot/01-true.scm: New file. * scaffold/boot/02-symbol.scm: New file. * scaffold/boot/03-string.scm: New file. * scaffold/boot/04-cons.scm: New file. * scaffold/boot/04-quote.scm: New file. * scaffold/boot/05-list.scm: New file. * scaffold/boot/06-tick.scm: New file. * scaffold/boot/07-if.scm: New file. * scaffold/boot/08-if-if.scm: New file. * scaffold/boot/10-cons.scm: New file. * scaffold/boot/11-list.scm: New file. * scaffold/boot/12-car.scm: New file. * scaffold/boot/13-cdr.scm: New file. * scaffold/boot/14-exit.scm: New file. * scaffold/boot/15-display.scm: New file. * scaffold/boot/16-if-eq-quote.scm: New file. * scaffold/boot/20-define-quote.scm: New file. * scaffold/boot/20-define-quoted.scm: New file. * scaffold/boot/20-define.scm: New file. * scaffold/boot/21-define-procedure.scm: New file. * scaffold/boot/22-define-procedure-2.scm: New file. * scaffold/boot/23-begin.scm: New file. * scaffold/boot/24-begin-define.scm: New file. * scaffold/boot/25-begin-define-2.scm: New file. * scaffold/boot/26-begin-define-later.scm: New file. * scaffold/boot/26-define-define.scm: New file. * scaffold/boot/27-lambda-define.scm: New file. * scaffold/boot/28-define-define.scm: New file. * scaffold/boot/29-lambda-define.scm: New file. * scaffold/boot/2a-lambda-lambda.scm: New file. * scaffold/boot/2b-define-lambda.scm: New file. * scaffold/boot/2c-define-lambda-recurse.scm: New file. * scaffold/boot/2d-define-lambda-set.scm: New file. * scaffold/boot/2e-define-second.scm: New file. * scaffold/boot/30-capture.scm: New file. * scaffold/boot/31-capture-define.scm: New file. * scaffold/boot/32-capture-modify-close.scm: New file. * scaffold/boot/33-procedure-override-close.scm: New file. * scaffold/boot/34-cdr-override-close.scm: New file. * scaffold/boot/35-closure-modify.scm: New file. * scaffold/boot/36-closure-override.scm: New file. * scaffold/boot/37-closure-lambda.scm: New file. * scaffold/boot/38-simple-format.scm: New file. * scaffold/boot/40-define-macro.scm: New file. * scaffold/boot/41-when.scm: New file. * scaffold/boot/42-if-when.scm: New file. * scaffold/boot/43-or.scm: New file. * scaffold/boot/44-or-if.scm: New file. * scaffold/boot/45-pass-if.scm: New file. * scaffold/boot/46-report.scm: New file. * scaffold/boot/47-pass-if-eq.scm: New file. * scaffold/boot/48-let.scm: New file. * scaffold/boot/49-macro-override.scm: New file. * scaffold/boot/4a-define-macro-define-macro.scm: New file. * scaffold/boot/4b-define-macro-define.scm: New file. * scaffold/boot/4c-quasiquote.scm: New file. * scaffold/boot/50-primitive-load.scm: New file. * scaffold/boot/51-module.scm: New file. * scaffold/boot/52-define-module.scm: New file. * scaffold/boot/53-closure-display.scm: New file. * scaffold/boot/60-let-syntax.scm: New file. * scaffold/boot/closure.scm: New file. * scaffold/boot/compose.scm: New file. * scaffold/boot/data/bar.mes: New file. * scaffold/boot/data/i.scm: New file. * scaffold/boot/data/module.mes: New file. * scaffold/boot/foo.scm: New file. * scaffold/boot/lambda-star.scm: New file. * scaffold/boot/vector.scm: New file. * tests/boot.test: New file. * tests/boot.test-guile: New file. * tests/srfi-16.test: New file. * tests/srfi-16.test-guile: New file.
2018-01-25 05:58:44 +00:00
(if (not guile?)
(pass-if "make-vector" (sequal? (make-vector 3) #(*unspecified* *unspecified* *unspecified*))))
(pass-if "make-vector 2" (sequal? (make-vector 3 1) #(1 1 1)))
(pass-if-equal "binary" 5 #b101)
(pass-if-equal "octal" 65 #o101)
(pass-if-equal "hex" 257 #x101)
(pass-if-equal "negate" #t ((negate eq?) 0 1))
(pass-if-equal "const" 42 ((const 42) 1 2 3 4))
2016-10-10 20:42:05 +00:00
(result 'report)