Skip to content

Commit 033d9d0

Browse files
andy5995claude
andcommitted
test: add XDG sandboxing and cleanup trap
Set XDG_DATA_HOME and XDG_CONFIG_HOME in the meson test environment so rmw cannot accidentally read/write the real user's XDG dirs during tests. Add a trap in test_media_root.sh to clean up /tmp dirs on failure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f8c6b3d commit 033d9d0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

test/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ test_env = [
4141
'MESON_SOURCE_ROOT=' + meson.project_source_root(),
4242
'RMW_FAKE_HOME=' + RMW_FAKE_HOME,
4343
'HOME=' + RMW_FAKE_HOME,
44+
'XDG_DATA_HOME=' + RMW_FAKE_HOME + '/.local/share',
45+
'XDG_CONFIG_HOME=' + RMW_FAKE_HOME + '/.config',
4446
'MESON_BUILD_ROOT=' + meson.project_build_root(),
4547
]
4648

test/test_media_root.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ TEST_DIR="/tmp/rmw-media-root-test"
3434
test_file="media_root_test"
3535
test_file_path="$TEST_DIR/$test_file"
3636

37+
cleanup() {
38+
rm -rf "$TRASH_DIR" "$TEST_DIR"
39+
}
40+
trap cleanup EXIT
41+
3742
# Clean up any leftovers from a previous run
3843
rm -rf "$TRASH_DIR" "$TEST_DIR"
3944

@@ -76,8 +81,6 @@ esac
7681
test -f "$test_file_path"
7782
test ! -f "$TRASH_DIR/info/$test_file.trashinfo"
7883

79-
# Cleanup
8084
rm -f "$TEST_CONFIG"
81-
rm -rf "$TRASH_DIR" "$TEST_DIR"
8285

8386
exit 0

0 commit comments

Comments
 (0)