|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -xeu -o pipefail |
| 4 | + |
| 5 | +# shellcheck source=tests/common.sh |
| 6 | +source "$(dirname "$0")/common.sh" |
| 7 | + |
| 8 | +TEST_DIR="test_glob_handling" |
| 9 | + |
| 10 | +# Clean up any previous test |
| 11 | +rm -rf "$TEST_DIR" |
| 12 | +mkdir -p "$TEST_DIR" |
| 13 | +cd "$TEST_DIR" |
| 14 | + |
| 15 | +echo "=== Testing glob pattern expansion ===" |
| 16 | + |
| 17 | +# Create test directory structure with various file types |
| 18 | +mkdir -p patch000/xxx patch000/yyy |
| 19 | +echo "content1" >patch000/1.txt |
| 20 | +echo "content2" >patch000/2.txt |
| 21 | +echo "content3" >patch000/xxx/3.txt |
| 22 | +echo "binary_data" >patch000/data.bin |
| 23 | +echo "another_file" >patch000/test.dat |
| 24 | +echo "nested_file" >patch000/yyy/nested.txt |
| 25 | + |
| 26 | +echo "Directory structure:" |
| 27 | +find . -type f | sort |
| 28 | + |
| 29 | +# Get the Windows binary path for all tests |
| 30 | +WIN_BINARY="$SCRIPT_DIR/../target/x86_64-pc-windows-gnu/release/dat3.exe" |
| 31 | +WINE_DAT3="$(winepath -w "$WIN_BINARY")" |
| 32 | + |
| 33 | +echo "" |
| 34 | +echo "=== Test 1: Basic glob pattern ===" |
| 35 | + |
| 36 | +# Test Linux build |
| 37 | +echo "Testing Linux: dat3 a test1_linux.dat 'patch000/*.txt'" |
| 38 | +"$DAT3" a test1_linux.dat 'patch000/*.txt' |
| 39 | +echo "Linux archive contents:" |
| 40 | +"$DAT3" l test1_linux.dat |
| 41 | + |
| 42 | +# Verify Linux glob expansion |
| 43 | +echo "Verifying Linux glob expansion..." |
| 44 | +if ! "$DAT3" l test1_linux.dat patch000/1.txt >/dev/null 2>&1; then |
| 45 | + echo "ERROR: Linux - patch000/1.txt not found in archive" |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | +if ! "$DAT3" l test1_linux.dat patch000/2.txt >/dev/null 2>&1; then |
| 49 | + echo "ERROR: Linux - patch000/2.txt not found in archive" |
| 50 | + exit 1 |
| 51 | +fi |
| 52 | +# Should NOT contain xxx/3.txt since it's in a subdirectory |
| 53 | +if "$DAT3" l test1_linux.dat patch000/xxx/3.txt >/dev/null 2>&1; then |
| 54 | + echo "ERROR: Linux - patch000/xxx/3.txt should not be in archive (subdirectory)" |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | +echo "Linux basic glob pattern verification passed!" |
| 58 | + |
| 59 | +# Test Windows build |
| 60 | +echo "Testing Windows: wine cmd /c \"$WINE_DAT3 a test1_windows.dat patch000\\*.txt\"" |
| 61 | +wine cmd /c "$WINE_DAT3 a test1_windows.dat patch000\\*.txt" |
| 62 | +echo "Windows archive contents:" |
| 63 | +wine cmd /c "$WINE_DAT3 l test1_windows.dat" |
| 64 | + |
| 65 | +# Verify Windows glob expansion |
| 66 | +echo "Verifying Windows glob expansion..." |
| 67 | +if ! wine cmd /c "$WINE_DAT3 l test1_windows.dat patch000\\1.txt" >/dev/null 2>&1; then |
| 68 | + echo "ERROR: Windows - glob expansion failed" |
| 69 | + exit 1 |
| 70 | +fi |
| 71 | +if ! wine cmd /c "$WINE_DAT3 l test1_windows.dat patch000\\2.txt" >/dev/null 2>&1; then |
| 72 | + printf "ERROR: Windows - patch000\\2.txt not found in archive\n" |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | +echo "Windows basic glob pattern verification passed!" |
| 76 | + |
| 77 | +echo "" |
| 78 | +echo "=== Test 2: Recursive glob pattern ===" |
| 79 | + |
| 80 | +# Test Linux build |
| 81 | +echo "Testing Linux recursive glob: patch000/**/*.txt" |
| 82 | +"$DAT3" a test2_linux.dat 'patch000/**/*.txt' |
| 83 | +echo "Linux recursive glob archive contents:" |
| 84 | +"$DAT3" l test2_linux.dat |
| 85 | + |
| 86 | +# Verify Linux recursive pattern includes subdirectory files |
| 87 | +if ! "$DAT3" l test2_linux.dat patch000/xxx/3.txt >/dev/null 2>&1; then |
| 88 | + echo "ERROR: Linux - Recursive glob should include patch000/xxx/3.txt" |
| 89 | + exit 1 |
| 90 | +fi |
| 91 | +if ! "$DAT3" l test2_linux.dat patch000/yyy/nested.txt >/dev/null 2>&1; then |
| 92 | + echo "ERROR: Linux - Recursive glob should include patch000/yyy/nested.txt" |
| 93 | + exit 1 |
| 94 | +fi |
| 95 | +echo "Linux recursive glob pattern verification passed!" |
| 96 | + |
| 97 | +# Test Windows build |
| 98 | +echo "Testing Windows recursive glob: patch000\\**\\*.txt" |
| 99 | +wine cmd /c "$WINE_DAT3 a test2_windows.dat patch000\\**\\*.txt" |
| 100 | +echo "Windows recursive glob archive contents:" |
| 101 | +wine cmd /c "$WINE_DAT3 l test2_windows.dat" |
| 102 | + |
| 103 | +# Verify Windows recursive pattern |
| 104 | +if ! wine cmd /c "$WINE_DAT3 l test2_windows.dat patch000\\xxx\\3.txt" >/dev/null 2>&1; then |
| 105 | + printf "ERROR: Windows - Recursive glob should include patch000\\xxx\\3.txt\n" |
| 106 | + exit 1 |
| 107 | +fi |
| 108 | +echo "Windows recursive glob pattern verification passed!" |
| 109 | + |
| 110 | +echo "" |
| 111 | +echo "=== Test 3: Character range glob pattern ===" |
| 112 | + |
| 113 | +# Test Linux build |
| 114 | +echo "Testing Linux character range glob: patch000/[12].txt" |
| 115 | +"$DAT3" a test3_linux.dat 'patch000/[12].txt' |
| 116 | +echo "Linux character range glob archive contents:" |
| 117 | +"$DAT3" l test3_linux.dat |
| 118 | + |
| 119 | +# Verify Linux character range pattern |
| 120 | +if ! "$DAT3" l test3_linux.dat patch000/1.txt >/dev/null 2>&1; then |
| 121 | + echo "ERROR: Linux - Character range glob should include patch000/1.txt" |
| 122 | + exit 1 |
| 123 | +fi |
| 124 | +if ! "$DAT3" l test3_linux.dat patch000/2.txt >/dev/null 2>&1; then |
| 125 | + echo "ERROR: Linux - Character range glob should include patch000/2.txt" |
| 126 | + exit 1 |
| 127 | +fi |
| 128 | +echo "Linux character range glob pattern verification passed!" |
| 129 | + |
| 130 | +# Test Windows build |
| 131 | +echo "Testing Windows character range glob: patch000\\[12].txt" |
| 132 | +wine cmd /c "$WINE_DAT3 a test3_windows.dat patch000\\[12].txt" |
| 133 | +echo "Windows character range glob archive contents:" |
| 134 | +wine cmd /c "$WINE_DAT3 l test3_windows.dat" |
| 135 | + |
| 136 | +# Verify Windows character range pattern |
| 137 | +if ! wine cmd /c "$WINE_DAT3 l test3_windows.dat patch000\\1.txt" >/dev/null 2>&1; then |
| 138 | + printf "ERROR: Windows - Character range glob should include patch000\\1.txt\n" |
| 139 | + exit 1 |
| 140 | +fi |
| 141 | +echo "Windows character range glob pattern verification passed!" |
| 142 | + |
| 143 | +echo "" |
| 144 | +echo "=== Test 4: Question mark glob pattern ===" |
| 145 | + |
| 146 | +# Test Linux build |
| 147 | +echo "Testing Linux question mark glob: patch000/?.txt" |
| 148 | +"$DAT3" a test4_linux.dat 'patch000/?.txt' |
| 149 | +echo "Linux question mark glob archive contents:" |
| 150 | +"$DAT3" l test4_linux.dat |
| 151 | + |
| 152 | +# Verify Linux question mark pattern matches single characters |
| 153 | +if ! "$DAT3" l test4_linux.dat patch000/1.txt >/dev/null 2>&1; then |
| 154 | + echo "ERROR: Linux - Question mark glob should include patch000/1.txt" |
| 155 | + exit 1 |
| 156 | +fi |
| 157 | +if ! "$DAT3" l test4_linux.dat patch000/2.txt >/dev/null 2>&1; then |
| 158 | + echo "ERROR: Linux - Question mark glob should include patch000/2.txt" |
| 159 | + exit 1 |
| 160 | +fi |
| 161 | +echo "Linux question mark glob pattern verification passed!" |
| 162 | + |
| 163 | +# Test Windows build |
| 164 | +echo "Testing Windows question mark glob: patch000\\?.txt" |
| 165 | +wine cmd /c "$WINE_DAT3 a test4_windows.dat patch000\\?.txt" |
| 166 | +echo "Windows question mark glob archive contents:" |
| 167 | +wine cmd /c "$WINE_DAT3 l test4_windows.dat" |
| 168 | + |
| 169 | +# Verify Windows question mark pattern |
| 170 | +if ! wine cmd /c "$WINE_DAT3 l test4_windows.dat patch000\\1.txt" >/dev/null 2>&1; then |
| 171 | + printf "ERROR: Windows - Question mark glob should include patch000\\1.txt\n" |
| 172 | + exit 1 |
| 173 | +fi |
| 174 | +echo "Windows question mark glob pattern verification passed!" |
| 175 | + |
| 176 | +echo "" |
| 177 | +echo "=== Test 5: Mixed file type glob patterns ===" |
| 178 | + |
| 179 | +# Test Linux build |
| 180 | +echo "Testing Linux mixed file types: patch000/*.txt patch000/*.dat patch000/*.bin" |
| 181 | +"$DAT3" a test5_linux.dat 'patch000/*.txt' 'patch000/*.dat' 'patch000/*.bin' |
| 182 | +echo "Linux mixed file type glob archive contents:" |
| 183 | +"$DAT3" l test5_linux.dat |
| 184 | + |
| 185 | +# Verify Linux mixed file types |
| 186 | +if ! "$DAT3" l test5_linux.dat patch000/1.txt >/dev/null 2>&1; then |
| 187 | + echo "ERROR: Linux - Mixed types should include patch000/1.txt" |
| 188 | + exit 1 |
| 189 | +fi |
| 190 | +if ! "$DAT3" l test5_linux.dat patch000/2.txt >/dev/null 2>&1; then |
| 191 | + echo "ERROR: Linux - Mixed types should include patch000/2.txt" |
| 192 | + exit 1 |
| 193 | +fi |
| 194 | +if ! "$DAT3" l test5_linux.dat patch000/data.bin >/dev/null 2>&1; then |
| 195 | + echo "ERROR: Linux - Mixed types should include patch000/data.bin" |
| 196 | + exit 1 |
| 197 | +fi |
| 198 | +if ! "$DAT3" l test5_linux.dat patch000/test.dat >/dev/null 2>&1; then |
| 199 | + echo "ERROR: Linux - Mixed types should include patch000/test.dat" |
| 200 | + exit 1 |
| 201 | +fi |
| 202 | +echo "Linux mixed file type glob pattern verification passed!" |
| 203 | + |
| 204 | +# Test Windows build |
| 205 | +echo "Testing Windows mixed file types: patch000\\*.txt patch000\\*.dat patch000\\*.bin" |
| 206 | +wine cmd /c "$WINE_DAT3 a test5_windows.dat patch000\\*.txt patch000\\*.dat patch000\\*.bin" |
| 207 | +echo "Windows mixed file type glob archive contents:" |
| 208 | +wine cmd /c "$WINE_DAT3 l test5_windows.dat" |
| 209 | + |
| 210 | +# Verify Windows mixed file types |
| 211 | +if ! wine cmd /c "$WINE_DAT3 l test5_windows.dat patch000\\1.txt" >/dev/null 2>&1; then |
| 212 | + printf "ERROR: Windows - Mixed types should include patch000\\1.txt\n" |
| 213 | + exit 1 |
| 214 | +fi |
| 215 | +if ! wine cmd /c "$WINE_DAT3 l test5_windows.dat patch000\\2.txt" >/dev/null 2>&1; then |
| 216 | + printf "ERROR: Windows - Mixed types should include patch000\\2.txt\n" |
| 217 | + exit 1 |
| 218 | +fi |
| 219 | +if ! wine cmd /c "$WINE_DAT3 l test5_windows.dat patch000\\data.bin" >/dev/null 2>&1; then |
| 220 | + printf "ERROR: Windows - Mixed types should include patch000\\data.bin\n" |
| 221 | + exit 1 |
| 222 | +fi |
| 223 | +if ! wine cmd /c "$WINE_DAT3 l test5_windows.dat patch000\\test.dat" >/dev/null 2>&1; then |
| 224 | + printf "ERROR: Windows - Mixed types should include patch000\\test.dat\n" |
| 225 | + exit 1 |
| 226 | +fi |
| 227 | +echo "Windows mixed file type glob pattern verification passed!" |
| 228 | + |
| 229 | +echo "" |
| 230 | +echo "All glob tests completed successfully!" |
| 231 | +echo "Both Linux and Windows builds passed all glob pattern tests!" |
0 commit comments