Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: cleanup #397

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: shellcheck

on:
push:
branches: master
paths:
- '**.sh'
- '**/shellcheck.yml'
pull_request:
branches: master
paths:
- '**.sh'
- '**/shellcheck.yml'

jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -x -P $GITHUB_WORKSPACE
13 changes: 7 additions & 6 deletions test/COMMON
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh
# included by tests scripts

create_some_files() {
Expand All @@ -7,18 +8,18 @@ c=1
while [ $c -lt 25 ]
do
touch somefiles/topdir/dir1/dir2/dir3/$c
c=`expr $c + 1`
c=$((c + 1))
done

touch somefiles/read_only_file
chmod ugo-w somefiles/read_only_file
}

cmp_substr () {
if [ -z "$1" -o -z "$2" ]; then
if [ -z "$1" ] || [ -z "$2" ]; then
return 1
fi
[ -z "${1##*$2*}" ]
[ -z "${1##*"$2"*}" ]
return $?
}

Expand All @@ -28,7 +29,7 @@ if test -z "${MESON_BUILD_ROOT}" || test -z "${RMW_FAKE_HOME}"; then
exit 1
fi

RMW_FAKE_HOME=${RMW_FAKE_HOME}/$(basename $0)_dir
RMW_FAKE_HOME="${RMW_FAKE_HOME}"/"$(basename "$0")_dir"
TESTS_DIR="${MESON_SOURCE_ROOT}/test"
CONFIG="${MESON_SOURCE_ROOT}/test/rmw.testrc"
ALT_CONFIG="${MESON_SOURCE_ROOT}/test/rmw.alt.testrc"
Expand All @@ -37,8 +38,8 @@ BIN_DIR="${MESON_BUILD_ROOT}"

export RMW_FAKE_HOME

if [ -e ${RMW_FAKE_HOME} ]; then
rm -rf ${RMW_FAKE_HOME}
if [ -e "${RMW_FAKE_HOME}" ]; then
rm -rf "${RMW_FAKE_HOME}"
fi

RMW_TEST_CMD_STRING="${BIN_DIR}/rmw -c $CONFIG"
Expand Down
12 changes: 12 additions & 0 deletions test/concatenate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

set -e

if [ -z "$BUILD_TEST_ROOT" ]; then
echo "This script requires meson to be run"
exit 1
fi

