#!/bin/sh
# $Id: compare-with-local,v 1.1 2002/01/14 07:49:17 shadow Exp $
#################################################################
#
# Copy file back and forth between $TMPDIR (defaults to /tmp)
# which is hopefully on local disk or any other well tested
# file system and the filesystem we want to test (in $PWD).
#
#################################################################

test $SHELLVERBOSE && set $SHELLVERBOSE

function compare () {
    if cmp $1 $2; then
	:
    else
	diff $1 $2
	exit 1
    fi
}

test $TMPDIR || TMPDIR=/tmp
TMPDIR=$TMPDIR/compare-with-local-$$
mkdir $TMPDIR || exit 1

# Generate test file
cat > $TMPDIR/bar << EOF
This is an arla temporary test file.
You may remove it any time.
Kontrollen blinkar blå.
EOF

cp $TMPDIR/bar bar
compare $TMPDIR/bar bar
mv bar $TMPDIR/bas
compare $TMPDIR/bar $TMPDIR/bas
 # this is for later overwrite test
 test -f bar && echo bar should not exist && exit 1
 cp $TMPDIR/bar bar
 compare $TMPDIR/bar bar
cat $TMPDIR/bas > bat
compare $TMPDIR/bar bat
cat bat > $TMPDIR/bau
compare $TMPDIR/bar $TMPDIR/bau
mv $TMPDIR/bau bav
compare $TMPDIR/bar bav
 # this is for later overwrite test
 test -f $TMPDIR/bau && echo $TMPDIR/bau should not exist && exit 1
 cp $TMPDIR/bar $TMPDIR/bau 
cp bav $TMPDIR/baw
compare $TMPDIR/bar $TMPDIR/baw

# If we get so far we can write new files. 
# Now test overwrite.

# Generate test file slightly different
cat > $TMPDIR/bar << EOF
This is an arla temporary test file.
You may remove it any time.
Mera jul.
EOF

cp $TMPDIR/bar bar
compare $TMPDIR/bar bar
mv bar $TMPDIR/bas
compare $TMPDIR/bar $TMPDIR/bas
cat $TMPDIR/bas > bat
compare $TMPDIR/bar bat
cat bat > $TMPDIR/bau
compare $TMPDIR/bar $TMPDIR/bau
mv $TMPDIR/bau bav
compare $TMPDIR/bar bav
cp bav $TMPDIR/baw
compare $TMPDIR/bar $TMPDIR/baw

${objdir}/rm-rf $TMPDIR
exit 0
