33
44Usage:
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
88By default, pcb2gcode writes to a temporary directory that is removed after the test,
99and the script compares that output to the existing expected/ tree. If expected/ is
1010missing, exit code 0 is accepted only when pcb2gcode produces no output files (same
1111idea 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
1515new tree, and skips comparison (use this to refresh golden files).
1616
3232import filecmp
3333import os
3434import re
35+ import shlex
3536import shutil
3637import subprocess
3738import 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+
7791def 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