mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Use disassembly for snapshot testing
This commit is contained in:
7 files changed
+61
-299
No files matched your search
Generated
-12
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-1
@@ -17,4 +17,4 @@ log = "0.4"
|
||||
arrayvec = "0.5"
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { version = "1.1", features = ["ron"] }
|
||||
insta = "1.1"
|
||||
+27
-4
@@ -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
|
||||
"
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -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: "<module>",
|
||||
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
|
||||
|
||||
@@ -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: "<module>",
|
||||
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
|
||||
|
||||
@@ -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: "<module>",
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user