diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-03-20 00:48:04 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-03-20 00:55:33 -0700 |
commit | 2429c65cce16a11841212a71ec2bb50373aa54d4 (patch) | |
tree | 97c5f2fff44f80ea1a02d0476b9e31b5d44d1d50 /010vm.cc | |
parent | 3ac523393d15d51b0fd1b042eab4f7cb539f68a9 (diff) | |
download | mu-2429c65cce16a11841212a71ec2bb50373aa54d4.tar.gz |
2799 - new approach to undoing changes in tests
As outlined at the end of 2797. This worked out surprisingly well. Now the snapshotting code touches fewer layers, and it's much better behaved, with less need for special-case logic, particularly inside run_interactive(). 30% slower, but should hopefully not cause any more bugs.
Diffstat (limited to '010vm.cc')
-rw-r--r-- | 010vm.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/010vm.cc b/010vm.cc index 56148f2a..1120280c 100644 --- a/010vm.cc +++ b/010vm.cc @@ -208,6 +208,36 @@ assert(Next_recipe_ordinal < 1000); // recipes being tested didn't overflow int :(before "End Setup") Next_recipe_ordinal = 1000; // consistent new numbers for each test +//: One final detail: tests can modify our global tables of recipes and types, +//: so we need some way to clean up after each test is done so it doesn't +//: influence later ones. +:(before "End Globals") +map<string, recipe_ordinal> Recipe_ordinal_snapshot; +map<recipe_ordinal, recipe> Recipe_snapshot; +map<string, type_ordinal> Type_ordinal_snapshot; +map<type_ordinal, type_info> Type_snapshot; +:(before "End One-time Setup") +save_snapshots(); +:(before "End Setup") +restore_snapshots(); + +:(code) +void save_snapshots() { + Recipe_ordinal_snapshot = Recipe_ordinal; + Recipe_snapshot = Recipe; + Type_ordinal_snapshot = Type_ordinal; + Type_snapshot = Type; + // End save_snapshots +} + +void restore_snapshots() { + Recipe = Recipe_snapshot; + Recipe_ordinal = Recipe_ordinal_snapshot; + Type_ordinal = Type_ordinal_snapshot; + Type = Type_snapshot; + // End restore_snapshots +} + //:: Helpers |