# HG changeset patch # User Arne Babenhauserheide # Date 1589483777 -7200 # Thu May 14 21:16:17 2020 +0200 # Node ID 5f6cf0d8db2680d66ce0092642b6138738b8613b # Parent 1ef2c761a2cf30ef79f54fb21afe0085132f6c98 doctest.scm updated diff --git a/doctests.scm b/doctests.scm --- a/doctests.scm +++ b/doctests.scm @@ -1,6 +1,7 @@ -#!/usr/bin/env sh -# -*- scheme -*- -exec guile -L $(dirname $(dirname $(realpath "$0"))) -e '(@@ (examples doctests) main)' -s "$0" "$@" +#!/usr/bin/env bash +(# -*- wisp -*-) +(guile -L $(dirname $(realpath "$0")) -c '(import (language wisp spec))') +(exec -a "$0" guile -L $(dirname $(realpath "$0")) --language=wisp -x .w -e '(doctests)' -c '' "$@") ; !# ;;; doctests --- simple testing by adding procedure-properties with tests. @@ -38,14 +39,13 @@ ;; #((tests (test-eqv 'A (A)))) ;; #f) -;; With wisp, you currently need to use the literal -;; ## -;; tests -;; test-equal ... +;; With wisp, you currently need to use the literal #((tests (...))) +;; TODO: add array parsing to wisp following quoting with ': +;; # a b → #(a b) and # : a b c → #((a b)) (define-module (doctests) - #:export (doctests-testmod)) + #:export (doctests-testmod main)) (import (ice-9 optargs) (ice-9 rdelim) @@ -98,14 +98,16 @@ (define (subtract a b) "Subtract B from A." - #((tests (test-eqv 3 (subtract 5 2)))) + #( + (tests (test-eqv 3 (subtract 5 2)))) (- a b)) (define (doctests-testmod mod) "Execute all doctests in the current module This procedure provides an example test:" - #((tests + #( + (tests ('mytest (define v (make-vector 5 99)) (test-assert (vector? v)) @@ -142,10 +144,15 @@ (testid (match doctest (((('quote id) tests ...) moretests ...) - (string-join (list filename (symbol->string name) (symbol->string id)) - "--")) + (string-join + (list filename + ;; escape / in paths + (string-join (string-split (symbol->string name) #\/ ) "--") + (symbol->string id)) + "--")) ((tests ...) - (string-join (list filename (symbol->string name)) + ;; escape / in paths + (string-join (list filename (string-join (string-split (symbol->string name) #\/ ) "--")) "--")))) (body (match doctest @@ -176,6 +183,15 @@ #t)))))) (loop (cdr names) (cdr doctests)))))) +(define (hello who) + "Say hello to WHO" + #( + (tests + (test-equal "Hello World!\n" + (hello "World")))) + (format #f "Hello ~a!\n" + who)) + (define %this-module (current-module)) (define (main args) (doctests-testmod %this-module))