Skip to content

Commit ff53a00

Browse files
authored
Merge pull request #889 from eyal0/explain_regen
test: Explain to the user how to regenerate expected outputs.
2 parents 728ba45 + df319e7 commit ff53a00

3 files changed

Lines changed: 40 additions & 20 deletions

File tree

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pcb2gcode_add_test_executable(
109109
# Integration script tests live in tests/data/CMakeLists.txt (and gerbv_example/).
110110
# They stay registered but are DISABLED unless PCB2GCODE_RUN_INTEGRATION_TESTS is ON
111111
# (see above). CTest labels: integration_expect_success vs integration_expect_failure.
112-
# Regenerate expected/ with tools/run_gerbv_example_test.py --overwrite-expected.
112+
# Regenerate expected/ with tools/run_gerbv_example_test.py --regenerate-expected.
113113
if(NOT PCB2GCODE_RUN_INTEGRATION_TESTS)
114114
set(_geos_display "${PCB2GCODE_GEOS_VERSION}")
115115
if(NOT _geos_display)

tests/data/CMakeLists.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if(PCB2GCODE_RUN_INTEGRATION_TESTS)
77
endif()
88

99
# run_gerbv_example_test.py harness. Ctest label reflects expected pcb2gcode exit code.
10-
# Also registers ${_name}_overwrite_expected. Build target integration_overwrite_all_expected
10+
# Also registers ${_name}_regenerate_expected. Build target integration_regenerate_all_expected
1111
# depends on every such target (one command refreshes all).
1212
function(pcb2gcode_add_integration_script_test _name _input_dir_relpath)
1313
cmake_parse_arguments(
@@ -42,22 +42,22 @@ function(pcb2gcode_add_integration_script_test _name _input_dir_relpath)
4242
set_tests_properties(
4343
"${_name}"
4444
PROPERTIES LABELS "${_integration_label}" DISABLED "${_pcb2gcode_integration_disabled}")
45-
set(_overwrite_cmd ${_base_cmd})
46-
list(APPEND _overwrite_cmd "--overwrite-expected")
47-
list(APPEND _overwrite_cmd ${_extra_args})
45+
set(_regenerate_cmd ${_base_cmd})
46+
list(APPEND _regenerate_cmd "--regenerate-expected")
47+
list(APPEND _regenerate_cmd ${_extra_args})
4848
add_custom_target(
49-
${_name}_overwrite_expected
50-
COMMAND ${_overwrite_cmd}
49+
${_name}_regenerate_expected
50+
COMMAND ${_regenerate_cmd}
5151
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
5252
DEPENDS pcb2gcode
53-
COMMENT "Overwrite expected/ for ${_name}")
53+
COMMENT "Regenerate expected/ for ${_name}")
5454
set_property(
5555
GLOBAL
5656
APPEND
57-
PROPERTY PCB2GCODE_INTEGRATION_OVERWRITE_TARGETS "${_name}_overwrite_expected")
57+
PROPERTY PCB2GCODE_INTEGRATION_REGENERATE_TARGETS "${_name}_regenerate_expected")
5858
endfunction()
5959

60-
set_property(GLOBAL PROPERTY PCB2GCODE_INTEGRATION_OVERWRITE_TARGETS "")
60+
set_property(GLOBAL PROPERTY PCB2GCODE_INTEGRATION_REGENERATE_TARGETS "")
6161
add_subdirectory(gerbv_example)
6262

6363
pcb2gcode_add_integration_script_test(
@@ -160,12 +160,12 @@ pcb2gcode_add_integration_script_test(
160160
PCB2GCODE_ARGS "--zchange-absolute=false")
161161

162162
get_property(
163-
_pcb2gcode_integration_overwrite_targets
163+
_pcb2gcode_integration_regenerate_targets
164164
GLOBAL
165-
PROPERTY PCB2GCODE_INTEGRATION_OVERWRITE_TARGETS)
166-
if(_pcb2gcode_integration_overwrite_targets)
165+
PROPERTY PCB2GCODE_INTEGRATION_REGENERATE_TARGETS)
166+
if(_pcb2gcode_integration_regenerate_targets)
167167
add_custom_target(
168-
integration_overwrite_all_expected
169-
DEPENDS ${_pcb2gcode_integration_overwrite_targets}
168+
integration_regenerate_all_expected
169+
DEPENDS ${_pcb2gcode_integration_regenerate_targets}
170170
COMMENT "Regenerate expected/ for all integration script tests")
171171
endif()

