Skip to content

Commit 2f1f445

Browse files
authored
Merge pull request #24 from slangbot/format-5903-aleino/example-tests-experiments
Format code for PR shader-slang#5903
2 parents d9c6d70 + e41b00d commit 2f1f445

File tree

2 files changed

+98
-116
lines changed

2 files changed

+98
-116
lines changed

.github/workflows/ci-examples.sh

+97-115
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ while [[ "$#" -gt 0 ]]; do
4141
exit 0
4242
;;
4343
--dry-run)
44-
dry_run=true
45-
;;
44+
dry_run=true
45+
;;
4646
--bin-dir)
4747
bin_dir="$2"
4848
shift
@@ -53,26 +53,24 @@ while [[ "$#" -gt 0 ]]; do
5353
;;
5454
--os)
5555
case $2 in
56-
windows|linux|macos)
57-
;;
58-
*)
59-
printf "error: Unrecognized os: '$2'\n\n" >&2
60-
show_help >&2
61-
exit 1
62-
;;
56+
windows | linux | macos) ;;
57+
*)
58+
printf "error: Unrecognized os: '$2'\n\n" >&2
59+
show_help >&2
60+
exit 1
61+
;;
6362
esac
6463
os="$2"
6564
shift
6665
;;
6766
--config)
6867
case $2 in
69-
debug|release)
70-
;;
71-
*)
72-
printf "error: Unrecognized config: '$2'\n\n" >&2
73-
show_help >&2
74-
exit 1
75-
;;
68+
debug | release) ;;
69+
*)
70+
printf "error: Unrecognized config: '$2'\n\n" >&2
71+
show_help >&2
72+
exit 1
73+
;;
7674
esac
7775
config="$2"
7876
shift
@@ -86,133 +84,117 @@ while [[ "$#" -gt 0 ]]; do
8684
shift
8785
done
8886

89-
if [[ "$os" == "" ]]
90-
then
91-
echo "error: No OS specified.\n\n"
92-
show_help >&2
93-
exit 1
87+
if [[ "$os" == "" ]]; then
88+
echo "error: No OS specified.\n\n"
89+
show_help >&2
90+
exit 1
9491
fi
9592

96-
if [[ "$config" == "" ]]
97-
then
98-
printf "error: No build configuration specified.\n\n" >&2
99-
show_help >&2
100-
exit 1
93+
if [[ "$config" == "" ]]; then
94+
printf "error: No build configuration specified.\n\n" >&2
95+
show_help >&2
96+
exit 1
10197
fi
10298

103-
if [[ "$bin_dir" == "" ]]
104-
then
105-
printf "error: No binary directory specified.\n\n" >&2
106-
show_help >&2
107-
exit 1
99+
if [[ "$bin_dir" == "" ]]; then
100+
printf "error: No binary directory specified.\n\n" >&2
101+
show_help >&2
102+
exit 1
108103
fi
109104

110-
if [[ "$skip_file" == "" ]]
111-
then
112-
printf "error: No skip file specified.\n\n" >&2
113-
show_help >&2
114-
exit 1
105+
if [[ "$skip_file" == "" ]]; then
106+
printf "error: No skip file specified.\n\n" >&2
107+
show_help >&2
108+
exit 1
115109
fi
116110

117-
if [[ ! -f "$skip_file" ]]
118-
then
119-
printf "error: Skip file '$skip_file' does not exist.\n\n" >&2
111+
if [[ ! -f "$skip_file" ]]; then
112+
printf "error: Skip file '$skip_file' does not exist.\n\n" >&2
120113
fi
121114

122-
if [[ ! -d "$bin_dir" ]]
123-
then
124-
printf "error: Binary directory '$bin_dir' does not exist.\n\n" >&2
115+
if [[ ! -d "$bin_dir" ]]; then
116+
printf "error: Binary directory '$bin_dir' does not exist.\n\n" >&2
125117
fi
126118

127119
summary=""
128120
failure_count=0
129121
skip_count=0
130122
sample_count=0
131123

