Skip to content

Commit bffc6e4

Browse files
andy5995claude
andcommitted
test: rewrite test_media_root.sh to use /tmp instead of hardcoded paths
The old test only ran on Andy's workstation (hardcoded /mnt/918375c2 mount point and /home/andy paths). The new approach: - Compares the device ID of /tmp with $HOME using stat - Skips if they are on the same device (test condition not met) - Otherwise uses /tmp as the simulated removable media root - Creates a temporary rmw config and waste folder under /tmp - Verifies the trashinfo Path is relative per FreeDesktop Trash spec - Cleans up after itself This makes the test portable and runnable on any system where /tmp is on a separate device (e.g. tmpfs on Linux CI runners). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4cd9999 commit bffc6e4

File tree

2 files changed

+59
-49
lines changed

2 files changed

+59
-49
lines changed

test/meson.build

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ test_cases = ['strings_rmw', 'utils', 'restore']
1313

1414
scripts = [
1515
'test_basic.sh',
16+
'test_media_root.sh',
1617
'test_purging.sh',
1718
'test_restore.sh',
1819
]
@@ -52,15 +53,3 @@ foreach s : scripts
5253
)
5354
endforeach
5455

55-
# test_media_root.sh intentionally unsets RMW_FAKE_HOME and operates under the
56-
# real HOME (it skips automatically on machines without the expected mount point).
57-
test(
58-
'test_media_root.sh',
59-
files('test_media_root.sh'),
60-
env: [
61-
'MESON_SOURCE_ROOT=' + meson.project_source_root(),
62-
'RMW_FAKE_HOME=' + RMW_FAKE_HOME,
63-
'MESON_BUILD_ROOT=' + meson.project_build_root(),
64-
],
65-
depends: main_bin,
66-
)

test/test_media_root.sh

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# Path should be relative
44
#
55
#https://specifications.freedesktop.org/trash-spec/1.0/#id-1.6.10.1 The key
6-
#Path contains the original location of the file/directory, as either an
7-
#absolute pathname (starting with the slash character “/”) or a relative
6+
#"Path" contains the original location of the file/directory, as either an
7+
#absolute pathname (starting with the slash character "/") or a relative
88
#pathname (starting with any other character). A relative pathname is to be
99
#from the directory in which the trash directory resides (for example, from
10-
#$XDG_DATA_HOME for the home trash directory); it MUST not include a “..”
11-
#directory, and for files not under that directory, absolute pathnames must
12-
#be used. The system SHOULD support absolute pathnames only in the home trash
10+
#$XDG_DATA_HOME for the "home trash" directory); it MUST not include a ".."
11+
#directory, and for files not "under" that directory, absolute pathnames must
12+
#be used. The system SHOULD support absolute pathnames only in the "home trash"
1313
#directory, not in the directories under $topdir.
1414

1515
set -ve
@@ -20,45 +20,66 @@ else
2020
. "${MESON_SOURCE_ROOT}/test/COMMON"
2121
fi
2222

23-
# This test will only work on Andy's workstation.
24-
# The media root, /home/andy/src is on a different partition than /home/andy
25-
# It's mounted with 'bind' and therefore has a different device id
26-
test ! -d /mnt/918375c2 && exit 0;
23+
# This test needs a file and waste folder on the same device, but a different
24+
# device than $HOME. Check whether /tmp qualifies.
25+
tmp_dev=$(stat -c %d /tmp 2>/dev/null || stat -f %d /tmp 2>/dev/null || echo "")
26+
home_dev=$(stat -c %d "$RMW_FAKE_HOME" 2>/dev/null || stat -f %d "$RMW_FAKE_HOME" 2>/dev/null || echo "")
2727

28-
# This test use Andy's regular config, outside of the test sandbox, so don't
29-
# run it if the epoch test setup is being used. Otherwise all the waste dirs
30-
# will be purged.
31-
test -n "$RMW_TEST_EPOCHALYPSE" && exit 0;
32-
echo "hello"
28+
if [ -z "$tmp_dev" ] || [ "$tmp_dev" = "$home_dev" ]; then
29+
echo "/tmp is on the same device as home, or stat is unavailable; skipping"
30+
exit 0
31+
fi
3332

