#!/bin/sh
# autopkgtest check: Build a groovy command using a Binding.
# (C) 2021 Pierre Gruet.
# Author: Pierre Gruet <pgt@debian.org>

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR

cat <<EOF >Test.java
import ch.grengine.Grengine;
import groovy.lang.Binding;
import java.lang.Object;
import java.lang.String;
import java.util.HashMap;

public class Test {
    public static void main(String[] args) {
        Grengine gren = new Grengine();
        HashMap<String,Object> map = new HashMap<String,Object>();
        map.put("x", 13);
        map.put("y", 28);
        Binding binding = new Binding(map);
        gren.run("println x+y", binding);
    }
}
EOF

javac -cp /usr/share/java/grengine.jar:. Test.java
java -cp /usr/share/java/grengine.jar:. Test | grep -q "^41$"

if [ $? -ne 0 ]; then
  exit 1
fi

