Skip to content

Commit bc2330e

Browse files
authored
Merge pull request #6 from ivangrynenko/resolve-pr-3
Deploy commit
2 parents 0cf296e + 0c9b282 commit bc2330e

File tree

5 files changed

+228
-66
lines changed

5 files changed

+228
-66
lines changed

.github/workflows/test.yml

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,53 @@ jobs:
5050
run: |
5151
cd .tests
5252
53+
# Track test results
54+
FAILED_TESTS=0
55+
5356
echo "Running test-copy.sh..."
5457
chmod +x test-copy.sh
55-
./test-copy.sh | tee reports/test-copy.log
58+
if ! ./test-copy.sh | tee reports/test-copy.log; then
59+
FAILED_TESTS=$((FAILED_TESTS + 1))
60+
fi
5661
5762
echo "Running test-debug.sh..."
5863
chmod +x test-debug.sh
59-
./test-debug.sh | tee reports/test-debug.log
64+
if ! ./test-debug.sh | tee reports/test-debug.log; then
65+
FAILED_TESTS=$((FAILED_TESTS + 1))
66+
fi
6067
6168
echo "Running test-invalid-option.sh..."
6269
chmod +x test-invalid-option.sh
63-
./test-invalid-option.sh | tee reports/test-invalid-option.log
70+
if ! ./test-invalid-option.sh | tee reports/test-invalid-option.log; then
71+
FAILED_TESTS=$((FAILED_TESTS + 1))
72+
fi
6473
6574
echo "Running test-conflicting-options.sh..."
6675
chmod +x test-conflicting-options.sh
67-
./test-conflicting-options.sh | tee reports/test-conflicting-options.log
76+
if ! ./test-conflicting-options.sh | tee reports/test-conflicting-options.log; then
77+
FAILED_TESTS=$((FAILED_TESTS + 1))
78+
fi
6879
6980
echo "Running test-missing-files.sh..."
7081
chmod +x test-missing-files.sh
71-
./test-missing-files.sh | tee reports/test-missing-files.log
82+
if ! ./test-missing-files.sh | tee reports/test-missing-files.log; then
83+
FAILED_TESTS=$((FAILED_TESTS + 1))
84+
fi
7285
7386
echo "Running run-all-tests.sh..."
7487
chmod +x run-all-tests.sh
75-
./run-all-tests.sh | tee reports/run-all-tests.log
88+
if ! ./run-all-tests.sh | tee reports/run-all-tests.log; then
89+
FAILED_TESTS=$((FAILED_TESTS + 1))
90+
fi
7691
7792
cd ..
7893
94+
# Exit with failure if any tests failed
95+
if [ $FAILED_TESTS -gt 0 ]; then
96+
echo "❌ $FAILED_TESTS test(s) failed!"
97+
exit 1
98+
fi
99+
79100
- name: Generate test summary
80101
if: always()
81102
run: |
@@ -104,6 +125,9 @@ jobs:
104125
105126
cat test-summary.md
106127
128+
# Store test results for later use
129+
echo "TESTS_FAILED=${TESTS_FAILED}" >> $GITHUB_ENV
130+
107131
- name: Upload test logs
108132
if: always()
109133
uses: actions/upload-artifact@v4
@@ -112,4 +136,14 @@ jobs:
112136
path: |
113137
.tests/reports/
114138
test-summary.md
115-
retention-days: 7
139+
retention-days: 7
140+
141+
- name: Check test results
142+
if: always()
143+
run: |
144+
if [ "${TESTS_FAILED:-0}" -gt 0 ]; then
145+
echo "❌ Tests failed! See test-summary.md for details."
146+
exit 1
147+
else
148+
echo "✅ All tests passed!"
149+
fi