132-
function skip
133-
{
134-
local p
135-
local line_index
136-
p="$1"
137-
line_index=1
138-
while read pattern
139-
do
140-
pat=$pattern
141-
if [[ ! $pat =~ .*# ]]
142-
then
143-
echo "error: Skip pattern on line $line_index is missing a comment!"
144-
exit 1
145-
fi
146-
pat="${pattern%% *#*}"
147-
if [[ $p =~ ^$pat$ ]]
148-
then
149-
return 0
150-
fi
151-
line_index=$((line_index+1))
152-
done <$skip_file
153-
154-
return 1
155-
}
156-
157-
function run_sample
158-
{
159-
local command
160-
local sample
161-
command=$@
162-
shift
163-
sample="${command%% *}"
164-
sample_count=$((sample_count+1))
165-
summary+="$sample: "
166-
if skip "$os:$config:$sample"
167-
then
168-
echo "Skipping $sample..."
169-
summary+="\n skipped\n"
170-
skip_count=$((skip_count+1))
171-
return
172-
fi
173-
echo "Running '$command'..."
174-
result=0
175-
pushd $bin_dir 1>/dev/null 2>&1
176-
if [[ ! "$dry_run" = true ]]
177-
then
178-
./$command || result=$?
124+
function skip {
125+
local p
126+
local line_index
127+
p="$1"
128+
line_index=1
129+
while read pattern; do
130+
pat=$pattern
131+
if [[ ! $pat =~ .*# ]]; then
132+
echo "error: Skip pattern on line $line_index is missing a comment!"
133+
exit 1
179134
fi
180-
if [[ $result -eq 0 ]]
181-
then
182-
summary+="\n success\n"
183-
else
184-
summary+="\n failure (exit code: $result)\n"
185-
failure_count=$((failure_count+1))
135+
pat="${pattern%% *#*}"
136+
if [[ $p =~ ^$pat$ ]]; then
137+
return 0
186138
fi
187-
popd 1>/dev/null 2>&1
139+
line_index=$((line_index + 1))
140+
done <$skip_file
141+
142+
return 1
143+
}
144+
145+
function run_sample {
146+
local command
147+
local sample
148+
command=$@
149+
shift
150+
sample="${command%% *}"
151+
sample_count=$((sample_count + 1))
152+
summary+="$sample: "
153+
if skip "$os:$config:$sample"; then
154+
echo "Skipping $sample..."
155+
summary+="\n skipped\n"
156+
skip_count=$((skip_count + 1))
157+
return
158+
fi
159+
echo "Running '$command'..."
160+
result=0
161+
pushd $bin_dir 1>/dev/null 2>&1
162+
if [[ ! "$dry_run" = true ]]; then
163+
./$command || result=$?
164+
fi
165+
if [[ $result -eq 0 ]]; then
166+
summary+="\n success\n"
167+
else
168+
summary+="\n failure (exit code: $result)\n"
169+
failure_count=$((failure_count + 1))
170+
fi
171+
popd 1>/dev/null 2>&1
188172
}
189173

190174
sample_commands=(
191-
'platform-test --test-mode'
192-
'ray-tracing-pipeline --test-mode'
193-
'ray-tracing --test-mode'
194-
'shader-toy --test-mode'
195-
'triangle --test-mode'
196-
'model-viewer --test-mode'
197-
'shader-object'
198-
'reflection-api'
199-
'hello-world'
200-
'gpu-printing'
201-
'cpu-hello-world'
202-
'cpu-com-example'
175+
'platform-test --test-mode'
176+
'ray-tracing-pipeline --test-mode'
177+
'ray-tracing --test-mode'
178+
'shader-toy --test-mode'
179+
'triangle --test-mode'
180+
'model-viewer --test-mode'
181+
'shader-object'
182+
'reflection-api'
183+
'hello-world'
184+
'gpu-printing'
185+
'cpu-hello-world'
186+
'cpu-com-example'
203187
)
204188

205-
for sample_command in "${sample_commands[@]}"
206-
do
207-
run_sample $sample_command
208-
echo ""
189+
for sample_command in "${sample_commands[@]}"; do
190+
run_sample $sample_command
191+
echo ""
209192
done
210193

211194
echo ""
212195
echo "Summary: "
213196
printf "\n$summary\n\n"
214197
echo "$failure_count failed, and $skip_count skipped, out of $sample_count tests"
215-
if [[ $failure_count -ne 0 ]]
216-
then
217-
exit 1
198+
if [[ $failure_count -ne 0 ]]; then
199+
exit 1
218200
fi

examples/shader-toy/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ struct ShaderToyApp : public WindowedAppBase
394394

395395
// We may not have a swapchain if we're running in test mode
396396
SLANG_ASSERT(isTestMode() || gSwapchain);
397-
if (gSwapchain)
397+
if (gSwapchain)
398398
gSwapchain->present();
399399
}
400400

0 commit comments

Comments
 (0)