diff options
author | Lex Spoon <lex@lexspoon.org> | 2006-05-26 12:23:50 +0000 |
---|---|---|
committer | Lex Spoon <lex@lexspoon.org> | 2006-05-26 12:23:50 +0000 |
commit | fa80c56a42832ed9b3b778266fb0da5cd0a4a18a (patch) | |
tree | 26395564ab58ed96d91702651123cc818144b47b /test | |
parent | e3b1cc9130d7046905cc86f0f25e25c1010c5900 (diff) | |
download | scala-fa80c56a42832ed9b3b778266fb0da5cd0a4a18a.tar.gz scala-fa80c56a42832ed9b3b778266fb0da5cd0a4a18a.tar.bz2 scala-fa80c56a42832ed9b3b778266fb0da5cd0a4a18a.zip |
added a test case for scalascript
Diffstat (limited to 'test')
-rw-r--r-- | test/files/script/fact.args | 1 | ||||
-rw-r--r-- | test/files/script/fact.check | 1 | ||||
-rwxr-xr-x | test/files/script/fact.scala | 15 | ||||
-rwxr-xr-x | test/scalatest | 42 |
4 files changed, 49 insertions, 10 deletions
diff --git a/test/files/script/fact.args b/test/files/script/fact.args new file mode 100644 index 0000000000..7813681f5b --- /dev/null +++ b/test/files/script/fact.args @@ -0,0 +1 @@ +5
\ No newline at end of file diff --git a/test/files/script/fact.check b/test/files/script/fact.check new file mode 100644 index 0000000000..22aa60821e --- /dev/null +++ b/test/files/script/fact.check @@ -0,0 +1 @@ +fact(5) = 120 diff --git a/test/files/script/fact.scala b/test/files/script/fact.scala new file mode 100755 index 0000000000..a15c93452c --- /dev/null +++ b/test/files/script/fact.scala @@ -0,0 +1,15 @@ +#!/bin/sh +# fact - A simple Scala script that prints out the factorial of +# the argument specified on the command line. + +exec scalascript "$0" "$@" +!# + + +val x = Integer.parseInt(argv(0)) + +def fact(x: Int):Int = + if(x==0) 1 + else x*fact(x-1) + +Console.println("fact(" + x + ") = " + fact(x)) diff --git a/test/scalatest b/test/scalatest index b578428654..3a372b0fa5 100755 --- a/test/scalatest +++ b/test/scalatest @@ -149,6 +149,7 @@ test_print_help() { echo "--pos next files test a compilation success"; echo "--neg next files test a compilation failure"; echo "--msil next files test the .NET backend"; + echo "--script next files test Scala embedded in scripts"; echo "--quick use the 'quick' build instead of distribution"; echo '--installed use the installed programs on $PATH' echo "--no-run run no test, use results of last run"; @@ -262,6 +263,18 @@ test_run_msil() { rm -f "$dstbase".il; } +# Tests a script with Scala code embedded in it +test_run_script() { + argsfile="$srcbase.args" + if [ ! -r "$argsfile" ] + then + argsfile=/dev/null + fi + chmod +x "$srcbase.scala" 2> /dev/null + PATH="$BIN_DIR:$PATH" "$srcbase.scala" `cat $argsfile` +} + + # Checks the specified test. test_check_test() { [ $# = 1 ] || abort "internal error"; @@ -377,6 +390,8 @@ test_check_all() { "neg" $FILES_NEG; test_check_kind "Testing .NET backend" \ "msil" $FILES_MSIL; + test_check_kind "Testing Scala embedded in script files" \ + "script" $FILES_SCRIPT; } @@ -395,13 +410,14 @@ test_add_file() { esac; TEST_ALL="false"; case "$TEST_TYPE" in - auto ) ;; - run ) FILES_RUN="$FILES_RUN $1"; return;; - jvm ) FILES_JVM="$FILES_JVM $1"; return;; - pos ) FILES_POS="$FILES_POS $1"; return;; - neg ) FILES_NEG="$FILES_NEG $1"; return;; - msil ) FILES_MSIL="$FILES_MSIL $1"; return;; - * ) abort "unknown test type \`$TEST_TYPE'";; + auto ) ;; + run ) FILES_RUN="$FILES_RUN $1"; return;; + jvm ) FILES_JVM="$FILES_JVM $1"; return;; + pos ) FILES_POS="$FILES_POS $1"; return;; + neg ) FILES_NEG="$FILES_NEG $1"; return;; + msil ) FILES_MSIL="$FILES_MSIL $1"; return;; + script ) FILES_SCRIPT="$FILES_SCRIPT $1"; return;; + * ) abort "unknown test type \`$TEST_TYPE'";; esac; case "$1" in run | */run | */run/* | run/* ) FILES_RUN="$FILES_RUN $1";; @@ -409,6 +425,7 @@ test_add_file() { pos | */pos | */pos/* | pos/* ) FILES_POS="$FILES_POS $1";; neg | */neg | */neg/* | neg/* ) FILES_NEG="$FILES_NEG $1";; msil | */msil | */msil/* | msil/* ) FILES_MSIL="$FILES_MSIL $1";; + script | */script | */script/* | script/* ) FILES_SCRIPT="$FILES_SCRIPT $1";; * ) abort "don't known what to do with \`$1'";; esac; } @@ -479,6 +496,7 @@ FILES_JVM=""; FILES_POS=""; FILES_NEG=""; FILES_MSIL=""; +FILES_SCRIPT=""; QUICK="$PREFIX/build/quick/bin" if [ -d "$PREFIX/dists" ]; then @@ -488,7 +506,7 @@ elif [ -d "$PREFIX/build" ]; then elif [ -d "$PREFIX/bin" ]; then LATEST="$PREFIX/bin"; else - abort "Scala binaries not be found"; + abort "Scala binaries could not be found"; fi; BIN_DIR="$LATEST/" # BIN_DIR should have a trailing / when needed, so that # it can also be set to the empty string @@ -509,6 +527,7 @@ while [ $# -gt 0 ]; do --pos ) TEST_TYPE="pos"; shift 1;; --neg ) TEST_TYPE="neg"; shift 1;; --msil ) TEST_TYPE="msil"; shift 1;; + --script ) TEST_TYPE="script"; shift 1;; --quick ) BIN_DIR="$QUICK/"; shift 1;; --installed ) BIN_DIR=""; shift 1;; --no-run ) NORUN="true"; shift 1;; @@ -541,7 +560,7 @@ printf_initialization "${COLOR:-many}"; if [ "$TEST_ALL" = "true" ]; then case "$TEST_TYPE" in - run ) FILES_RUN="$FILES_RUN $SRCDIR/run";; + run ) FILES_RUN="$FILES_RUN $SRCDIR/run";; esac; case "$TEST_TYPE" in auto | jvm ) FILES_JVM="$FILES_JVM $SRCDIR/run $SRCDIR/jvm";; @@ -553,7 +572,10 @@ if [ "$TEST_ALL" = "true" ]; then auto | neg ) FILES_NEG="$FILES_NEG $SRCDIR/neg";; esac; case "$TEST_TYPE" in - msil ) FILES_MSIL="$FILES_MSIL $SRCDIR/run";; + msil ) FILES_MSIL="$FILES_MSIL $SRCDIR/run";; + esac; + case "$TEST_TYPE" in + auto | script ) FILES_SCRIPT="$FILES_SCRIPT $SRCDIR/script";; esac; fi; |