-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.bash
More file actions
executable file
·91 lines (79 loc) · 2.21 KB
/
test.bash
File metadata and controls
executable file
·91 lines (79 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
echo "=== Testing timeout command ==="
echo "Building timeout..."
make
echo "✓ Build successful"
echo "Testing help and version options"
./timeout --help | head -1
./timeout --version
echo "✓ Help and version options work"
echo "Testing normal command execution"
./timeout 1s echo "Hello world"
echo "✓ Normal command execution works"
echo "Testing timeout with sleep"
./timeout 1s sleep 3
exit_code=$?
if [ $exit_code -eq 124 ]; then
echo "✓ Timeout worked (exit: 124)"
else
echo "✗ Timeout failed (exit: $exit_code)"
exit 1
fi
echo "Testing preserve-status option"
./timeout -p 1s echo "test"
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "✓ Preserve-status worked (exit: 0)"
else
echo "✗ Preserve-status failed (exit: $exit_code)"
exit 1
fi
echo "Testing signal option"
./timeout -s TERM 1s sleep 3
exit_code=$?
if [ $exit_code -eq 124 ]; then
echo "✓ Signal option worked (exit: 124)"
else
echo "✗ Signal option failed (exit: $exit_code)"
exit 1
fi
echo "Testing foreground option"
echo "test input" | ./timeout -f 1s cat > /tmp/foreground_test.txt
if [ "$(cat /tmp/foreground_test.txt)" = "test input" ]; then
echo "✓ Foreground option works with input/output"
else
echo "✗ Foreground option failed"
exit 1
fi
# Test that foreground mode still respects timeout
./timeout -f 1s sleep 3
exit_code=$?
if [ $exit_code -eq 124 ]; then
echo "✓ Foreground mode still respects timeout (exit: 124)"
else
echo "✗ Foreground mode timeout failed (exit: $exit_code)"
exit 1
fi
echo "Testing non-existent command"
./timeout 1s nonexistent_command_xyz_abc 2>/dev/null
exit_code=$?
if [ $exit_code -eq 127 ]; then
echo "✓ Non-existent command returns 127"
else
echo "✗ Non-existent command failed (exit: $exit_code, expected 127)"
exit 1
fi
echo "Testing non-executable command"
echo "#!/bin/sh" > test_not_exec
chmod a-x test_not_exec
./timeout 1s ./test_not_exec 2>/dev/null
exit_code=$?
if [ $exit_code -eq 126 ]; then
echo "✓ Non-executable command returns 126"
else
echo "✗ Non-executable command failed (exit: $exit_code, expected 126)"
rm -f test_not_exec
exit 1
fi
rm -f test_not_exec
echo "=== All tests completed ==="