Add tests for `--language'.
authorLudovic Courtès <ludo@gnu.org>
Sat, 26 Jan 2013 20:49:17 +0000 (21:49 +0100)
committerLudovic Courtès <ludo@gnu.org>
Sat, 26 Jan 2013 20:49:17 +0000 (21:49 +0100)
* test-suite/standalone/Makefile.am (top_srcdir): Add `top_srcdir'.
  (check_SCRIPTS, TESTS): Add `test-language'.
  (EXTRA_DIST): Add `test-language.el' and `test-language.js'.
* test-suite/standalone/test-language,
  test-suite/standalone/test-language.el,
  test-suite/standalone/test-language.js: New files.

test-suite/standalone/Makefile.am
test-suite/standalone/test-language [new file with mode: 0755]
test-suite/standalone/test-language.el [new file with mode: 0644]
test-suite/standalone/test-language.js [new file with mode: 0644]

index daa3d07..be5d913 100644 (file)
@@ -1,7 +1,7 @@
 ## Process this file with automake to produce Makefile.in.
 ##
 ## Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-##   2011, 2012 Free Software Foundation, Inc.
+##   2011, 2012, 2013 Free Software Foundation, Inc.
 ##
 ## This file is part of GUILE.
 ##
@@ -31,6 +31,7 @@ BUILT_SOURCES =
 EXTRA_DIST =
 
 TESTS_ENVIRONMENT =                                            \
+  top_srcdir="$(top_srcdir)"                                   \
   srcdir="$(srcdir)"                                           \
   builddir="$(builddir)"                                       \
   @LOCALCHARSET_TESTS_ENVIRONMENT@                             \
@@ -88,6 +89,10 @@ TESTS += test-command-line-encoding
 check_SCRIPTS += test-command-line-encoding2
 TESTS += test-command-line-encoding2
 
+check_SCRIPTS += test-language
+TESTS += test-language
+EXTRA_DIST += test-language.el test-language.js
+
 # test-num2integral
 test_num2integral_SOURCES = test-num2integral.c
 test_num2integral_CFLAGS = ${test_cflags}
diff --git a/test-suite/standalone/test-language b/test-suite/standalone/test-language
new file mode 100755 (executable)
index 0000000..59ed82b
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+set -e
+
+# Make sure that code passed as `-c' or `-l' is evaluted using the
+# right language.
+
+# The default language in effect until `--language' is encountered is
+# Scheme.
+guile -c "(exit (= 3 (apply + '(1 2))))" --language=elisp
+! guile -c "(= (funcall (symbol-function '+) 1 2) 3)" 2> /dev/null
+
+guile --language=elisp -c "(= (funcall (symbol-function '+) 1 2) 3)"
+guile --language=ecmascript -c '(function (x) { return x * x; })(2);'
+
+# Same with `-l'.
+guile --no-auto-compile -l "$top_srcdir/module/ice-9/q.scm" -c 1
+guile --no-auto-compile                                \
+      -l "$top_srcdir/module/ice-9/q.scm"      \
+      --language=elisp                         \
+      -l "$srcdir/test-language.el"            \
+      --language=ecmascript                    \
+      -l "$srcdir/test-language.js"            \
+      --language=scheme                                \
+      -c 1
diff --git a/test-suite/standalone/test-language.el b/test-suite/standalone/test-language.el
new file mode 100644 (file)
index 0000000..c1f09cc
--- /dev/null
@@ -0,0 +1,11 @@
+;; Sample Elisp code for `test-language'.
+
+(defun fib (n)
+  "Anything but a fib."
+  (if (<= n 1)
+      n
+    (+ (fib (- n 1))
+       (fib (- n 2)))))
+
+(or (= 13 (fib 7))
+    (error "Something's wrong!"))
diff --git a/test-suite/standalone/test-language.js b/test-suite/standalone/test-language.js
new file mode 100644 (file)
index 0000000..c8de366
--- /dev/null
@@ -0,0 +1,12 @@
+/* Sample ECMAscript code for `test-language'.  */
+
+function fib (n)
+{
+    if (n <= 1)
+       return n;
+    else
+       return fib (n - 1) + fib (n - 2);
+}
+
+if (fib (7) != 13)
+    error ("Something's wrong!");