on master help sign in
add prybar-scala (#43)

* install scala 2.13.1 in prybar docker image * start scala repl without args * handle c, e, ps1, q flags * rm commented code * make sure we can at least quit the scala repl * scala 1_plus_1 * scala eval, load file, printing, and ps1 tests * bump timeout to 15 seconds to allow for scala to evaluate first expression

commitac0c2223e416e898286341570d6d2152bfc59b82 authorDan Stowell <danstowell@fastmail.com> dateWed 26 Feb 2020, 12:54 (7 years ago) parentf4b6f6b
10 files changed+140−1
languages/scala/main.go+45 run_tests+1−1 scripts/docker-install.sh+6 test_files/sumofsquares.scala+5 tests/scala/1_plus_1.exp+14 tests/scala/eval_code.exp+6 tests/scala/loadfile.exp+17 tests/scala/printing.exp+17 tests/scala/quit.exp+8 tests/scala/set_ps1.exp+21
languages/scala/main.gonew file+45
@@ -0,0 +1,45 @@
1+package main
2+
3+import (
4+ "fmt"
5+ "os"
6+ "os/exec"
7+ "syscall"
8+ "github.com/replit/prybar/utils"
9+)
10+
11+
12+func Execute(config *utils.Config) {
13+ path, err := exec.LookPath("scala")
14+
15+ if err != nil {
16+ panic(err)
17+ }
18+
19+ env := os.Environ()
20+ args := []string{"scala"}
21+
22+ if config.Quiet {
23+ args = append(args, "-Dscala.shell.welcome=")
24+ }
25+
26+ if config.Code != "" {
27+ args = append(args, "-e", config.Code)
28+ }
29+
30+ if config.Exp != "" {
31+ printStatement := fmt.Sprintf("print(%s)", config.Exp)
32+ args = append(args, "-e", printStatement)
33+ }
34+
35+ if config.Ps1 != "" {
36+ args = append(args, "-Dscala.shell.prompt=%n" + config.Ps1)
37+ }
38+
39+ if config.Args != nil && len(config.Args) > 0 {
40+ args = append(args, "-i")
41+ args = append(args, config.Args...)
42+ }
43+
44+ syscall.Exec(path, args, env)
45+}
run_tests+1−1
@@ -15,7 +15,7 @@ for t in ${tests}; do
1515
1616 echo -n "... $name"
1717
18− test_out=$(timeout 10 "./tests/$t" 2>&1)
18+ test_out=$(timeout 15 "./tests/$t" 2>&1)
1919 if [[ $? != 0 ]]; then
2020 echo -e "\n========== \"$t\" failed =========="
2121 echo $test_out
scripts/docker-install.sh+6
@@ -72,6 +72,12 @@ wget -nv https://launchpadlibrarian.net/309343864/libmozjs185-dev_1.8.5-1.0.0+df
7272dpkg -i *.deb
7373rm *.deb
7474
75+wget -nv https://downloads.lightbend.com/scala/2.13.1/scala-2.13.1.tgz
76+tar -xf *.tgz
77+cp -R scala-*/bin/* /usr/local/bin/
78+cp -R scala-*/lib/* /usr/local/lib/
79+rm -rf scala-*
80+
7581# prybar-elisp has support for automatically running inside a Cask
7682# environment if there is a Cask file in the working directory. Might
7783# as well install Cask so it's easy to test.
test_files/sumofsquares.scalanew file+5
@@ -0,0 +1,5 @@
1+def sumOfSquares(x: Int, y: Int): Int = {
2+ val x2 = x * x
3+ val y2 = y * y
4+ x2 + y2
5+}
tests/scala/1_plus_1.expnew file+14
@@ -0,0 +1,14 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-scala -i -q
5+match_max 100000
6+expect -exact "\[35m\r
7+--> \[0m"
8+send -- "1 + 1\r"
9+expect -exact "1 + 1\r
10+res0: Int = 2\r
11+\[35m\r
12+--> \[0m"
13+send -- ":quit\r"
14+expect eof
tests/scala/eval_code.expnew file+6
@@ -0,0 +1,6 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-scala -e 1+1
5+match_max 100000
6+expect eof
tests/scala/loadfile.expnew file+17
@@ -0,0 +1,17 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-scala -i test_files/sumofsquares.scala
5+match_max 100000
6+expect -exact "Welcome to Scala 2.13.1 (OpenJDK 64-Bit Server VM, Java 11.0.5).\r
7+Type in expressions for evaluation. Or try :help.\r
8+\[35m\r
9+--> \[0m"
10+send -- "print(sumOfSquares(,"
11+expect -exact "\[K"
12+send -- "3, 4))\r"
13+expect -exact "3, 4))\r
14+25\[35m\r
15+--> \[0m"
16+send -- ":quit\r"
17+expect eof
tests/scala/printing.expnew file+17
@@ -0,0 +1,17 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-scala -i -q
5+match_max 100000
6+expect -exact "\[35m\r
7+--> \[0m"
8+send -- "print(\"hello\")\r"
9+expect -exact "print(\"hello\")\r
10+hello\[35m\r
11+--> \[0m"
12+send -- "print(1 + 1)\r"
13+expect -exact "print(1 + 1)\r
14+2\[35m\r
15+--> \[0m"
16+send -- ":quit\r"
17+expect eof
tests/scala/quit.expnew file+8
@@ -0,0 +1,8 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-scala -i -q
5+match_max 100000
6+expect -exact "--> "
7+send -- ":quit\r"
8+expect eof
tests/scala/set_ps1.expnew file+21
@@ -0,0 +1,21 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-scala -ps1 {sc> }
5+match_max 100000
6+expect -exact "Welcome to Scala 2.13.1 (OpenJDK 64-Bit Server VM, Java 11.0.5).\r
7+Type in expressions for evaluation. Or try :help.\r
8+\[35m\r
9+sc> \[0m"
10+send -- "print(\"hit"
11+expect -exact "\[K"
12+send -- ""
13+expect -exact "\[K"
14+send -- ""
15+expect -exact "\[K"
16+send -- "prompt\")\r"
17+expect -exact "prompt\")\r
18+prompt\[35m\r
19+sc> \[0m"
20+send -- ":quit\r"
21+expect eof