#!/bin/csh

set prog = $cwd
set testdir = /tmp
set file = "file"
set dir = "dir"
set r = $prog/run_one_test

while ($#argv > 0)
  switch ($1)
  case "-d":
    shift
    set testdir = $1
    breaksw
  endsw
  shift
end

set testdir = $testdir/sandbox

# Make a sandbox to play in
if (-d $testdir) then
  if (-d $testdir/$dir) then
    chmod -f 777 $testdir/$dir
  endif
  rm -rf $testdir
endif
mkdir $testdir
cd $testdir
echo "testdir = $testdir"

# Create a test file, give owner all permissions
touch $file
setfacl -m u::rwx $file

# Remove permissions one at a time, check that they're really gone

$r $prog write u::rx $file $file
$r $prog read u::x $file $file

# Same, with a directory instead of a file

# Create a test directory, give owner all permissions
mkdir $dir
setfacl -m u::rwx $dir

# Remove permissions one at a time, check that they're really gone

$r $prog creat u::rx $dir $dir/$file
$r $prog listdir u::x $dir $dir
