#!/bin/sh
# Smoke test: compile and run a small Scala program with the installed
# scalac/scala (the update-alternatives wrappers in /usr/bin), to confirm
# the shipped 2.12 compiler and standard library work end to end.
set -e

WORK="${AUTOPKGTEST_TMP:-$(mktemp -d)}"
cd "$WORK"

cat > Hello.scala <<'EOF'
object Hello {
  def main(args: Array[String]): Unit = {
    val xs = List(1, 2, 3).map(_ + 1)
    println("Scala says: " + xs.mkString(", "))
  }
}
EOF

scalac Hello.scala
scala Hello > out.txt
cat out.txt
grep -qx "Scala says: 2, 3, 4" out.txt

# The same through the series commands (<cmd>-2.12).
mkdir o212
scalac-2.12 -d o212 Hello.scala
scala-2.12 -cp o212 Hello | grep -qx "Scala says: 2, 3, 4"
scalap-2.12 -cp o212 Hello > /dev/null
echo "smoke test: PASS"