script="$BUILD_TEST_ROOT"/"$1".sh
cat script-head fragments/"$1".sh > "$script"
chmod +x "$script"
11 changes: 11 additions & 0 deletions test/fragments/01_arg_u.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create_some_files
$RMW_TEST_CMD_STRING ${RMW_FAKE_HOME}/somefiles/*
output=$($RMW_TEST_CMD_STRING -uvv | grep Waste)
echo "OUTPUT:"
echo "---"
echo "$output"
echo "---"
test "$output" = "+'${RMW_FAKE_HOME}/.Waste/files/read_only_file' -> '${RMW_FAKE_HOME}/somefiles/read_only_file'
-${RMW_FAKE_HOME}/.Waste/info/read_only_file.trashinfo
+'${RMW_FAKE_HOME}/.Waste/files/topdir' -> '${RMW_FAKE_HOME}/somefiles/topdir'
-${RMW_FAKE_HOME}/.Waste/info/topdir.trashinfo"
5 changes: 5 additions & 0 deletions test/fragments/fail_restore_files_not_in_waste.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
create_some_files

echo "Try to restore files that aren't in a Waste/files folder"
cmp_substr "$($RMW_TEST_CMD_STRING -z ${RMW_FAKE_HOME}/somefiles/* 2>&1 && exit 1)" \
"not in a Waste directory"
2 changes: 2 additions & 0 deletions test/fragments/mrl_not_exist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cmp_substr "$($RMW_TEST_CMD_STRING -u)" \
"no items in the list"
6 changes: 6 additions & 0 deletions test/fragments/restore_with_wildcard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
create_some_files

$RMW_TEST_CMD_STRING ${RMW_FAKE_HOME}/somefiles/topdir -v
cd $PRIMARY_WASTE_DIR/files
$RMW_TEST_CMD_STRING -z topd*
test -e "${RMW_FAKE_HOME}/somefiles/topdir"
46 changes: 44 additions & 2 deletions test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,50 @@ add_test_setup(
env: 'RMW_FAKE_MEDIA_ROOT=true'
)

newscripts = [
'fail_restore_files_not_in_waste',
'01_arg_u',
'mrl_not_exist',
'restore_with_wildcard'
]

build_test_root = meson.current_build_dir()
RMW_FAKE_HOME = join_paths(build_test_root, 'rmw-tests-home')

cat_prog = find_program('cat')
sh_prog = find_program('sh', required: true)

foreach scriptfoo : newscripts
# run_command(
# 'concatenate.sh',
# scriptfoo,
# env: { 'BUILD_TEST_ROOT': build_test_root },
# check: true
# )

concat_fragments = custom_target(
scriptfoo,
command: [ cat_prog, '@INPUT@' ],
capture: true,
input: ['script-head', 'fragments/@[email protected]'.format(scriptfoo)],
output: scriptfoo + '.sh',
install: false,
build_by_default: true
)

test(
scriptfoo,
sh_prog,
args: join_paths(meson.current_build_dir(), scriptfoo + '.sh'),
env : {
'MESON_SOURCE_ROOT': meson.project_source_root(),
'RMW_FAKE_HOME': RMW_FAKE_HOME,
'MESON_BUILD_ROOT': meson.project_build_root()
},
depends: main_bin
)
endforeach

test_cases = [
'strings_rmw',
'utils_rmw',
Expand All @@ -16,8 +60,6 @@ scripts = [
'test_restore.sh',
]

RMW_FAKE_HOME = join_paths(meson.current_build_dir(), 'rmw-tests-home')

foreach case : test_cases
exe = executable(
'test_' + case,
Expand Down
16 changes: 16 additions & 0 deletions test/script-head
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

set -ve

if [ -e COMMON ]; then
. ./COMMON
else
. "${MESON_SOURCE_ROOT}/test/COMMON"
fi

if [ -e "${RMW_FAKE_HOME}" ]; then
rm -rf "${RMW_FAKE_HOME}"
fi

$RMW_TEST_CMD_STRING
cd "$RMW_FAKE_HOME"
87 changes: 42 additions & 45 deletions test/test_basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,99 +4,97 @@ set -ve
if [ -e COMMON ]; then
. ./COMMON
else
. "${MESON_SOURCE_ROOT}/test/COMMON"
. "${MESON_SOURCE_ROOT}"/test/COMMON
fi

echo "== On first run, directories should get created"
$RMW_TEST_CMD_STRING

echo $SEPARATOR
echo "$SEPARATOR"
echo "List the waste folders..."
echo "rmw should display folders on removable devices that are not mounted"
echo $SEPARATOR
echo "$SEPARATOR"
output="$($RMW_TEST_CMD_STRING -l)"
echo "${output}"
test "${output}" = "/mnt/fs/Trash-$(id -u)
/mnt/sda10000/example_waste
"${MESON_BUILD_ROOT}"/test/rmw-tests-home/test_basic.sh_dir/.Waste
"${MESON_BUILD_ROOT}"/test/rmw-tests-home/test_basic.sh_dir/.local/share/Waste-2
"${MESON_BUILD_ROOT}"/test/rmw-tests-home/test_basic.sh_dir/.local/share/Waste-3"
${MESON_BUILD_ROOT}/test/rmw-tests-home/test_basic.sh_dir/.Waste
${MESON_BUILD_ROOT}/test/rmw-tests-home/test_basic.sh_dir/.local/share/Waste-2
${MESON_BUILD_ROOT}/test/rmw-tests-home/test_basic.sh_dir/.local/share/Waste-3"

echo $SEPARATOR
echo "$SEPARATOR"

# Make some temporary files
mkdir ${RMW_FAKE_HOME}/tmp-files && cd ${RMW_FAKE_HOME}/tmp-files
mkdir "${RMW_FAKE_HOME}"/tmp-files && cd "${RMW_FAKE_HOME}"/tmp-files

echo "\n\n == creating temporary files to be deleted"
printf "\n\n == creating temporary files to be deleted"
for file in 1 2 3; do
touch $file
done
cd ${RMW_FAKE_HOME}/..
cd "${RMW_FAKE_HOME}"/..

echo "\n\n == rmw should be able to operate on multiple files\n"
$RMW_TEST_CMD_STRING --verbose ${RMW_FAKE_HOME}/tmp-files/*
printf "\n\n == rmw should be able to operate on multiple files\n"
$RMW_TEST_CMD_STRING --verbose "${RMW_FAKE_HOME}/tmp-files"/*

test -f "${PRIMARY_WASTE_DIR}/files/1"
test -f "${PRIMARY_WASTE_DIR}/files/2"
test -f "${PRIMARY_WASTE_DIR}/files/3"
test -f "${PRIMARY_WASTE_DIR}/info/1.trashinfo"
test -f "${PRIMARY_WASTE_DIR}/info/2.trashinfo"
test -f "${PRIMARY_WASTE_DIR}/info/3.trashinfo"
for file in 1 2 3; do
test -f "${PRIMARY_WASTE_DIR}"/files/"$file"
test -f "${PRIMARY_WASTE_DIR}"/info/"$file".trashinfo
done

echo $SEPARATOR
echo "$SEPARATOR"
echo "rmw should append a time_string to duplicate files..."
cd ${RMW_FAKE_HOME}/tmp-files
cd "${RMW_FAKE_HOME}"/tmp-files
for file in 1 2 3; do
touch $file
done
$RMW_TEST_CMD_STRING 1 2 3

echo "\n\n == Show contents of the files and info directories"
printf "\n\n == Show contents of the files and info directories"

test -n "$(ls -A $PRIMARY_WASTE_DIR/files)"
test -n "$(ls -A $PRIMARY_WASTE_DIR/info)"
test -n "$(ls -A "$PRIMARY_WASTE_DIR"/files)"
test -n "$(ls -A "$PRIMARY_WASTE_DIR"/info)"

output="$(ls -A $PRIMARY_WASTE_DIR/files | wc -l | sed 's/ //g')"
test "$output" = "6"
output=$(find "$PRIMARY_WASTE_DIR"/files | wc -l)
test "$output" = "7"

echo $SEPARATOR
echo "$SEPARATOR"
echo " == rmw should refuse to move a waste folder or a file that resides within a waste folder"
output="$($RMW_TEST_CMD_STRING $PRIMARY_WASTE_DIR/info)"
output=$($RMW_TEST_CMD_STRING "$PRIMARY_WASTE_DIR"/info)
test "${output}" = " :warning: $PRIMARY_WASTE_DIR/info resides within a waste folder and has been ignored
0 items were removed to the waste folder"

# If the file gets removed (which it shouldn't), then the test that follows it will fail
$RMW_TEST_CMD_STRING $PRIMARY_WASTE_DIR/info/1.trashinfo
$RMW_TEST_CMD_STRING "$PRIMARY_WASTE_DIR"/info/1.trashinfo

echo "\n\n == Display contents of 1.trashinfo "
cat $PRIMARY_WASTE_DIR/info/1.trashinfo
printf "\n\n == Display contents of 1.trashinfo "
cat "$PRIMARY_WASTE_DIR"/info/1.trashinfo

echo $SEPARATOR
echo "$SEPARATOR"
echo " == Test -m option"
output=$($RMW_TEST_CMD_STRING --verbose -m)
cmp_substr "$output" ".Waste/files/1_"
cmp_substr "$output" ".Waste/files/2_"
cmp_substr "$output" ".Waste/files/3_"

echo $SEPARATOR
echo "$SEPARATOR"
echo " == test undo/restore feature"

$RMW_TEST_CMD_STRING --verbose -u
$RMW_TEST_CMD_STRING --verbose -z $PRIMARY_WASTE_DIR/files/1
$RMW_TEST_CMD_STRING --verbose -z $PRIMARY_WASTE_DIR/files/2
$RMW_TEST_CMD_STRING --verbose -z $PRIMARY_WASTE_DIR/files/3
$RMW_TEST_CMD_STRING --verbose -z "$PRIMARY_WASTE_DIR"/files/1
$RMW_TEST_CMD_STRING --verbose -z "$PRIMARY_WASTE_DIR"/files/2
$RMW_TEST_CMD_STRING --verbose -z "$PRIMARY_WASTE_DIR"/files/3

echo "\n\n == test that the files are restored to their previous locations"
printf "\n\n == test that the files are restored to their previous locations"

test -f ${RMW_FAKE_HOME}/tmp-files/1
test -f ${RMW_FAKE_HOME}/tmp-files/2
test -f ${RMW_FAKE_HOME}/tmp-files/3
test -f "${RMW_FAKE_HOME}"/tmp-files/1
test -f "${RMW_FAKE_HOME}"/tmp-files/2
test -f "${RMW_FAKE_HOME}"/tmp-files/3

echo "\n\n == test that the .trashinfo files have been removed"
printf "\n\n == test that the .trashinfo files have been removed"

test ! -f $PRIMARY_WASTE_DIR/info/1.trashinfo
test ! -f $PRIMARY_WASTE_DIR/info/2.trashinfo
test ! -f $PRIMARY_WASTE_DIR/info/3.trashinfo
test ! -f "$PRIMARY_WASTE_DIR"/info/1.trashinfo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need curly braces here?

test ! -f "$PRIMARY_WASTE_DIR"/info/2.trashinfo
test ! -f "$PRIMARY_WASTE_DIR"/info/3.trashinfo

# Ignore dot directories
mkdir tmpdot
Expand All @@ -123,8 +121,7 @@ cmp_substr "$($RMW_ALT_TEST_CMD_STRING -l)" \
cmp_substr "$($RMW_TEST_CMD_STRING '')" \
"skipping"

output=$($RMW_TEST_CMD_STRING ${RMW_FAKE_HOME})
output=$($RMW_TEST_CMD_STRING "${RMW_FAKE_HOME}")
cmp_substr "$output" "Skipping"

echo "Basic tests passed"
exit 0
Loading