.tests/file-maps.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,39 @@ validate_javascript() {
153153
validate_core() {
154154
local test_dir=$1
155155
validate_files "$test_dir" "${CORE_FILES[@]}"
156+
}
157+
158+
# Function to validate JavaScript security files only (without core)
159+
validate_javascript_security_only() {
160+
local test_dir=$1
161+
validate_files "$test_dir" "${JAVASCRIPT_FILES[@]}"
162+
}
163+
164+
# Function to validate ignore files
165+
validate_ignore_files() {
166+
local test_dir=$1
167+
local missing_files=0
168+
local missing_file_list=()
169+
170+
# Check for .cursorignore
171+
if [ ! -f "$test_dir/.cursorignore" ]; then
172+
missing_files=$((missing_files + 1))
173+
missing_file_list+=(".cursorignore")
174+
fi
175+
176+
# Check for .cursorindexingignore
177+
if [ ! -f "$test_dir/.cursorindexingignore" ]; then
178+
missing_files=$((missing_files + 1))
179+
missing_file_list+=(".cursorindexingignore")
180+
fi
181+
182+
if [ $missing_files -gt 0 ]; then
183+
echo "Missing ignore files: $missing_files"
184+
for file in "${missing_file_list[@]}"; do
185+
echo " - $file"
186+
done
187+
return 1
188+
fi
189+
190+
return 0
156191
}

.tests/run-all-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ run_test "Core Rules Installation" "php install.php --core --yes" "validate_core
137137
run_test "JavaScript OWASP Installation" "php install.php --javascript --yes" "validate_javascript"
138138

139139
# Test 6: Tag Filtering - JavaScript Security
140-
run_test "Tag Filtering - JavaScript Security" "php install.php --tags 'language:javascript category:security' --yes" "validate_javascript"
140+
run_test "Tag Filtering - JavaScript Security" "php install.php --tags 'language:javascript category:security' --yes" "validate_javascript_security_only"
141141

142142
# Test 7: Tag Preset - JavaScript OWASP
143-
run_test "Tag Preset - JavaScript OWASP" "php install.php --tag-preset js-owasp --yes" "validate_javascript"
143+
run_test "Tag Preset - JavaScript OWASP" "php install.php --tag-preset js-owasp --yes" "validate_javascript_security_only"
144144

145145
# Test 8: Help Information
146146
run_test "Help Information" "php install.php --help" "" 0

.tests/test-ignore-files-option.sh

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ validate_ignore_files() {
7676
test_ignore_files_option() {
7777
print_message "$BLUE" "\n=== Testing Ignore Files Option ==="
7878

79-
# Test 1: --ignore-files option with core installation
80-
print_message "$BLUE" "Testing: php install.php --core --ignore-files --yes"
79+
# Test 1: --ignore-files=yes option with core installation
80+
print_message "$BLUE" "Testing: php install.php --core --ignore-files=yes --yes"
8181
local test_dir="$TEMP_DIR/test_ignore_files"
8282
rm -rf "$test_dir"
8383
mkdir -p "$test_dir"
@@ -89,12 +89,12 @@ test_ignore_files_option() {
8989
fi
9090

9191
cd "$test_dir"
92-
php install.php --core --ignore-files --yes > output.log 2>&1
92+
php install.php --core --ignore-files=yes --yes > output.log 2>&1
9393
local exit_code=$?
9494
cd "$BASE_DIR"
9595

9696
if [ $exit_code -ne 0 ]; then
97-
print_message "$RED" "✗ Installation with --ignore-files failed with exit code $exit_code"
97+
print_message "$RED" "✗ Installation with --ignore-files=yes failed with exit code $exit_code"
9898
print_message "$YELLOW" "Command output:"
9999
cat "$test_dir/output.log"
100100
return 1
@@ -128,63 +128,63 @@ test_ignore_files_option() {
128128

129129
print_message "$GREEN" "✓ Ignore files have content"
130130

131-
# Test 2: Installation without --ignore-files should not install ignore files
132-
print_message "$BLUE" "Testing: php install.php --core --yes (without --ignore-files)"
131+
# Test 2: Installation with --ignore-files=no should not install ignore files
132+
print_message "$BLUE" "Testing: php install.php --core --ignore-files=no --yes"
133133
local test_dir_no_ignore="$TEMP_DIR/test_no_ignore_files"
134134
rm -rf "$test_dir_no_ignore"
135135
mkdir -p "$test_dir_no_ignore"
136136

137137
get_fresh_installer "$test_dir_no_ignore/install.php"
138138
cd "$test_dir_no_ignore"
139-
php install.php --core --yes > output.log 2>&1
139+
php install.php --core --ignore-files=no --yes > output.log 2>&1
140140
local exit_code_no_ignore=$?
141141
cd "$BASE_DIR"
142142

143143
if [ $exit_code_no_ignore -ne 0 ]; then
144-
print_message "$RED" "✗ Installation without --ignore-files failed with exit code $exit_code_no_ignore"
144+
print_message "$RED" "✗ Installation with --ignore-files=no failed with exit code $exit_code_no_ignore"
145145
return 1
146146
fi
147147

148148
# Validate ignore files were NOT installed
149149
if [ -f "$test_dir_no_ignore/.cursorignore" ]; then
150-
print_message "$RED" "✗ .cursorignore should not be installed without --ignore-files option"
150+
print_message "$RED" "✗ .cursorignore should not be installed with --ignore-files=no option"
151151
return 1
152152
fi
153153

154154
if [ -f "$test_dir_no_ignore/.cursorindexingignore" ]; then
155-
print_message "$RED" "✗ .cursorindexingignore should not be installed without --ignore-files option"
155+
print_message "$RED" "✗ .cursorindexingignore should not be installed with --ignore-files=no option"
156156
return 1
157157
fi
158158

159-
print_message "$GREEN" "✓ Ignore files correctly not installed without --ignore-files option"
159+
print_message "$GREEN" "✓ Ignore files correctly not installed with --ignore-files=no option"
160160

161-
# Test 3: Short option -i
162-
print_message "$BLUE" "Testing: php install.php --core -i -y (short option)"
163-
local test_dir_short="$TEMP_DIR/test_ignore_files_short"
164-
rm -rf "$test_dir_short"
165-
mkdir -p "$test_dir_short"
161+
# Test 3: Default behavior (--ignore-files=yes is default)
162+
print_message "$BLUE" "Testing: php install.php --core --yes (default should install ignore files)"
163+
local test_dir_default="$TEMP_DIR/test_ignore_files_default"
164+
rm -rf "$test_dir_default"
165+
mkdir -p "$test_dir_default"
166166

167-
get_fresh_installer "$test_dir_short/install.php"
168-
cd "$test_dir_short"
169-
php install.php --core -i -y > output.log 2>&1
170-
local exit_code_short=$?
167+
get_fresh_installer "$test_dir_default/install.php"
168+
cd "$test_dir_default"
169+
php install.php --core --yes > output.log 2>&1
170+
local exit_code_default=$?
171171
cd "$BASE_DIR"
172172

173-
if [ $exit_code_short -ne 0 ]; then
174-
print_message "$RED" "✗ Installation with -i failed with exit code $exit_code_short"
173+
if [ $exit_code_default -ne 0 ]; then
174+
print_message "$RED" "✗ Installation with default settings failed with exit code $exit_code_default"
175175
return 1
176176
fi
177177

178-
# Validate ignore files were installed with short option
179-
validation_output_short=$(validate_ignore_files "$test_dir_short" 2>&1)
180-
validation_result_short=$?
178+
# Validate ignore files were installed by default
179+
validation_output_default=$(validate_ignore_files "$test_dir_default" 2>&1)
180+
validation_result_default=$?
181181

182-
if [ $validation_result_short -ne 0 ]; then
183-
print_message "$RED" "✗ Ignore files validation failed for -i option:"
184-
print_message "$YELLOW" "$validation_output_short"
182+
if [ $validation_result_default -ne 0 ]; then
183+
print_message "$RED" "✗ Ignore files should be installed by default:"
184+
print_message "$YELLOW" "$validation_output_default"
185185
return 1
186186
else
187-
print_message "$GREEN" "✓ Ignore files short option (-i) works correctly"
187+
print_message "$GREEN" "✓ Ignore files correctly installed by default"
188188
fi
189189

190190
print_message "$GREEN" "✓ Ignore files option tests passed"

0 commit comments

Comments
 (0)