summarylogtreecommitdiffstats
path: root/test.sh
blob: 83e1e33d24f5da4248b9d10cd8e0fa1df7df87cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash

java_=$(source PKGBUILD && echo $java_)

if ! tmpdir=$(mktemp --directory --tmpdir graalvm-test.XXXX); then
    exit
fi
cd -- "$tmpdir" || exit
function cleanup {
    cd / || exit
    rm -rf -- "$tmpdir"
}
trap cleanup EXIT
PATH=/usr/lib/jvm/java-${java_}-graalvm/bin/:$(systemd-path search-binaries-default)

printf '%s\n' 'Testing polyglot R, JavaScript, Python, Ruby, and Java...'

cat > test.R << 'EOF'
jsPlus = eval.polyglot('js', '(function(s1, s2) { return s1 + s2; })')
pythonPlus = eval.polyglot('python', 'lambda s1, s2: s1 + s2')
rubyOne = eval.polyglot('ruby', '1')
pythonOne = eval.polyglot('python', '1')
rOne = 1
jvmPrint = java.type("java.lang.System")$out$println
jvmPrint(pythonPlus(jsPlus(rubyOne, pythonOne), rOne))
EOF

rThree=$(Rscript --polyglot --jvm test.R) || exit
if [[ $rThree != 3 ]]; then
    printf 'expected 3, got %q\n' "$rThree"
    exit 1
fi

printf '%s\n' 'Testing native image...'

cat > Test.java << 'EOF'
public class Test {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}
EOF
javac Test.java || exit
native-image Test > /dev/null || exit

helloWorld=$(./test) || exit
if [[ $helloWorld != 'Hello, world!' ]]; then
    printf 'expected "Hello, world!", got %q\n' "$helloWorld"
    exit 1
fi

printf '%s\n' 'Testing GraalWASM...'

PATH=$PATH:/usr/lib/emscripten

cat > hello.c << 'EOF'
#include <stdio.h>

int main() {
  printf("Hello, WASM!\n");
  return 0;
}
EOF
emcc -o hello.wasm hello.c || exit

helloWorld=$(wasm --Builtins=wasi_snapshot_preview1 hello.wasm) || exit
if [[ $helloWorld != 'Hello, WASM!' ]]; then
    printf 'expected "Hello, WASM!", got %q\n' "$helloWorld"
    exit 1
fi

printf '%s\n' 'Done.'