33+
# /tmp is on a different device — use it as the simulated media root.
34+
TRASH_DIR="/tmp/.Trash-$(id -u)"
35+
TEST_DIR="/tmp/rmw-media-root-test"
3436
test_file="media_root_test"
35-
PREV_RMW_FAKE_HOME=${RMW_FAKE_HOME}
36-
# needs to be unset so rmw will use $HOME instead
37-
unset RMW_FAKE_HOME
38-
mkdir -p "$PREV_RMW_FAKE_HOME"
39-
test_file_path=${PREV_RMW_FAKE_HOME}/$test_file
40-
if test -f "$test_file_path"; then
41-
rm "$test_file_path"
42-
fi
43-
if test -f /home/andy/src/rmw-project/.Trash-1000/files/$test_file; then
44-
rm /home/andy/src/rmw-project/.Trash-1000/files/$test_file
45-
fi
46-
if test -f /home/andy/src/rmw-project/.Trash-1000/info/$test_file.trashinfo; then
47-
rm /home/andy/src/rmw-project/.Trash-1000/info/$test_file.trashinfo
48-
fi
37+
test_file_path="$TEST_DIR/$test_file"
38+
39+
# Clean up any leftovers from a previous run
40+
rm -rf "$TRASH_DIR" "$TEST_DIR"
41+
42+
# Create test config pointing the waste folder to /tmp
43+
mkdir -p "$RMW_FAKE_HOME"
44+
TEST_CONFIG="$RMW_FAKE_HOME/media-root.testrc"
45+
printf 'WASTE = /tmp/.Trash-%s, removable\nexpire_age = 90\n' "$(id -u)" > "$TEST_CONFIG"
46+
47+
# Create waste dir manually (required because it is marked removable)
48+
mkdir -p "$TRASH_DIR/files" "$TRASH_DIR/info"
49+
mkdir -p "$TEST_DIR"
50+
4951
touch "$test_file_path"
50-
"$BIN_DIR"/rmw -c /home/andy/.config/rmwrc "$test_file_path"
52+
"$BIN_DIR"/rmw -c "$TEST_CONFIG" "$test_file_path"
5153

52-
output=$(grep Path /home/andy/src/rmw-project/.Trash-1000/info/$test_file.trashinfo)
54+
test -f "$TRASH_DIR/info/$test_file.trashinfo"
55+
test -f "$TRASH_DIR/files/$test_file"
56+
test ! -f "$test_file_path"
5357

54-
# There should be no leading '/' in the filename.
55-
path_expected=$(echo "${MESON_BUILD_ROOT}" | sed -e "s/\/home\/andy\/src\/rmw-project\///g")
56-
echo "$path_expected"
57-
test "$output" = "Path=${path_expected}/test/rmw-tests-home/test_media_root.sh_dir/media_root_test"
58+
# The Path must be relative (no leading '/') since the waste folder is at
59+
# the topdir of /tmp's partition.
60+
output=$(grep '^Path=' "$TRASH_DIR/info/$test_file.trashinfo")
61+
echo "trashinfo: $output"
62+
case "$output" in
63+
Path=/*)
64+
echo "FAIL: Path is absolute, expected relative"
65+
exit 1
66+
;;
67+
Path=*)
68+
echo "PASS: Path is relative"
69+
;;
70+
*)
71+
echo "FAIL: Path line not found"
72+
exit 1
73+
;;
74+
esac
5875

59-
output=$("$BIN_DIR"/rmw -uvv -c /home/andy/.config/rmwrc | grep media_root_test)
76+
# Restore and verify
77+
"$BIN_DIR"/rmw -uvv -c "$TEST_CONFIG"
78+
test -f "$test_file_path"
79+
test ! -f "$TRASH_DIR/info/$test_file.trashinfo"
6080

61-
test "$output" = "+'/home/andy/src/rmw-project/.Trash-1000/files/media_root_test' -> '${MESON_BUILD_ROOT}/test/rmw-tests-home/test_media_root.sh_dir/media_root_test'
62-
-/home/andy/src/rmw-project/.Trash-1000/info/media_root_test.trashinfo"
81+
# Cleanup
82+
rm -f "$TEST_CONFIG"
83+
rm -rf "$TRASH_DIR" "$TEST_DIR"
6384

6485
exit 0

0 commit comments

Comments
 (0)