#!/usr/bin/env bash

set -ev

test $DARCS || DARCS=$PWD/../darcs
ACTUAL_DARCS=`which $DARCS`
DARCSPATH=`dirname $ACTUAL_DARCS`
PATH="$DARCSPATH:$PATH"
export PATH

# This test seems to be sensitive to having IFS='' set by the test harness, so
# we set it back and always quote $DARCS instead. Without one or the other
# approach in place, the test could fail if run on a path with a space init.
IFS=' '

rm -rf tmp
mkdir tmp
cd tmp
"$DARCS" init

empty='test ! -s'
nonempty='test -s'

rm -f foo
"$DARCS" add foo >stdout 2>stderr && exit 1 || true
$empty stdout
$nonempty stderr

>foo
"$DARCS" add foo >stdout 2>stderr
$empty stdout
$empty stderr

"$DARCS" add foo >stdout 2>stderr && exit 1 || true
$empty stdout
$nonempty stderr

rm foo
"$DARCS" add foo >stdout 2>stderr && exit 1 || true
$empty stdout
$nonempty stderr

cd ..
rm -rf tmp
