Skip to content

Commit

Permalink
tests/run-multitests.py: Show test/truth diff.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmo committed Sep 18, 2020
1 parent 857e2c8 commit 06dda48
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/run-multitests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys, os, time, re, select
import argparse
import subprocess
import tempfile

sys.path.append("../tools")
import pyboard
Expand All @@ -18,6 +19,9 @@
CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3")
MICROPYTHON = os.getenv("MICROPY_MICROPYTHON", "../ports/unix/micropython")

# For diff'ing test output
DIFF = os.getenv("MICROPY_DIFF", "diff -u")

PYTHON_TRUTH = CPYTHON3

INSTANCE_READ_TIMEOUT_S = 10
Expand Down Expand Up @@ -323,6 +327,18 @@ def run_test_on_instances(test_file, num_instances, instances):
return error, skip, output_str


def print_diff(a, b):
a_fd, a_path = tempfile.mkstemp(text=True)
b_fd, b_path = tempfile.mkstemp(text=True)
os.write(a_fd, a.encode())
os.write(b_fd, b.encode())
os.close(a_fd)
os.close(b_fd)
subprocess.run(DIFF.split(" ") + [a_path, b_path])
os.unlink(a_path)
os.unlink(b_path)


def run_tests(test_files, instances_truth, instances_test):
skipped_tests = []
passed_tests = []
Expand Down Expand Up @@ -372,6 +388,8 @@ def run_tests(test_files, instances_truth, instances_test):
print(output_test, end="")
print("### TRUTH ###")
print(output_truth, end="")
print("### DIFF ###")
print_diff(output_test, output_truth)

if cmd_args.show_output:
print()
Expand Down

0 comments on commit 06dda48

Please sign in to comment.