-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
129 lines (112 loc) · 4.44 KB
/
test.sh
File metadata and controls
129 lines (112 loc) · 4.44 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# Test script for li
#
# Copyright (c) 2025 Lotus-OS Core
# Licensed under MIT License
set -e
echo "======================================"
echo "Li Test Suite"
echo "======================================"
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Test counter
TESTS_PASSED=0
TESTS_FAILED=0
# Function to run a test
run_test() {
local test_name="$1"
local test_command="$2"
local expected_exit="$3"
echo -n "Testing: $test_name... "
if eval "$test_command" > /dev/null 2>&1; then
actual_exit=0
else
actual_exit=1
fi
if [ "$actual_exit" == "$expected_exit" ]; then
echo -e "${GREEN}PASSED${NC}"
((TESTS_PASSED++))
else
echo -e "${RED}FAILED${NC}"
echo " Command: $test_command"
echo " Expected exit code: $expected_exit"
echo " Actual exit code: $actual_exit"
((TESTS_FAILED++))
fi
}
# Build li first
echo -e "${YELLOW}Building li...${NC}"
if make -C /workspace/li clean 2>/dev/null; then
if make -C /workspace/li; then
echo -e "${GREEN}Build successful!${NC}\n"
else
echo -e "${RED}Build failed!${NC}\n"
exit 1
fi
fi
# Check if li was built
if [ ! -f "/workspace/li/li" ]; then
echo -e "${RED}Error: li binary not found!${NC}"
exit 1
fi
# Run tests
echo "======================================"
echo "Running Tests"
echo "======================================"
# Basic functionality tests
run_test "Help flag (-h)" "/workspace/li/li -h" "0"
run_test "Help flag (--help)" "/workspace/li/li --help" "0"
run_test "Version flag (-v)" "/workspace/li/li -v" "0"
run_test "Version flag (--version)" "/workspace/li/li --version" "0"
run_test "List current directory" "/workspace/li/li" "0"
run_test "List /tmp" "/workspace/li/li /tmp" "0"
run_test "List with long format" "/workspace/li/li -l /tmp" "0"
run_test "List with all files" "/workspace/li/li -a" "0"
run_test "List with almost all" "/workspace/li/li -A" "0"
run_test "List one per line" "/workspace/li/li -1" "0"
run_test "List in columns" "/workspace/li/li -C" "0"
run_test "List across" "/workspace/li/li -x" "0"
run_test "List with inode" "/workspace/li/li -i /tmp" "0"
run_test "List with human readable" "/workspace/li/li -H /tmp" "0"
run_test "List recursive" "/workspace/li/li -R /etc" "0"
run_test "List tree mode" "/workspace/li/li -k /etc 2>&1 | head -20" "0"
run_test "List zebra mode" "/workspace/li/li -z /tmp" "0"
run_test "List table mode" "/workspace/li/li -n /tmp" "0"
run_test "List two-column mode" "/workspace/li/li -N /tmp" "0"
run_test "List with classify" "/workspace/li/li -F /tmp" "0"
run_test "List with stats" "/workspace/li/li --stats /tmp" "0"
run_test "List with reverse" "/workspace/li/li -r" "0"
run_test "List with sort by size" "/workspace/li/li -S /tmp" "0"
run_test "List with sort by time" "/workspace/li/li -t /tmp" "0"
run_test "List with sort by extension" "/workspace/li/li -X /usr/include | head -20" "0"
run_test "List with dirs first" "/workspace/li/li -d /tmp" "0"
run_test "List with omit owner" "/workspace/li/li -g /tmp" "0"
run_test "List with omit group" "/workspace/li/li -o /tmp" "0"
run_test "List with no icons" "/workspace/li/li --no-icons /tmp" "0"
run_test "List with color always" "/workspace/li/li --color=always /tmp" "0"
run_test "List with color never" "/workspace/li/li --color=never /tmp" "0"
run_test "List with icons always" "/workspace/li/li --icons=always /tmp" "0"
run_test "List with icons never" "/workspace/li/li --icons=never /tmp" "0"
run_test "List with relative time" "/workspace/li/li --time-style=relative /tmp" "0"
run_test "List with full-iso time" "/workspace/li/li --time-style=full-iso /tmp" "0"
run_test "List with long-iso time" "/workspace/li/li --time-style=long-iso /tmp" "0"
run_test "List with iso time" "/workspace/li/li --time-style=iso /tmp" "0"
# Test non-existent directory (should fail)
run_test "Non-existent directory" "/workspace/li/li /nonexistent/path 2>/dev/null" "1"
# Test invalid option (should fail)
run_test "Invalid option" "/workspace/li/li --invalid-option 2>/dev/null" "2"
echo ""
echo "======================================"
echo "Test Results"
echo "======================================"
echo -e "Passed: ${GREEN}$TESTS_PASSED${NC}"
echo -e "Failed: ${RED}$TESTS_FAILED${NC}"
echo "======================================"
if [ $TESTS_FAILED -gt 0 ]; then
exit 1
fi
echo -e "\n${GREEN}All tests passed!${NC}"
exit 0