#!/bin/sh

# Basic test to test all the commands in the package: trash-put,
# trash-list, trash-restore, trash-rm and trash-empty.  The test:
#   - trashes a file
#   - checks that it's in the trash
#   - restores it
#   - trashes it again
#   - removes it from the trash
#   - empties the trash

set -e

HOME=$(mktemp --tmpdir -d trashcli_test_home.XXXXXX)
cd $HOME

### Create the file
echo foo > foo
ls foo > /dev/null

### Trash it
trash-put foo
# ls must fail since the file is no longer there
count=$(ls | grep -c foo || true)
[ $count -eq 0 ]

### Check that it made it to the trash
trash-list | grep -q foo

### Restore it
# Note: this only works in clean environments that started with an
# empty trash
echo 0 | trash-restore
ls foo > /dev/null

### Now trash it and remove it from the trash
trash-put foo
trash-rm foo
count=$(ls | grep -c foo || true)
[ $count -eq 0 ]
count=$(trash-list | grep -c foo || true)
[ $count -eq 0 ]

### Create a bunch of files, trash them and empty the trash
# This is currently disabled as I don't have an adt-virt that allows
# the "breaks-testbed" restriction.  If you uncomment it, Add
# "Restrictions: breaks-testbed" to the autopkgtest's control file.
# echo foo > foo
# echo bar > bar
# trash-put foo bar
# count=$(trash-list | wc -l)
# [ $count -eq 2 ]
# trash-empty
# count=$(trash-list | wc -l)
# [ $count -eq 2 ]

### Cleanup
#rm -r $HOME
