Skip to content

Commit

Permalink
Add option to lean test runner to automatically update the expected f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
ineol committed Feb 4, 2025
1 parent ba1ae75 commit ade5679
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion test/lean/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import re
import sys
import hashlib
import argparse

mydir = os.path.dirname(__file__)
os.chdir(mydir)
sys.path.insert(0, os.path.realpath('..'))

from sailtest import *

update_expected = args.update_expected

sail_dir = get_sail_dir()
sail = get_sail()

Expand All @@ -30,7 +33,13 @@ def test_lean():
step('mkdir -p {}'.format(basename))
step('\'{}\' {} --lean --lean-output-dir {}'.format(sail, filename, basename))
step(f'lake --dir {basename}/out build')
step('diff {}/out/Out.lean {}.expected.lean'.format(basename, basename))
status = step_with_status('diff {}/out/Out.lean {}.expected.lean'.format(basename, basename))
if status != 0:
if update_expected:
print(f'Overriding file {basename}.expected.lean')
step(f'cp {basename}/out/Out.lean {basename}.expected.lean')
else:
sys.exit(1)
step('rm -r {}'.format(basename))
print_ok(filename)
sys.exit(0)
Expand Down
7 changes: 6 additions & 1 deletion test/sailtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
parser.add_argument("--hide-error-output", help="Hide error information.", action='store_true')
parser.add_argument("--compact", help="Compact output.", action='store_true')
parser.add_argument("--targets", help="Targets to use (where supported).", action='append')
parser.add_argument("--update-expected", help="Update the expected file (where supported)", action="store_true")
args = parser.parse_args()

def is_compact():
Expand Down Expand Up @@ -113,7 +114,7 @@ def project_chunks(filenames, cores):
ys.append(list(chunk))
return ys

def step(string, expected_status=0):
def step_with_status(string, expected_status=0):
p = subprocess.Popen(string, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
out, err = p.communicate()
status = p.wait()
Expand All @@ -127,6 +128,10 @@ def step(string, expected_status=0):
print(out.decode('utf-8'))
print('{}stderr{}:'.format(color.NOTICE, color.END))
print(err.decode('utf-8'))
return status

def step(string, expected_status=0):
if step_with_status(string) != expected_status:
sys.exit(1)

def banner(string):
Expand Down

0 comments on commit ade5679

Please sign in to comment.