Skip to content

Improve test script to log diff #5131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion test/migration-tool-tests/src/test/resources/run-test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import filecmp
import os
import shutil, errno
import argparse
import difflib

RESOURCE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "resources")
BEFORE_DIR = os.path.join(RESOURCE_DIR, "before")
Expand All @@ -29,11 +30,19 @@ def run_test(version):
comparison = filecmp.dircmp(TARGET_DIR, AFTER_DIR)
is_same = compare_directory(filecmp.dircmp(TARGET_DIR, AFTER_DIR))
if not is_same:
comparison.report_full_closure()
raise Exception("The transformed directory('target/generated-test-sources/project') does not match with the expected one('src/test/resources/after')")

def compare_directory(dcmp):
if dcmp.diff_files or dcmp.left_only or dcmp.right_only:
for diff_file in dcmp.diff_files:
file1 = open(dcmp.right + "/" + diff_file, 'r')
file2 = open(dcmp.left + "/" + diff_file, 'r')
diff = difflib.ndiff(file1.readlines(), file2.readlines())
changes = [l for l in diff if l.startswith('+ ') or l.startswith('- ')]
print("Diff found in file: " + diff_file)
for change in changes:
print(change)

return False
for sub_dcmp in dcmp.subdirs.values():
if not compare_directory(sub_dcmp):
Expand Down