@@ -9,13 +9,43 @@ usage() {
9
9
exit 1
10
10
}
11
11
12
+ # ###############
13
+ # Check file existence and compare its state against the version in git
12
14
check_file () {
13
15
file=" $1 "
16
+ description=" $2 "
17
+
18
+ if [[ ! -f " $file " ]]; then
19
+ echo " The $description does not exist:"
20
+ echo " $file "
21
+ failure=1
22
+ return
23
+ fi
24
+
14
25
# Check if the file is tracked by git
15
26
git ls-files --error-unmatch " $file " > /dev/null 2>&1
16
27
untracked=$?
17
- # Compare the content with the refernece value
18
- diff_output=$( git diff --ignore-cr-at-eol -- " $file " )
28
+
29
+ if [[ $untracked -eq 1 ]]; then
30
+ echo " The $description is not tracked by git:"
31
+ echo " $file "
32
+ # Add the file to the index to be able to diff it...
33
+ git add " $file "
34
+ # ... print the diff ...
35
+ git --no-pager diff HEAD -- " $file "
36
+ # ... and remove the file from the diff
37
+ git rm --cached -- " $file " > /dev/null 2>&1
38
+
39
+ failure=1
40
+ else
41
+ # Compare the content with the refernece value checked in git
42
+ diff_output=$( git diff --ignore-cr-at-eol -- " $file " )
43
+ if [[ -n " $diff_output " ]]; then
44
+ echo " Non-matching $description :"
45
+ printf " \n$diff_output \n\n"
46
+ failure=1
47
+ fi
48
+ fi
19
49
}
20
50
21
51
optstring=" c:t:"
@@ -127,11 +157,11 @@ for test_file in $tests; do
127
157
test_bin=" test.exe"
128
158
129
159
# Choose mode - default to mixed code
130
- descr=" mixed cpp1 and cpp2 code"
160
+ descr=" mixed Cpp1 and Cpp2 code"
131
161
opt=" "
132
- # Using naming convention to discriminate pure cpp2 code
162
+ # Using naming convention to discriminate pure Cpp2 code
133
163
if [[ $test_name == " pure2" * ]]; then
134
- descr=" pure cpp2 code"
164
+ descr=" pure Cpp2 code"
135
165
opt=" -p"
136
166
fi
137
167
echo " Testing $descr : $test_name .cpp2"
@@ -144,115 +174,63 @@ for test_file in $tests; do
144
174
failure=0
145
175
compiler_issue=0
146
176
# #######
147
- # Check the output
148
- if [ -f " $expeced_output " ]; then
149
- # The C++1 generation output has to be tracked
150
- check_file " $expeced_output "
151
- if [[ $untracked -eq 1 ]]; then
152
- echo " The Cpp1 generation output file is not tracked by git:"
153
- echo " $expeced_output "
154
- failure=1
155
- elif [[ -n " $diff_output " ]]; then
156
- echo " Non-matching std out/err:"
157
- printf " \n$diff_output \n\n"
158
- failure=1
159
- fi
160
- else
161
- echo " Missing expected output file treaded as failure"
162
- failure=1
163
- fi
177
+ # The C++1 generation output has to exist and to be tracked by git
178
+ check_file " $expeced_output " " Cpp1 generation output file"
164
179
165
180
# #######
166
181
# Check the generated code
167
182
if [ -f " $expected_src " ]; then
168
183
# The file was generated, so it should be tracked by git
169
- check_file " $expected_src "
170
- if [[ $untracked -eq 1 ]]; then
171
- echo " The generated file is not tracked by git:"
172
- echo " $expected_src "
173
- failure=1
174
- elif [[ -n " $diff_output " ]]; then
175
- echo " Non-matching generated src:"
176
- printf " \n$diff_output \n\n"
177
- failure=1
178
- else
179
- # #######
180
- # Compile and run the generated code in a sub-shell
181
- expected_src_compil_out=" $exec_out_dir /$generated_cpp_name .output"
182
- expected_src_exec_out=" $exec_out_dir /$generated_cpp_name .execution"
183
- expected_files=" $expected_results_dir /$test_name .files"
184
+ check_file " $expected_src " " generated Cpp1 file"
185
+ # #######
186
+ # Compile and run the generated code in a sub-shell
187
+ expected_src_compil_out=" $exec_out_dir /$generated_cpp_name .output"
188
+ expected_src_exec_out=" $exec_out_dir /$generated_cpp_name .execution"
189
+ expected_files=" $expected_results_dir /$test_name .files"
184
190
185
- echo " Compiling generated code"
186
-
187
- # For some tests the binary needs to be placed in "$exec_out_dir"
188
- # For that reason the compilation is done directly in that dir
189
- # The source is temporarily copied to avoid issues with bash paths in cl.exe
190
- (cd $exec_out_dir ; \
191
- cp ../../$expected_src $generated_cpp_name ;
192
- $compiler_cmd " $test_bin " \
193
- $generated_cpp_name \
194
- > $generated_cpp_name .output 2>&1 )
195
- compilation_result=$?
196
- rm $exec_out_dir /$generated_cpp_name
191
+ echo " Compiling the generated Cpp1 code"
192
+
193
+ # For some tests the binary needs to be placed in "$exec_out_dir"
194
+ # For that reason the compilation is done directly in that dir
195
+ # The source is temporarily copied to avoid issues with bash paths in cl.exe
196
+ (cd $exec_out_dir ; \
197
+ cp ../../$expected_src $generated_cpp_name ;
198
+ $compiler_cmd " $test_bin " \
199
+ $generated_cpp_name \
200
+ > $generated_cpp_name .output 2>&1 )
201
+ compilation_result=$?
202
+ rm $exec_out_dir /$generated_cpp_name
197
203
198
- if [ -f " $expected_src_compil_out " ]; then
199
- # Check for local compiler issues
200
- if [[ $compilation_result -ne 0 ]]; then
201
- # Workaround an issue with MSVC missing std modules
202
- if cat $expected_src_compil_out | grep -q " error C1011" ; then
203
- echo " Skipping further checks due to missing std modules support"
204
- compiler_issue=1
205
- fi
204
+ if [ -f " $expected_src_compil_out " ]; then
205
+ # Check for local compiler issues
206
+ if [[ $compilation_result -ne 0 ]]; then
207
+ # Workaround an issue with MSVC missing std modules
208
+ if cat $expected_src_compil_out | grep -q " error C1011" ; then
209
+ echo " Skipping further checks due to missing std modules support"
210
+ compiler_issue=1
206
211
fi
212
+ fi
213
+ # #######
214
+ # Check the Cpp1 compilation message (if there are no local compiler issues)
215
+ if [[ $compiler_issue -ne 1 ]]; then
216
+ check_file " $expected_src_compil_out " " Cpp1 compilation message file"
217
+ fi
218
+ # Check the result of a successful compilation
219
+ if [[ $compilation_result -eq 0 ]]; then
207
220
# #######
208
- # Check the compilation message (if there are no local compiler issues)
209
- if [[ $compiler_issue -ne 1 ]]; then
210
- check_file " $expected_src_compil_out "
211
- if [[ $untracked -eq 1 ]]; then
212
- echo " The compilation message file is not tracked by git:"
213
- echo " $expected_src_compil_out "
214
- failure=1
215
- elif [[ -n " $diff_output " ]]; then
216
- echo " Non-matching comilation output:"
217
- printf " \n$diff_output \n\n"
218
- failure=1
219
- fi
220
- fi
221
- # Check the result of a successful compilation
222
- if [[ $compilation_result -eq 0 ]]; then
223
- # #######
224
- # Execute the compiled code in $exec_out_dir
225
- echo " Executing the compiled test binary"
226
- # Run the binary in a sub-shell in $exec_out_dir so that files are written there
227
- ( cd " $exec_out_dir " ; ./$test_bin > " $generated_cpp_name .execution" 2>&1 )
221
+ # Execute the compiled code in $exec_out_dir
222
+ echo " Executing the compiled test binary"
223
+ # Run the binary in a sub-shell in $exec_out_dir so that files are written there
224
+ ( cd " $exec_out_dir " ; ./$test_bin > " $generated_cpp_name .execution" 2>&1 )
228
225
229
- check_file " $expected_src_exec_out "
230
- if [[ $untracked -eq 1 ]]; then
231
- echo " Execution output file is not tracked by git:"
232
- echo " $expected_src_exec_out "
233
- failure=1
234
- elif [[ -n " $diff_output " ]]; then
235
- echo " Non-matching execution output:"
236
- printf " \n$diff_output \n\n"
237
- failure=1
238
- fi
239
- # If the test generates files check their content
240
- if [[ -f " $expected_files " ]]; then
241
- echo " Checking written files"
242
- files=" $( cat " $expected_files " ) "
243
- for file in ${files/ ,/ } ; do
244
- check_file " $exec_out_dir /$file "
245
- if [[ $untracked -eq 1 ]]; then
246
- echo " The file generated by the binary is not tracked by git:"
247
- echo " $exec_out_dir /$file "
248
- failure=1
249
- elif [[ -n " $diff_output " ]]; then
250
- echo " Non-matching content of written file:"
251
- printf " \n$diff_output \n\n"
252
- failure=1
253
- fi
254
- done
255
- fi
226
+ check_file " $expected_src_exec_out " " execution output file"
227
+ # If the test generates files check their content
228
+ if [[ -f " $expected_files " ]]; then
229
+ echo " Checking files written by the binary"
230
+ files=" $( cat " $expected_files " ) "
231
+ for file in ${files/ ,/ } ; do
232
+ check_file " $exec_out_dir /$file " " file meant to be written by the binary"
233
+ done
256
234
fi
257
235
fi
258
236
fi
0 commit comments