wisp
 
(Arne Babenhauserheide)
2014-01-09: added a minimal, quite unclean but working testrunner.

added a minimal, quite unclean but working testrunner.

diff --git a/Makefile.am b/Makefile.am
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,8 +1,8 @@
 wisp = wisp.scm language/wisp/spec.scm
 wisp_SOURCES = wisp-guile.w wisp-reader.w
-EXTRA_DIST = $(wisp_SOURCES) $(wisp_DATA) bootstrap.sh wisp.py examples tests
+EXTRA_DIST = $(wisp_SOURCES) $(wisp_DATA) bootstrap.sh wisp.py examples tests runtests.sh
 CLEANFILES = ${wisp} 
-DISTCLEANFILES = ${CLEANFILES} @builddir@/1 @builddir@/2
+DISTCLEANFILES = ${CLEANFILES} @abs_top_builddir@/1 @abs_top_builddir@/2 @abs_top_builddir@/test.sh
 
 all : ${wisp} $(changelog)
 
@@ -11,4 +11,12 @@ all : ${wisp} $(changelog)
 
 .INTERMEDIATE: input.in.intermediate
 input.in.intermediate: ${wisp_SOURCES}
-	@srcdir@/bootstrap.sh @srcdir@
+	@abs_top_srcdir@/bootstrap.sh @abs_top_srcdir@
+
+.PHONY: test.sh
+test.sh : wisp.scm runtests.sh
+	echo '#!/bin/bash' > @abs_top_builddir@/test.sh
+	echo @abs_top_srcdir@/runtests.sh @abs_top_srcdir@ @abs_top_builddir@ >> @abs_top_builddir@/test.sh
+	chmod +x @abs_top_builddir@/test.sh
+
+TESTS=test.sh
diff --git a/runtests.sh b/runtests.sh
new file mode 100755
--- /dev/null
+++ b/runtests.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+# Simple test runner for wisp, mainly intended to be run by autotools.
+
+if [[ x"$1" == x"" || x"$1" == x"." ]]; then
+    srcdir="$(pwd)"
+else
+    srcdir="$1"
+fi
+
+if [[ x"$2" == x"" || x"$2" == x"."  ]]; then
+    builddir="$(pwd)"
+else
+    builddir="$2"
+fi
+
+failed=0
+cd ${srcdir}/tests
+for i in *.w; do
+    d=$(guile ${builddir}/wisp.scm "$i" > ${builddir}/testtempfoo.scm; diff -wuB ${builddir}/testtempfoo.scm "$(basename "$i" .w)".scm; rm ${builddir}/testtempfoo.scm)
+    if test x"$d" = x""; then
+        continue
+    else
+        echo test "$i" failed. Diff: "$d"
+        failed=1
+    fi
+done
+cd - >/dev/null # undo dir change
+exit $failed
diff --git a/tests/btest.scm b/tests/btest.scm
new file mode 100644
--- /dev/null
+++ b/tests/btest.scm
@@ -0,0 +1,4 @@
+(display "b")
+(newline)
+
+
diff --git a/tests/continuation.scm b/tests/continuation.scm
new file mode 100644
--- /dev/null
+++ b/tests/continuation.scm
@@ -0,0 +1,10 @@
+(a b c d e
+  f g h
+  i j k)
+
+(concat "I want " 
+    (getwish from me)
+    " - " username)
+
+
+
diff --git a/tests/emacs-customization-tex-master.scm b/tests/emacs-customization-tex-master.scm
new file mode 100644
--- /dev/null
+++ b/tests/emacs-customization-tex-master.scm
@@ -0,0 +1,35 @@
+(defun guess-TeX-master (filename)
+      "Guess the master file for FILENAME from currently open .tex files."
+      (let 
+          (()
+            (candidate nil)
+            (filename (file-name-nondirectory filename)))
+          (save-excursion
+            (dolist (buffer (buffer-list))
+              (with-current-buffer buffer
+
+                (let 
+                   (()
+                     (name (buffer-name))
+                     (file buffer-file-name))
+                   (if 
+                     (and file (string-match "\\.tex$" file))
+
+                     (progn
+                       (goto-char (point-min))
+                       (if 
+                          (re-search-forward 
+                            (concat "\\\\input{" filename "}")
+                            nil t)
+                          (setq candidate file))
+                       (if 
+                          (re-search-forward 
+                            (concat "\\\\include{" (file-name-sans-extension filename) "}")
+                            nil t)
+                          (setq candidate file))))))))
+          
+          (if candidate
+            (message "TeX master document: %s" (file-name-nondirectory candidate)))
+          candidate))
+
+
diff --git a/tests/emacs-customization.scm b/tests/emacs-customization.scm
new file mode 100644
--- /dev/null
+++ b/tests/emacs-customization.scm
@@ -0,0 +1,59 @@
+(if (file-directory-p "~/.emacs.d/private/journal/")
+     (setq-default journal-dir "~/.emacs.d/private/journal/"))
+
+(global-set-key [(control meta .)] 'goto-last-change-reverse)
+
+(require 'org-latex)
+(add-to-list 'org-export-latex-packages-alist 
+  '("" "minted"))
+
+(add-to-list 'org-export-latex-packages-alist 
+  '("" "color"))
+
+(setq org-export-latex-listings 'minted)
+
+(add-hook 'outline-mode-hook 
+          (lambda ()
+             (require 'outline-magic)))
+
+
+(defun find-file-as-root ()
+  "Like `ido-find-file, but automatically edit the file with
+root-privileges (using tramp/sudo), if the file is not writable by
+user."
+  (interactive)
+  (let ((file (ido-read-file-name "Edit as root: ")))
+    (unless (file-writable-p file)
+      (setq file (concat find-file-root-prefix file)))
+    (find-file file)))
+
+(defun find-current-as-root ()
+  "Reopen current file as root"
+  (interactive)
+  (set-visited-file-name (concat find-file-root-prefix (buffer-file-name)))
+  (setq buffer-read-only nil))
+
+; the next function definition is equivalent, due to inline : 
+
+(defun find-current-as-root ()
+  "Reopen current file as root"
+  (interactive)
+  (set-visited-file-name 
+    (concat find-file-root-prefix 
+      (buffer-file-name)))
+  (setq buffer-read-only nil))
+
+(custom-set-variables
+ ;; custom-set-variables was added by Custom.
+ ;; If you edit it by hand, you could mess it up, so be careful.
+ ;; Your init file should contain only one such instance.
+ ;; If there is more than one, they won't work right.
+ '(bbdb-complete-name-allow-cycling t)
+ '(bbdb-ignore-some-messages-alist (quote (("From" . "mailer-daemon"))))
+ '(bbdb-offer-save (quote savenoprompt)))
+
+
+(setq a "x"
+   b "y"
+   c "z")
+
diff --git a/tests/example.scm b/tests/example.scm
new file mode 100644
--- /dev/null
+++ b/tests/example.scm
@@ -0,0 +1,61 @@
+(defun a (b c)
+  (let
+    (()
+      (d "i am a string
+do not break me!")
+      (()
+  ; comment: 0
+        (f)
+; comment : 1
+        `(g )); comment " : " 2
+      (()
+        (h (I am in brackets:
+           do not : change "me"))
+        i)))
+  ,(' j k)
+
+  l
+
+; comment
+
+  (a c))
+
+(defun b (:n o)
+  "second defun : with a docstring!"
+  (message "I am here")
+  t)
+
+(defun c (e f)
+  ((g))
+  (:
+    (h
+      (i))
+    (j))
+  '(())
+  (k)
+  l
+  (m))
+
+(defun _ (\:)
+  
+   \:)
+
+(\_ b)
+
+(defun d ()
+      (let 
+          ((a b)
+            (c d))))
+
+(a (((c))))
+
+(let 
+    ((a b)
+      (c)))
+
+(let ((a b)))
+
+a
+
+
+
diff --git a/tests/factorial.scm b/tests/factorial.scm
new file mode 100644
--- /dev/null
+++ b/tests/factorial.scm
@@ -0,0 +1,24 @@
+;; short version
+; note: once you use one inline colon, all the following forms on that
+; line will get closed at the end of the line
+
+(define (factorial n)
+  (if (zero? n)
+    1
+    (* n (factorial (- n 1)))))
+
+(display (factorial 5 ))
+
+
+;; more vertical space, less colons
+(define (factorial n)
+  (if (zero? n)
+    1
+    (* n 
+      (factorial 
+        (- n 1)))))
+
+(display (factorial 5 ))
+
+
+
diff --git a/tests/flexible-parameter-list.scm b/tests/flexible-parameter-list.scm
new file mode 100644
--- /dev/null
+++ b/tests/flexible-parameter-list.scm
@@ -0,0 +1,14 @@
+; Test using a . as first parameter on a line by prefixing it with a second .
+(define
+  (a i
+    . b)
+  (unless (>= i (length b))
+    (display (number->string (length b )))
+    (display (list-ref b i))
+    (newline)
+    (apply a ( + i 1 ) b)))
+    
+
+(a 0 "123" "345" "567")
+
+
diff --git a/tests/linebreaks.scm b/tests/linebreaks.scm
new file mode 100644
--- /dev/null
+++ b/tests/linebreaks.scm
@@ -0,0 +1,16 @@
+; Test linebreaks in strings and brackets
+
+("flubbub
+
+flabbab")
+
+(hrug (nadda
+madda gadda "shoktom
+ mee"  " sep  
+ka"
+  hadda)
+    (gom))
+
+(flu)
+
+
diff --git a/tests/mtest.scm b/tests/mtest.scm
new file mode 100644
--- /dev/null
+++ b/tests/mtest.scm
@@ -0,0 +1,5 @@
+#!/home/arne/wisp/wisp-multiline.sh  !#
+
+(display 1)
+
+
diff --git a/tests/namedlet.scm b/tests/namedlet.scm
new file mode 100644
--- /dev/null
+++ b/tests/namedlet.scm
@@ -0,0 +1,12 @@
+#!/home/arne/wisp/wisp-multiline.sh  
+; !#
+(define (hello who)
+  (display who))
+
+(let hello
+  ((who 0))
+  (if (= who 5)
+    (display who)
+    (hello (+ 1 who))))
+
+
diff --git a/tests/quotecolon.scm b/tests/quotecolon.scm
new file mode 100644
--- /dev/null
+++ b/tests/quotecolon.scm
@@ -0,0 +1,12 @@
+#!/home/arne/wisp/wisp-multiline.sh  
+; !#
+(define a 1 ); test whether ' : correctly gets turned into '(
+; and whether brackets in commments are treated correctly.
+
+(define a '(1 2 3))
+
+(define
+  (a b)
+  (c))
+
+
diff --git a/tests/range.scm b/tests/range.scm
new file mode 100644
--- /dev/null
+++ b/tests/range.scm
@@ -0,0 +1,25 @@
+(import (rnrs))
+
+(define range
+ (case-lambda
+   ((n ); one-argument syntax
+     (range 0 n 1))
+   ((n0 n ); two-argument syntax
+     (range n0 n 1))
+   ((n0 n s ); three-argument syntax
+     (assert 
+         (and 
+             (for-all number? (list n0 n s))
+             (not (zero? s))))
+     (let ((cmp (if (positive? s) >= <= )))
+       (let loop 
+           ((i n0 )
+             (acc '()))
+           (if 
+             (cmp i n )
+             (reverse acc)
+             (loop (+ i s) (cons i acc))))))))
+             
+(display (apply string-append "" (map number->string (range 5))))
+(newline)
+
diff --git a/tests/readable-tests.scm b/tests/readable-tests.scm
new file mode 100644
--- /dev/null
+++ b/tests/readable-tests.scm
@@ -0,0 +1,39 @@
+(define (fibfast n)
+      (if (< n 2))
+      n           
+      (fibup n 2 1 0 ))
+
+(define (fibup maxnum count n-1 n-2)
+       (if (= maxnum count)
+         (+ n-1  n-2)
+         (fibup maxnum 
+               (+ count 1 )
+               (+ n-1 n-2 )
+               n-1)))
+
+(define (factorial n)
+       (if (<= n 1)
+         1
+         (* n 
+           (factorial (- n 1)))))
+
+(define (gcd x y)
+       (if (= y 0))
+       x
+       (gcd y
+         (rem x y)))
+
+(define (add-if-all-numbers lst)
+       (call/cc 
+         (lambda (exit)
+                (let loop 
+                  (()
+                    (lst lst )
+                    (sum 0))
+                  (if (null? lst)
+                     sum
+                     (if (not (number? (car lst)))
+                        (exit #f)
+                        (+ (car lst)
+                          (loop (cdr lst)))))))))
+
diff --git a/tests/shebang.scm b/tests/shebang.scm
new file mode 100644
--- /dev/null
+++ b/tests/shebang.scm
@@ -0,0 +1,4 @@
+#!/usr/bin/wisp.py # !#
+; This tests shebang lines
+
+
diff --git a/tests/sublist.scm b/tests/sublist.scm
new file mode 100644
--- /dev/null
+++ b/tests/sublist.scm
@@ -0,0 +1,7 @@
+; sublists allow to start single line function calls with a colon ( : ).
+
+(defun a (b c)
+  (let ((e . f)))
+  g)
+
+
diff --git a/tests/websafe-indent.scm b/tests/websafe-indent.scm
new file mode 100644
--- /dev/null
+++ b/tests/websafe-indent.scm
@@ -0,0 +1,7 @@
+(defun a (b c)
+  (d e
+    (f)
+    (g h)
+    i))
+
+