Compare old and new code outputs to detect unintended changes.
Project details
twinrun enables developers to run both old and new versions of code on identical inputs, highlighting discrepancies in outputs. This tool effectively reveals unintended changes that traditional diffs overlook, making it invaluable for ensuring behavior preservation during refactoring or feature updates.
Twinrun is a powerful tool designed to help developers identify behavioral changes between the old and new versions of code when changes have been made. Unlike traditional methods which simply highlight the lines that have changed, Twinrun dives deeper to determine what the program actually does differently under identical inputs. This utility is essential in mitigating unintended side effects often introduced during code refactors or modifications.
Behavioral Output Comparison: Twinrun operates by running both the old and new versions of the code on the same set of inputs. It reports discrepancies in outputs, unveiling changes that were not intended by the developer.
Oracle-Based Validation: Employing the old code as the "oracle," Twinrun eliminates the need for explicit specifications or assertions, allowing it to identify deviations in behavior intuitively. If the behavior of code unexpectedly changes, Twinrun will flag the exact call that indicates it.
To utilize Twinrun, simply invoke it from your command line, specifying the base and head revisions:
$ twinrun . --base main --head HEAD
twinrun main..HEAD
DELTA billing/cart.py :: Cart.total +7 more calls
Cart(0).total()
base return int 0
head return float 0.0
DELTA billing/cart.py :: Cart.add +21 more calls
Cart(0).add(1)
base return NoneType None
after self=[('items', [1]), ('rate', 0)]
head return NoneType None
after self=[('items', [2]), ('rate', 0)]
Twinrun keeps track of each call, assessing how many callables were checked and how many discrepancies it discovered.
Twinrun is designed to integrate seamlessly into Continuous Integration workflows. It can be set up to validate code submissions automatically in pull requests and ensures that regressions are caught before merging changes into the main branch, maintaining code quality.
When deliberate changes to the code are made and accepted, Twinrun allows these findings to be recorded, establishing them as expected behavior for future references. This promotes transparency and clarity in the evolution of a codebase.
Twinrun stands out as an essential tool for developers who prioritize maintaining code integrity during modifications. It provides valuable insights into how changes can affect program logic and outputs, significantly reducing the risk of unintentional regressions.
Comments
0Start the conversation
Share the first comment.