-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_if_functionality.sh
More file actions
executable file
·94 lines (79 loc) · 2.81 KB
/
test_if_functionality.sh
File metadata and controls
executable file
·94 lines (79 loc) · 2.81 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
#!/bin/bash
# Test script for if/elif/else functionality in Flash shell
# This script tests various conditional constructs
set -e
# Find the flash binary, handling cross-compilation
find_flash_binary() {
# First try the target-specific path (for cross-compilation)
if [ -n "$CARGO_BUILD_TARGET" ]; then
local target_path="./target/$CARGO_BUILD_TARGET/release/flash"
if [ -f "$target_path" ]; then
echo "$target_path"
return
fi
fi
# Fall back to the default path
local default_path="./target/release/flash"
if [ -f "$default_path" ]; then
echo "$default_path"
return
fi
# Try to find any flash binary in target directories
for dir in ./target/*/release; do
if [ -f "$dir/flash" ]; then
echo "$dir/flash"
return
fi
done
# Last resort: return the default path
echo "$default_path"
}
FLASH_BINARY=$(find_flash_binary)
if [ ! -f "$FLASH_BINARY" ]; then
echo "Error: Flash binary not found at $FLASH_BINARY"
echo "Available binaries:"
find ./target -name "flash" -type f 2>/dev/null || echo "No flash binaries found"
exit 1
fi
echo "Testing if/elif/else functionality with binary: $FLASH_BINARY"
# Test 1: Simple if statement
echo "Test 1: Simple if statement"
result=$($FLASH_BINARY -c 'if [ "hello" = "hello" ]; then echo "success"; fi')
if [ "$result" != "success" ]; then
echo "FAIL: Simple if statement failed"
exit 1
fi
echo "PASS: Simple if statement"
# Test 2: If-else statement
echo "Test 2: If-else statement"
result=$($FLASH_BINARY -c 'if [ "hello" = "world" ]; then echo "fail"; else echo "success"; fi')
if [ "$result" != "success" ]; then
echo "FAIL: If-else statement failed"
exit 1
fi
echo "PASS: If-else statement"
# Test 3: If-elif-else statement
echo "Test 3: If-elif-else statement"
result=$($FLASH_BINARY -c 'if [ "1" = "2" ]; then echo "fail1"; elif [ "2" = "2" ]; then echo "success"; else echo "fail2"; fi')
if [ "$result" != "success" ]; then
echo "FAIL: If-elif-else statement failed"
exit 1
fi
echo "PASS: If-elif-else statement"
# Test 4: Multiple elif branches
echo "Test 4: Multiple elif branches"
result=$($FLASH_BINARY -c 'if [ "1" = "2" ]; then echo "fail1"; elif [ "2" = "3" ]; then echo "fail2"; elif [ "3" = "3" ]; then echo "success"; else echo "fail3"; fi')
if [ "$result" != "success" ]; then
echo "FAIL: Multiple elif branches failed"
exit 1
fi
echo "PASS: Multiple elif branches"
# Test 5: Nested if statements
echo "Test 5: Nested if statements"
result=$($FLASH_BINARY -c 'if [ "1" = "1" ]; then if [ "2" = "2" ]; then echo "success"; fi; fi')
if [ "$result" != "success" ]; then
echo "FAIL: Nested if statements failed"
exit 1
fi
echo "PASS: Nested if statements"
echo "All if/elif/else tests passed!"