Skip to content

Commit 9dd42dc

Browse files
committed
make --regen or --fresh required
1 parent 3f1f41f commit 9dd42dc

File tree

1 file changed

+15
-70
lines changed

1 file changed

+15
-70
lines changed

scripts/test_in_metta.sh

Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -170,30 +170,9 @@ process_file() {
170170
DEBUG "==========================================================================="
171171

172172
##########################################################
173-
# Decide (Well try to Guess) which is the hyperon_results (.answers file)
173+
# The hyperon_results (.answers file)
174174
##########################################################
175-
export hyperon_results=(${file}\..*) # gets any other names as well
176-
# List of excluded extensions
177-
# (because now that any file can be an answer file we need to still be able to use test directories for test that
178-
# use things besides metta files such as
179-
# buffer_test.metta.md uses_config_test.metta.mettalogrc )
180-
# We really need a naming convertion for those generate file names that doenst already conflict with the test framework names
181-
# current conflicts are
182-
#
183-
# transpile_test.metta.pl (the prolog version of the transpilation)
184-
# test.metta.html (created on test output for web results . (stored elsewhere most of the time))
185-
# large_file.metta.datalog - Created for test files larger than 20mb
186-
# uses_config_test.metta.mettalogrc currently used for configs
187-
# a_mork_test.metta.xml ( XML translated metta files )
188-
# a_jetta_test.metta.js ( Tests created by Adam )
189-
# test.metta.bak (file backups)
190-
#
191-
# Perhaps Stassa might use a predicatable naming convention that can be filtered
192-
# test_error -> result_test_error
193-
# unknown_error -> result_unknown_error
194-
excluded_extensions=( "tmp" "bak" "html" "~" "sav" "ansi" "pl" "csv"
195-
"py" "txt" "md" "tee" "o" "dll" "so" "exe" "sh" "text" "rc"
196-
"mettalogrc" "bat" "c" "java" "datalog" "in" "out" "xml" "obo" )
175+
export hyperon_results=(${file}\.answers) # gets any other names as well
197176

198177
local base_name="$absfile"
199178
test_local_dir=$(dirname "$base_name")
@@ -217,49 +196,18 @@ process_file() {
217196
esac
218197
done < "$rcfile"
219198
fi
220-
199+
221200
##########################################################
222201
# Decide whether or not to run hyperon test
223202
##########################################################
224203
local take_hyperon_test=false
225-
if [[ "$no_regen" -eq 1 ]]; then
204+
if [[ "$regen_hyperon_results" -eq 0 ]]; then
226205
take_hyperon_test=false
227-
DEBUG_H_E "--no-regen flag is set. Disabling generation of $file.answers"
206+
DEBUG_H_E "--regen flag is not set. Disabling generation of $file.answers"
228207
else
229-
local file_found=false
230-
# Loop over all potential files matching the base pattern
231-
for potential_file in "${base_name}\.".*; do
232-
# Extract the extension of the file
233-
extension="${potential_file##*.}"
234-
exclude_item=false
235-
236-
# Check if the extracted extension is in the excluded list
237-
for excluded in "${excluded_extensions[@]}"; do
238-
if [[ "$extension" == "$excluded" ]]; then
239-
exclude_item=true
240-
break
241-
fi
242-
done
243-
244-
# If the extension is not in the excluded list, use the file
245-
if [ -f "$potential_file" ]; then
246-
if [[ "$exclude_item" == true ]]; then
247-
DEBUG_H_E "Skipped $potential_file"
248-
else
249-
DEBUG_H_E "Found $potential_file"
250-
export hyperon_results=$potential_file
251-
file_found=true
252-
break # break if you only need the first match
253-
fi
254-
fi
255-
if [[ "$file_found" == true ]]; then
256-
break
257-
fi
258-
done
259208

260209
# Check if no file was found
261-
if [[ "$file_found" == false ]]; then
262-
export hyperon_results="${base_name}.answers"
210+
if [[ ! -f "${hyperon_results}" ]]; then
263211
DEBUG_H_E "No alternate answer file extension: defaulting to ${hyperon_results} file."
264212
take_hyperon_test=true
265213
else
@@ -382,11 +330,8 @@ process_file() {
382330

383331
if [ -f "${hyperon_results}" ]; then
384332
if grep -q "Got" "${hyperon_results}"; then
385-
DEBUG_H_E "${RED}Failures in Rust Answers ${hyperon_results} assumed should be ${file}.test_error ${NC}"
386-
if [[ "${hyperon_results}" != "${file}.test_error" ]]; then
387-
cat "${hyperon_results}" > "${file}.test_error"
388-
export hyperon_results="${file}.test_error"
389-
fi
333+
DEBUG_H_E "${RED}Failures in Rust Answers ${hyperon_results}${NC}"
334+
echo ERROR_INFO >> "${hyperon_results}"
390335
fi
391336
echo INFO >> "${hyperon_results}"
392337
fi
@@ -598,7 +543,7 @@ run_tests_auto_reply=""
598543
generate_report_auto_reply=""
599544
METTALOG_OUTPUT="$METTALOG_DIR/reports/tests_output/testrun_$(date +%Y%m%d_%H%M%S)"
600545
fresh=0
601-
no_regen=0
546+
regen_hyperon_results=0
602547
clean=0 # 0 means don't clean, 1 means do clean
603548
if_failures=0
604549
if_regressions=0
@@ -745,7 +690,7 @@ find_test_masks() {
745690
files_with_exclamation+=("$subfile")
746691
fi
747692
fi
748-
done < <(find "$file" -type f -print0)
693+
done < <(find -L "$file" -type f -print0)
749694
fi
750695
fi
751696
done
@@ -762,15 +707,15 @@ function add_test_units_dir() {
762707

763708
#set +v
764709
DEBUG "Finding files with 'test' in their name and apply $EXTRA_FIND_ARGS ..."
765-
mapfile -t test_files < <(find "${BASE_DIR}" $EXTRA_FIND_ARGS -type f -iname "*test*.metta")
710+
mapfile -t test_files < <(find -L "${BASE_DIR}" $EXTRA_FIND_ARGS -type f -iname "*test*.metta")
766711
DEBUG "'Test' files found: ${#test_files[@]}"
767712

768713
DEBUG "Finding files containing 'assert' keyword and apply $MUST_HAVE ..."
769-
mapfile -t assert_files < <(find "${BASE_DIR}" $EXTRA_FIND_ARGS -type f -name '*.metta' -print0 | xargs -0 grep -rl 'assert' -- $GREP_ARGS)
714+
mapfile -t assert_files < <(find -L "${BASE_DIR}" $EXTRA_FIND_ARGS -type f -name '*.metta' -print0 | xargs -0 grep -rl 'assert' -- $GREP_ARGS)
770715
DEBUG "Assert<*> files found: ${#assert_files[@]} "
771716

772717
DEBUG "Finding files containing execution directive (lines starting with '!') and apply $MUST_HAVE ..."
773-
mapfile -t has_tests < <(find "${BASE_DIR}" $EXTRA_FIND_ARGS -type f -name '*.metta' -print0 | xargs -0 grep -rl '^!\([^!]*\)$' -- $GREP_ARGS)
718+
mapfile -t has_tests < <(find -L "${BASE_DIR}" $EXTRA_FIND_ARGS -type f -name '*.metta' -print0 | xargs -0 grep -rl '^!\([^!]*\)$' -- $GREP_ARGS)
774719
DEBUG "Test directive files found: ${#has_tests[@]}"
775720

776721

@@ -923,7 +868,7 @@ show_help() {
923868
echo " -y|--yes Automatically choose 'y' for rerunning all tests"
924869
echo " -n|--no Automatically choose 'n'"
925870
echo " --fresh Clean up by deleting any .answers files under directory"
926-
echo " --no-regen Do not create/recreate .answers files"
871+
echo " --regen Update missing or stale .answers files"
927872
echo " --clean Clean up by deleting all .html files under directory"
928873
echo " --continue The default. Continue running tests (Generating any missing html files)"
929874
echo " --failures Rerun Unsuccessful tests"
@@ -1031,7 +976,7 @@ while [ "$#" -gt 0 ]; do
1031976
--dry-run) dry_run=1 ;;
1032977
--test) dry_run=0 ; add_to_list "$1" passed_along_to_mettalog ;;
1033978
--fresh) fresh=1 ;;
1034-
--no-regen*) no_regen=1 ;;
979+
--regen*) regen_hyperon_results=1 ;;
1035980
--v=*) PYSWIP_VERSION="${1#*=}"; add_to_list "$1" passed_along_to_mettalog ;;
1036981
--exclude=*) EXTRA_FIND_ARGS+=" ! -path ${1#*=}"; CANT_HAVE="${1#*=}" ;;
1037982
--include=*) EXTRA_FIND_ARGS+=" -path ${1#*=}"; MUST_HAVE="${1#*=}" ;;

0 commit comments

Comments
 (0)