tools/run_gerbv_example_test.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
44
Usage:
55
tools/run_gerbv_example_test.py <input_dir> <pcb2gcode_binary>
6-
[--overwrite-expected] [--expected-exit-code N] [--pcb2gcode-arg ARG ...]
6+
[--regenerate-expected] [--expected-exit-code N] [--pcb2gcode-arg ARG ...]
77
88
By default, pcb2gcode writes to a temporary directory that is removed after the test,
99
and the script compares that output to the existing expected/ tree. If expected/ is
1010
missing, exit code 0 is accepted only when pcb2gcode produces no output files (same
1111
idea as tools/integration_tests.py for --version / --help).
1212
13-
With --overwrite-expected, the script removes expected/ under the input directory
13+
With --regenerate-expected, the script removes expected/ under the input directory
1414
(if present), runs pcb2gcode with --output-dir set to that path, runs fix-up on the
1515
new tree, and skips comparison (use this to refresh golden files).
1616
@@ -32,6 +32,7 @@
3232
import filecmp
3333
import os
3434
import re
35+
import shlex
3536
import shutil
3637
import subprocess
3738
import sys
@@ -74,6 +75,19 @@ def _directory_tree_has_files(path):
7475
return False
7576

7677

78+
def _print_regenerate_command_hint(input_dir, binary, pcb2gcode_args):
79+
"""Print a copy-paste shell command (for ctest / CI logs)."""
80+
script = os.path.abspath(sys.argv[0])
81+
argv = [sys.executable, script, input_dir, binary, "--regenerate-expected"]
82+
for a in pcb2gcode_args:
83+
argv.append("--pcb2gcode-arg=" + a)
84+
line = " ".join(shlex.quote(x) for x in argv)
85+
print(
86+
"To regenerate expected/ output, run from the repository root:\n " + line,
87+
file=sys.stderr,
88+
)
89+
90+
7791
def compare_directories(left, right):
7892
"""Return True if both trees exist, have the same relative files, and contents match."""
7993
if not os.path.isdir(left) or not os.path.isdir(right):
@@ -96,13 +110,13 @@ def main():
96110
parser = argparse.ArgumentParser(
97111
description=(
98112
"Run pcb2gcode on one gerbv_example case: compare to expected/, "
99-
"or overwrite expected/ with fresh output (--overwrite-expected)."
113+
"or overwrite expected/ with fresh output (--regenerate-expected)."
100114
)
101115
)
102116
parser.add_argument("input_dir", help="Example directory (contains millproject, expected/, …)")
103117
parser.add_argument("pcb2gcode_binary", help="Path to pcb2gcode executable")
104118
parser.add_argument(
105-
"--overwrite-expected",
119+
"--regenerate-expected",
106120
action="store_true",
107121
help="Remove input_dir/expected/, regenerate it with pcb2gcode, and skip comparison",
108122
)
@@ -185,14 +199,20 @@ def main():
185199
+ effective_out,
186200
file=sys.stderr,
187201
)
202+
_print_regenerate_command_hint(
203+
args.input_dir, args.pcb2gcode_binary, args.pcb2gcode_arg
204+
)
188205
return 1
189206
return 0
190207
if not compare_directories(expected_path, effective_out):
191-
if args.overwrite_expected:
208+
if args.regenerate_expected:
192209
# Delete expected_path and copy effective_out to it.
193210
shutil.rmtree(expected_path, ignore_errors=True)
194211
shutil.copytree(effective_out, expected_path)
195212
return 0
213+
_print_regenerate_command_hint(
214+
args.input_dir, args.pcb2gcode_binary, args.pcb2gcode_arg
215+
)
196216
return 1
197217
return 0
198218
finally:

0 commit comments

Comments
 (0)