on master help sign in
add prybar-scala (#43)
ac0c222Dan Stowell
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
15
15
16 echo -n "... $name"
16 echo -n "... $name"
17
17
18− test_out=$(timeout 10 "./tests/$t" 2>&1)
18+ test_out=$(timeout 15 "./tests/$t" 2>&1)
19 if [[ $? != 0 ]]; then
19 if [[ $? != 0 ]]; then
20 echo -e "\n========== \"$t\" failed =========="
20 echo -e "\n========== \"$t\" failed =========="
21 echo $test_out
21 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
72dpkg -i *.deb
72dpkg -i *.deb
73rm *.deb
73rm *.deb
74
74
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+
75# prybar-elisp has support for automatically running inside a Cask
81# prybar-elisp has support for automatically running inside a Cask
76# environment if there is a Cask file in the working directory. Might
82# environment if there is a Cask file in the working directory. Might
77# as well install Cask so it's easy to test.
83# 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