From df28c022e11fe4ee470e445b735207b4468d8e34 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:54:47 -0500 Subject: [PATCH] Use disassembly for snapshot testing --- Cargo.lock | 12 -- bytecode/src/bytecode.rs | 2 +- compiler/Cargo.toml | 2 +- compiler/src/compile.rs | 31 ++++- ...hon_compiler__compile__tests__if_ands.snap | 97 ++------------ ...on_compiler__compile__tests__if_mixed.snap | 118 ++---------------- ...thon_compiler__compile__tests__if_ors.snap | 98 ++------------- 7 files changed, 61 insertions(+), 299 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9fb0bd832..c0e424eed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -894,7 +894,6 @@ dependencies = [ "console", "difference", "lazy_static 1.4.0", - "ron", "serde", "serde_json", "serde_yaml", @@ -1617,17 +1616,6 @@ dependencies = [ "is-macro", ] -[[package]] -name = "ron" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a58080b7bb83b2ea28c3b7a9a994fd5e310330b7c8ca5258d99b98128ecfe4" -dependencies = [ - "base64", - "bitflags", - "serde", -] - [[package]] name = "rust-argon2" version = "0.8.2" diff --git a/bytecode/src/bytecode.rs b/bytecode/src/bytecode.rs index fa5a8b66b..427df199c 100644 --- a/bytecode/src/bytecode.rs +++ b/bytecode/src/bytecode.rs @@ -681,7 +681,7 @@ impl Instruction { ) -> fmt::Result { macro_rules! w { ($variant:ident) => { - writeln!(f, "{:20}", stringify!($variant)) + writeln!(f, stringify!($variant)) }; ($variant:ident, $var:expr) => { writeln!(f, "{:20} ({})", stringify!($variant), $var) diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 4e184f454..6ca888182 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -17,4 +17,4 @@ log = "0.4" arrayvec = "0.5" [dev-dependencies] -insta = { version = "1.1", features = ["ron"] } +insta = "1.1" diff --git a/compiler/src/compile.rs b/compiler/src/compile.rs index bbc5123b8..4be7c307e 100644 --- a/compiler/src/compile.rs +++ b/compiler/src/compile.rs @@ -2351,20 +2351,43 @@ mod tests { compiler.pop_code_object() } + macro_rules! assert_dis_snapshot { + ($value:expr) => { + insta::assert_snapshot!( + insta::internals::AutoName, + $value.display_expand_codeobjects().to_string(), + stringify!($value) + ) + }; + } + #[test] fn test_if_ors() { - insta::assert_ron_snapshot!(compile_exec("if True or False or False:\n pass\n")); + assert_dis_snapshot!(compile_exec( + "\ +if True or False or False: + pass +" + )); } #[test] fn test_if_ands() { - insta::assert_ron_snapshot!(compile_exec("if True and False and False:\n pass\n")); + assert_dis_snapshot!(compile_exec( + "\ +if True and False and False: + pass +" + )); } #[test] fn test_if_mixed() { - insta::assert_ron_snapshot!(compile_exec( - "if (True and False) or (False and True):\n pass\n" + assert_dis_snapshot!(compile_exec( + "\ +if (True and False) or (False and True): + pass +" )); } } diff --git a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ands.snap b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ands.snap index e89c82e4a..0d5953c28 100644 --- a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ands.snap +++ b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ands.snap @@ -1,90 +1,13 @@ --- source: compiler/src/compile.rs -expression: "compile_exec(\"if True and False and False:\\n pass\\n\")" +expression: "compile_exec(\"\\\nif True and False and False:\n pass\n\")" --- -CodeObject( - instructions: [ - LoadConst( - idx: 0, - ), - JumpIfFalse( - target: Label(0), - ), - LoadConst( - idx: 1, - ), - JumpIfFalse( - target: Label(0), - ), - LoadConst( - idx: 2, - ), - JumpIfFalse( - target: Label(0), - ), - LoadConst( - idx: 3, - ), - ReturnValue, - ], - label_map: { - Label(0): 6, - }, - locations: [ - Location( - row: 1, - column: 4, - ), - Location( - row: 1, - column: 4, - ), - Location( - row: 1, - column: 13, - ), - Location( - row: 1, - column: 13, - ), - Location( - row: 1, - column: 23, - ), - Location( - row: 1, - column: 23, - ), - Location( - row: 2, - column: 2, - ), - Location( - row: 2, - column: 2, - ), - ], - flags: CodeFlags( - bits: 8, - ), - posonlyarg_count: 0, - arg_names: [], - varargs_name: None, - kwonlyarg_names: [], - varkeywords_name: None, - source_path: "source_path", - first_line_number: 0, - obj_name: "", - constants: [ - Boolean( - value: true, - ), - Boolean( - value: false, - ), - Boolean( - value: false, - ), - None, - ], -) + 0 LoadConst (true) + 1 JumpIfFalse (6) + 2 LoadConst (false) + 3 JumpIfFalse (6) + 4 LoadConst (false) + 5 JumpIfFalse (6) + >> 6 LoadConst (None) + 7 ReturnValue + diff --git a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_mixed.snap b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_mixed.snap index 302667f16..5476053b1 100644 --- a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_mixed.snap +++ b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_mixed.snap @@ -1,109 +1,15 @@ --- source: compiler/src/compile.rs -expression: "compile_exec(\"if (True and False) or (False and True):\\n pass\\n\")" +expression: "compile_exec(\"\\\nif (True and False) or (False and True):\n pass\n\")" --- -CodeObject( - instructions: [ - LoadConst( - idx: 0, - ), - JumpIfFalse( - target: Label(2), - ), - LoadConst( - idx: 1, - ), - JumpIfTrue( - target: Label(1), - ), - LoadConst( - idx: 2, - ), - JumpIfFalse( - target: Label(0), - ), - LoadConst( - idx: 3, - ), - JumpIfFalse( - target: Label(0), - ), - LoadConst( - idx: 4, - ), - ReturnValue, - ], - label_map: { - Label(0): 8, - Label(1): 8, - Label(2): 4, - }, - locations: [ - Location( - row: 1, - column: 5, - ), - Location( - row: 1, - column: 5, - ), - Location( - row: 1, - column: 14, - ), - Location( - row: 1, - column: 14, - ), - Location( - row: 1, - column: 25, - ), - Location( - row: 1, - column: 25, - ), - Location( - row: 1, - column: 35, - ), - Location( - row: 1, - column: 35, - ), - Location( - row: 2, - column: 2, - ), - Location( - row: 2, - column: 2, - ), - ], - flags: CodeFlags( - bits: 8, - ), - posonlyarg_count: 0, - arg_names: [], - varargs_name: None, - kwonlyarg_names: [], - varkeywords_name: None, - source_path: "source_path", - first_line_number: 0, - obj_name: "", - constants: [ - Boolean( - value: true, - ), - Boolean( - value: false, - ), - Boolean( - value: false, - ), - Boolean( - value: true, - ), - None, - ], -) + 0 LoadConst (true) + 1 JumpIfFalse (4) + 2 LoadConst (false) + 3 JumpIfTrue (8) + >> 4 LoadConst (false) + 5 JumpIfFalse (8) + 6 LoadConst (true) + 7 JumpIfFalse (8) + >> 8 LoadConst (None) + 9 ReturnValue + diff --git a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ors.snap b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ors.snap index 21a5e47b7..d2bc38502 100644 --- a/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ors.snap +++ b/compiler/src/snapshots/rustpython_compiler__compile__tests__if_ors.snap @@ -1,91 +1,13 @@ --- source: compiler/src/compile.rs -expression: "compile_exec(\"if True or False or False:\\n pass\\n\")" +expression: "compile_exec(\"\\\nif True or False or False:\n pass\n\")" --- -CodeObject( - instructions: [ - LoadConst( - idx: 0, - ), - JumpIfTrue( - target: Label(1), - ), - LoadConst( - idx: 1, - ), - JumpIfTrue( - target: Label(1), - ), - LoadConst( - idx: 2, - ), - JumpIfFalse( - target: Label(0), - ), - LoadConst( - idx: 3, - ), - ReturnValue, - ], - label_map: { - Label(0): 6, - Label(1): 6, - }, - locations: [ - Location( - row: 1, - column: 4, - ), - Location( - row: 1, - column: 4, - ), - Location( - row: 1, - column: 12, - ), - Location( - row: 1, - column: 12, - ), - Location( - row: 1, - column: 21, - ), - Location( - row: 1, - column: 21, - ), - Location( - row: 2, - column: 2, - ), - Location( - row: 2, - column: 2, - ), - ], - flags: CodeFlags( - bits: 8, - ), - posonlyarg_count: 0, - arg_names: [], - varargs_name: None, - kwonlyarg_names: [], - varkeywords_name: None, - source_path: "source_path", - first_line_number: 0, - obj_name: "", - constants: [ - Boolean( - value: true, - ), - Boolean( - value: false, - ), - Boolean( - value: false, - ), - None, - ], -) + 0 LoadConst (true) + 1 JumpIfTrue (6) + 2 LoadConst (false) + 3 JumpIfTrue (6) + 4 LoadConst (false) + 5 JumpIfFalse (6) + >> 6 LoadConst (None) + 7 ReturnValue +