#!/bin/sh
#
#  Test-opts -- test some Icon command options

#  prepend Icon binary directory to path
PATH=../../bin:$PATH

#  merge stdin and stderr
exec 2>&1

#  remove files if left over from before
test -f olleh    && chmod +rw olleh
test -f hello    && chmod +rw hello
test -f hello.u1 && chmod +rw hello.u1
test -f hello.u2 && chmod +rw hello.u2
rm -f hello hello.u? olleh

#  stop on errors
set -e -x

#  simple compile and execute, with no arguments
icont hello -x
./hello north
rm hello

#  compile and execute with options
icont -u -s -o olleh hello.icn -x south
./olleh east
rm olleh
test ! -f hello
test ! -f hello.u?

#  separate compilation
icont -c -t -s hello
icont -u -s hello.u -x west

#  make sure that these files all exist
#  and that subsequent commands don't touch them
chmod -rwx hello.u? hello

#  icont direct execution
icont -X hello.icn Tucson

#  icon command
icon hello.icn Pima

#  icon command from standard input
icon - <hello.icn Arizona

#  shell magic execution (icont)
chmod +rwx hello
echo '#!../../bin/icont -X' | cat - hello.icn > hello
./hello world

#  shell magic execution (icon)
echo '#!../../bin/icon' | cat - hello.icn > hello
./hello galaxy

#  shell magic execution (/usr/bin/env icon)
echo '#!/usr/bin/env icon' | cat - hello.icn > hello
./hello universe

#  in-line program
icon -P 'procedure main(); write("HOWDY!"); end'

#  final file cleanup
chmod +rw hello.u?
rm hello.u? hello
: done
