@@ -126,33 +126,46 @@ $(FASTOBO): | build
126126# FILE UTILITIES
127127# ----------------------------------------
128128
129- # clean old result files from directory (prevents old file inclusion in concat_files)
130- # args = input-directory, command-to-match-test-files
131- define clean_prior_results
132- @TMP_FILES=$$(find $(1 ) | $(2 ) ) ; \
129+ # cleans csv files from a directory, optionally matching pattern(s)
130+ # --> to prevent existing file inclusion in concat_csv
131+ # args = input-directory, pattern(s)-to-match-files (should end with .csv)
132+ define clean_existing_csv
133+ @PATTERN=($(2 ) ) ; \
134+ if [ "$$PATTERN" ]; then \
135+ TMP_FILES=$$(find $(1 ) -name "$(firstword $(2 ) ) " $(patsubst % ,-o -name "% ",$(wordlist 2,$(words $(2 ) ) ,$(2 ) ) ) ) ; \
136+ else \
137+ TMP_FILES=$$(find $(1 ) -name "*.csv" ) ; \
138+ fi ; \
133139 if [ "$$TMP_FILES" ]; then \
134- rm $$TMP_FILES ; \
135- fi ;
140+ rm -f $$TMP_FILES ; \
141+ fi
136142endef
137143
138- # concatenate test results from multiple files into one
139- # args = type ('TEST' will error if output), output-file, input-directory, command-to-match-test-files
140- define concat_files
141- @TMP_FILES=$$(find $(3 ) | $(4 ) ) ; \
144+ # concatenate multiple CSV files into one
145+ # args = file category ('TEST' to error, if output), output-file, input-directory, pattern(s)-to-match-files (should end with .csv)
146+ define concat_csv
147+ @PATTERN=($(4 ) ) ; \
148+ if [ "$$PATTERN" ]; then \
149+ TMP_FILES=$$(find $(3 ) -name "$(firstword $(4 ) ) " $(patsubst % ,-o -name "% ",$(wordlist 2,$(words $(4 ) ) ,$(4 ) ) ) ) ; \
150+ else \
151+ TMP_FILES=$$(find $(3 ) -name "*.csv" ) ; \
152+ fi ; \
142153 if [ "$$TMP_FILES" ]; then \
143154 awk 'BEGIN { OFS = FS = "," } ; { \
144155 if (FNR == 1) { \
145- gsub(/^.*verify- |\.csv/, "", FILENAME) ; \
156+ gsub(/^.*\/ |\.csv/, "", FILENAME) ; \
146157 if (NR != 1) { print "" } ; \
147158 print "$(1 ) : " FILENAME ; print $$0 \
148159 } \
149160 else { print $$0 } \
150161 }' $$TMP_FILES > $(2 ) \
151162 && rm -f $$TMP_FILES ; \
152- if [ "$(1 ) " = "TEST" ] ; then exit 1 ; fi ; \
153- else \
154- touch $(2 ) ; \
155- fi ;
163+ if [ "$(1 ) " = "TEST" ] ; then \
164+ exit 1 ; \
165+ fi ; \
166+ elif [ "$(1 ) " = "TEST" ]; then \
167+ echo "" > $(2 ) ; \
168+ fi
156169endef
157170
158171
@@ -204,13 +217,13 @@ EDIT_V_QUERIES := $(wildcard src/sparql/verify/edit-verify-*.rq src/sparql/verif
204217.PRECIOUS : build/reports/edit-verify.csv
205218verify-edit : build/reports/edit-verify.csv
206219build/reports/edit-verify.csv : $(EDIT ) | check_robot build/reports/temp
207- $(call clean_prior_results ,$(word 2,$|) ,grep -E "/( edit-) ? verify-. * \ . csv$$ " )
220+ $(call clean_existing_csv ,$(word 2,$|) ,edit-verify-* .csv verify- * .csv)
208221 @$(ROBOT ) verify \
209222 --input $< \
210223 --queries $(EDIT_V_QUERIES ) \
211224 --fail-on-violation false \
212225 --output-dir $(word 2,$|)
213- $(call concat_files ,TEST,$@ ,$(word 2,$|) ,grep -E "/( edit-) ? verify-. * \ . csv$$ " )
226+ $(call concat_csv ,TEST,$@ ,$(word 2,$|) ,edit-verify-* .csv verify- * .csv)
214227
215228# Verify of doid-edit.owl that should be run quarterly (not part of release)
216229QUARTER_V_QUERIES := $(wildcard src/sparql/verify/quarter-verify-* .rq)
@@ -219,13 +232,13 @@ QUARTER_V_QUERIES := $(wildcard src/sparql/verify/quarter-verify-*.rq)
219232quarterly_test : build/reports/quarterly_test.csv
220233build/reports/quarterly_test.csv : $(EDIT ) | check_robot build/reports/temp
221234 @echo " Verifying $<..."
222- $(call clean_prior_results ,$(word 2,$|) ,grep -E "/ quarter-verify-. * \ .csv$$" )
235+ $(call clean_existing_csv ,$(word 2,$|) ,quarter-verify-* .csv)
223236 @$(ROBOT ) verify \
224237 --input $< \
225238 --queries $(QUARTER_V_QUERIES ) \
226239 --fail-on-violation false \
227240 --output-dir $(word 2,$|)
228- $(call concat_files ,TEST,$@ ,$(word 2,$|) ,grep -E "/ quarter-verify-. * \ .csv$$" )
241+ $(call concat_csv ,TEST,$@ ,$(word 2,$|) ,quarter-verify-* .csv)
229242
230243
231244# #########################################
0 commit comments