-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrun_all_examples.sh
More file actions
executable file
·157 lines (138 loc) · 4.92 KB
/
run_all_examples.sh
File metadata and controls
executable file
·157 lines (138 loc) · 4.92 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
# Script to run all examples and generate .docx files for validation
set -e # Exit on error
echo "🚀 Running all examples to generate .docx files..."
echo ""
# Resolve directories
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
# Change to examples directory
cd "$SCRIPT_DIR"
VALIDATOR_PROJECT="$ROOT_DIR/DocxValidator"
VALIDATE_DOCX=true
if ! command -v dotnet >/dev/null 2>&1; then
echo "⚠️ dotnet CLI not found; skipping Open XML validation"
VALIDATE_DOCX=false
elif [ ! -f "$VALIDATOR_PROJECT/DocxValidator.csproj" ]; then
echo "⚠️ DocxValidator project not found at $VALIDATOR_PROJECT; skipping Open XML validation"
VALIDATE_DOCX=false
else
echo "🔍 Open XML validation enabled via DocxValidator"
fi
EXAMPLES=(
"01_basic"
"02_intermediate"
"04_fields"
"05_styles"
"06_sections"
"07_advanced"
"08_images"
"09_advanced_tables"
"11_multi_section"
)
FAILED=()
PASSED=()
GENERATED_FILES=()
VALIDATED_FILES=()
VALIDATION_FAILED=()
for example in "${EXAMPLES[@]}"; do
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📝 Running $example..."
if cd "$example"; then
# Build
if go build -o ./example_binary 2>&1; then
# Run the example
if ./example_binary 2>&1; then
echo "✅ $example executed successfully"
PASSED+=("$example")
# Find generated .docx files
docx_files=$(find . -name "*.docx" -type f 2>/dev/null || true)
if [ -n "$docx_files" ]; then
while IFS= read -r file; do
relative_file="${example}/${file#./}"
absolute_file="$PWD/${file#./}"
GENERATED_FILES+=("$relative_file")
echo " 📄 Generated: ${file#./}"
if [ "$VALIDATE_DOCX" = true ]; then
echo " 🔍 Validating with DocxValidator..."
if output=$(dotnet run --project "$VALIDATOR_PROJECT" -- "$absolute_file" 2>&1); then
echo " ✅ Open XML validation passed"
VALIDATED_FILES+=("$relative_file")
else
echo " ❌ Open XML validation failed"
VALIDATION_FAILED+=("$relative_file")
echo ""
echo "$output" | sed 's/^/ /'
echo ""
fi
fi
done <<< "$docx_files"
fi
# Clean up binary
rm -f ./example_binary
else
echo "❌ $example execution failed"
FAILED+=("$example")
fi
else
echo "❌ $example build failed"
FAILED+=("$example")
fi
cd ..
else
echo "❌ Could not enter directory $example"
FAILED+=("$example")
fi
echo ""
done
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 SUMMARY"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Passed: ${#PASSED[@]}/${#EXAMPLES[@]}"
echo "❌ Failed: ${#FAILED[@]}/${#EXAMPLES[@]}"
echo "📄 Files generated: ${#GENERATED_FILES[@]}"
if [ "$VALIDATE_DOCX" = true ]; then
echo "🔍 Validations passed: ${#VALIDATED_FILES[@]}"
echo "🚫 Validations failed: ${#VALIDATION_FAILED[@]}"
else
echo "🔍 Open XML validation skipped"
fi
if [ ${#FAILED[@]} -gt 0 ]; then
echo ""
echo "Failed examples:"
for example in "${FAILED[@]}"; do
echo " ❌ $example"
done
fi
if [ ${#GENERATED_FILES[@]} -gt 0 ]; then
echo ""
echo "Generated .docx files:"
for file in "${GENERATED_FILES[@]}"; do
echo " 📄 $file"
done
fi
if [ "$VALIDATE_DOCX" = true ] && [ ${#VALIDATION_FAILED[@]} -gt 0 ]; then
echo ""
echo "Validation failures:"
for file in "${VALIDATION_FAILED[@]}"; do
echo " ❌ $file"
done
fi
echo ""
if [ ${#FAILED[@]} -gt 0 ] || { [ "$VALIDATE_DOCX" = true ] && [ ${#VALIDATION_FAILED[@]} -gt 0 ]; }; then
if [ ${#FAILED[@]} -gt 0 ]; then
echo "❌ Some examples failed"
fi
if [ "$VALIDATE_DOCX" = true ] && [ ${#VALIDATION_FAILED[@]} -gt 0 ]; then
echo "❌ Some .docx files failed Open XML validation"
fi
exit 1
else
echo "✅ All examples executed successfully!"
if [ "$VALIDATE_DOCX" = true ]; then
echo "🎉 All generated .docx files passed Open XML validation"
else
echo "🎉 You can now open the generated .docx files to validate them"
fi
exit 0
fi