summaryrefslogtreecommitdiff
path: root/zjit
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2026-03-24 23:09:09 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2026-03-25 14:27:45 -0700
commitd8353e1bc5c36832a47e710cfda1e3350640f921 (patch)
tree3b2b9c5c407b05ff6ef99fb38ed4bfc1b039279c /zjit
parent84d71b88ad57995dd206a3c2211973985e162774 (diff)
ZJIT: Add assert_compiles for codegen tests to assert successful compilation
In the old Ruby-based tests, assert_compiles asserted that every compilation triggered by the test script succeeds, while assert_runs (now inspect) allowed compilation failures. This distinction was lost during the migration to Rust tests. Introduce assert_compiles() in Rust that temporarily enables ZJITState::assert_compiles during program evaluation, causing a panic if any compilation fails. Replace inspect() with assert_compiles() in 146 tests that compile successfully, keeping inspect() for 224 tests that intentionally test graceful compilation failures or side exits.
Diffstat (limited to 'zjit')
-rw-r--r--zjit/src/codegen_tests.rs292
-rw-r--r--zjit/src/cruby.rs9
-rw-r--r--zjit/src/state.rs6
3 files changed, 161 insertions, 146 deletions
diff --git a/zjit/src/codegen_tests.rs b/zjit/src/codegen_tests.rs
index 53d539cff4..703901b6bc 100644
--- a/zjit/src/codegen_tests.rs
+++ b/zjit/src/codegen_tests.rs
@@ -76,7 +76,7 @@ fn test_putstring() {
test
"##);
assert_contains_opcode("test", YARVINSN_putstring);
- assert_snapshot!(inspect(r##"test"##), @r#""""#);
+ assert_snapshot!(assert_compiles(r##"test"##), @r#""""#);
}
#[test]
@@ -86,7 +86,7 @@ fn test_putchilledstring() {
test
"#);
assert_contains_opcode("test", YARVINSN_putchilledstring);
- assert_snapshot!(inspect(r#"test"#), @r#""""#);
+ assert_snapshot!(assert_compiles(r#"test"#), @r#""""#);
}
#[test]
@@ -118,7 +118,7 @@ fn test_getglobal_with_warning() {
test
"#);
assert_contains_opcode("test", YARVINSN_getglobal);
- assert_snapshot!(inspect(r#"test"#), @r#""rescued""#);
+ assert_snapshot!(assert_compiles(r#"test"#), @r#""rescued""#);
}
#[test]
@@ -131,7 +131,7 @@ fn test_setglobal() {
test
");
assert_contains_opcode("test", YARVINSN_setglobal);
- assert_snapshot!(inspect("test"), @"1");
+ assert_snapshot!(assert_compiles("test"), @"1");
}
#[test]
@@ -143,7 +143,7 @@ fn test_string_intern() {
test
"#);
assert_contains_opcode("test", YARVINSN_intern);
- assert_snapshot!(inspect(r#"test"#), @":foo123");
+ assert_snapshot!(assert_compiles(r#"test"#), @":foo123");
}
#[test]
@@ -155,7 +155,7 @@ fn test_duphash() {
test
");
assert_contains_opcode("test", YARVINSN_duphash);
- assert_snapshot!(inspect("test"), @"{a: 1}");
+ assert_snapshot!(assert_compiles("test"), @"{a: 1}");
}
#[test]
@@ -167,7 +167,7 @@ fn test_pushtoarray() {
test
");
assert_contains_opcode("test", YARVINSN_pushtoarray);
- assert_snapshot!(inspect("test"), @"[1, 2, 3]");
+ assert_snapshot!(assert_compiles("test"), @"[1, 2, 3]");
}
#[test]
@@ -179,7 +179,7 @@ fn test_splatarray_new_array() {
test [1, 2]
");
assert_contains_opcode("test", YARVINSN_splatarray);
- assert_snapshot!(inspect("test [1, 2]"), @"[1, 2, 3]");
+ assert_snapshot!(assert_compiles("test [1, 2]"), @"[1, 2, 3]");
}
#[test]
@@ -194,7 +194,7 @@ fn test_splatarray_existing_array() {
test [3]
");
assert_contains_opcode("test", YARVINSN_splatarray);
- assert_snapshot!(inspect("test [3]"), @"[1, 2, 3]");
+ assert_snapshot!(assert_compiles("test [3]"), @"[1, 2, 3]");
}
#[test]
@@ -206,7 +206,7 @@ fn test_concattoarray() {
test 3
");
assert_contains_opcode("test", YARVINSN_concattoarray);
- assert_snapshot!(inspect("test 3"), @"[1, 2, 3]");
+ assert_snapshot!(assert_compiles("test 3"), @"[1, 2, 3]");
}
#[test]
@@ -223,7 +223,7 @@ fn test_definedivar() {
test
");
assert_contains_opcode("test", YARVINSN_definedivar);
- assert_snapshot!(inspect("test"), @r#"[nil, "instance-variable", nil]"#);
+ assert_snapshot!(assert_compiles("test"), @r#"[nil, "instance-variable", nil]"#);
}
#[test]
@@ -238,7 +238,7 @@ fn test_setglobal_with_trace_var_exception() {
test
"#);
assert_contains_opcode("test", YARVINSN_setglobal);
- assert_snapshot!(inspect(r#"test"#), @r#""rescued""#);
+ assert_snapshot!(assert_compiles(r#"test"#), @r#""rescued""#);
}
#[test]
@@ -417,7 +417,7 @@ fn test_getblockparamproxy() {
test { 1 }
");
assert_contains_opcode("test", YARVINSN_getblockparamproxy);
- assert_snapshot!(inspect("test { 1 }"), @"1");
+ assert_snapshot!(assert_compiles("test { 1 }"), @"1");
}
#[test]
@@ -429,7 +429,7 @@ fn test_getblockparam() {
test { 2 }.call
");
assert_contains_opcode("test", YARVINSN_getblockparam);
- assert_snapshot!(inspect("test { 2 }.call"), @"2");
+ assert_snapshot!(assert_compiles("test { 2 }.call"), @"2");
}
#[test]
@@ -443,7 +443,7 @@ fn test_getblockparam_proxy_side_exit_restores_block_local() {
test {}
");
assert_contains_opcode("test", YARVINSN_getblockparam);
- assert_snapshot!(inspect("test {}"), @"2");
+ assert_snapshot!(assert_compiles("test {}"), @"2");
}
#[test]
@@ -458,7 +458,7 @@ fn test_getblockparam_used_twice_in_args() {
test {1}.call
");
assert_contains_opcode("test", YARVINSN_getblockparam);
- assert_snapshot!(inspect("test {1}.call"), @"1");
+ assert_snapshot!(assert_compiles("test {1}.call"), @"1");
}
#[test]
@@ -470,7 +470,7 @@ fn test_optimized_method_call_proc_call() {
test(proc { |x| x * 2 })
");
assert_contains_opcode("test", YARVINSN_opt_send_without_block);
- assert_snapshot!(inspect("test(proc { |x| x * 2 })"), @"2");
+ assert_snapshot!(assert_compiles("test(proc { |x| x * 2 })"), @"2");
}
#[test]
@@ -482,7 +482,7 @@ fn test_optimized_method_call_proc_aref() {
test(proc { |x| x * 2 })
");
assert_contains_opcode("test", YARVINSN_opt_aref);
- assert_snapshot!(inspect("test(proc { |x| x * 2 })"), @"4");
+ assert_snapshot!(assert_compiles("test(proc { |x| x * 2 })"), @"4");
}
#[test]
@@ -494,7 +494,7 @@ fn test_optimized_method_call_proc_yield() {
test(proc { |x| x * 2 })
");
assert_contains_opcode("test", YARVINSN_opt_send_without_block);
- assert_snapshot!(inspect("test(proc { |x| x * 2 })"), @"6");
+ assert_snapshot!(assert_compiles("test(proc { |x| x * 2 })"), @"6");
}
#[test]
@@ -506,7 +506,7 @@ fn test_optimized_method_call_proc_kw_splat() {
test(proc { |**kw| kw[:a] + kw[:b] }, { a: 1, b: 2 })
");
assert_contains_opcode("test", YARVINSN_opt_send_without_block);
- assert_snapshot!(inspect("test(proc { |**kw| kw[:a] + kw[:b] }, { a: 1, b: 2 })"), @"3");
+ assert_snapshot!(assert_compiles("test(proc { |**kw| kw[:a] + kw[:b] }, { a: 1, b: 2 })"), @"3");
}
#[test]
@@ -924,7 +924,7 @@ fn test_sendforward() {
test(1, 2)
");
assert_contains_opcode("test", YARVINSN_sendforward);
- assert_snapshot!(inspect("test(1, 2)"), @"[1, 2]");
+ assert_snapshot!(assert_compiles("test(1, 2)"), @"[1, 2]");
}
#[test]
@@ -1873,7 +1873,7 @@ fn test_opt_eq() {
test(0, 2) # profile opt_eq
");
assert_contains_opcode("test", YARVINSN_opt_eq);
- assert_snapshot!(inspect("[test(1, 1), test(0, 1)]"), @"[true, false]");
+ assert_snapshot!(assert_compiles("[test(1, 1), test(0, 1)]"), @"[true, false]");
}
#[test]
@@ -1883,7 +1883,7 @@ fn test_opt_eq_with_minus_one() {
test(1) # profile opt_eq
");
assert_contains_opcode("test", YARVINSN_opt_eq);
- assert_snapshot!(inspect("[test(0), test(-1)]"), @"[false, true]");
+ assert_snapshot!(assert_compiles("[test(0), test(-1)]"), @"[false, true]");
}
#[test]
@@ -1893,7 +1893,7 @@ fn test_opt_neq_dynamic() {
test(0, 2) # profile opt_neq
");
assert_contains_opcode("test", YARVINSN_opt_neq);
- assert_snapshot!(inspect("[test(1, 1), test(0, 1)]"), @"[false, true]");
+ assert_snapshot!(assert_compiles("[test(1, 1), test(0, 1)]"), @"[false, true]");
}
#[test]
@@ -2011,7 +2011,7 @@ fn test_opt_lt() {
test(2, 3) # profile opt_lt
");
assert_contains_opcode("test", YARVINSN_opt_lt);
- assert_snapshot!(inspect("[test(0, 1), test(0, 0), test(1, 0)]"), @"[true, false, false]");
+ assert_snapshot!(assert_compiles("[test(0, 1), test(0, 0), test(1, 0)]"), @"[true, false, false]");
}
#[test]
@@ -2021,7 +2021,7 @@ fn test_opt_lt_with_literal_lhs() {
test(2) # profile opt_lt
");
assert_contains_opcode("test", YARVINSN_opt_lt);
- assert_snapshot!(inspect("[test(1), test(2), test(3)]"), @"[false, false, true]");
+ assert_snapshot!(assert_compiles("[test(1), test(2), test(3)]"), @"[false, false, true]");
}
#[test]
@@ -2031,7 +2031,7 @@ fn test_opt_le() {
test(2, 3) # profile opt_le
");
assert_contains_opcode("test", YARVINSN_opt_le);
- assert_snapshot!(inspect("[test(0, 1), test(0, 0), test(1, 0)]"), @"[true, true, false]");
+ assert_snapshot!(assert_compiles("[test(0, 1), test(0, 0), test(1, 0)]"), @"[true, true, false]");
}
#[test]
@@ -2041,7 +2041,7 @@ fn test_opt_gt() {
test(2, 3) # profile opt_gt
");
assert_contains_opcode("test", YARVINSN_opt_gt);
- assert_snapshot!(inspect("[test(0, 1), test(0, 0), test(1, 0)]"), @"[false, false, true]");
+ assert_snapshot!(assert_compiles("[test(0, 1), test(0, 0), test(1, 0)]"), @"[false, false, true]");
}
#[test]
@@ -2050,7 +2050,7 @@ fn test_opt_empty_p() {
def test(x) = x.empty?
");
assert_contains_opcode("test", YARVINSN_opt_empty_p);
- assert_snapshot!(inspect("[test([1]), test(\"1\"), test({})]"), @"[false, false, true]");
+ assert_snapshot!(assert_compiles("[test([1]), test(\"1\"), test({})]"), @"[false, false, true]");
}
#[test]
@@ -2059,7 +2059,7 @@ fn test_opt_succ() {
def test(obj) = obj.succ
");
assert_contains_opcode("test", YARVINSN_opt_succ);
- assert_snapshot!(inspect(r#"[test(-1), test("A")]"#), @r#"[0, "B"]"#);
+ assert_snapshot!(assert_compiles(r#"[test(-1), test("A")]"#), @r#"[0, "B"]"#);
}
#[test]
@@ -2068,7 +2068,7 @@ fn test_opt_and() {
def test(x, y) = x & y
");
assert_contains_opcode("test", YARVINSN_opt_and);
- assert_snapshot!(inspect("[test(0b1101, 3), test([3, 2, 1, 4], [8, 1, 2, 3])]"), @"[1, [3, 2, 1]]");
+ assert_snapshot!(assert_compiles("[test(0b1101, 3), test([3, 2, 1, 4], [8, 1, 2, 3])]"), @"[1, [3, 2, 1]]");
}
#[test]
@@ -2077,7 +2077,7 @@ fn test_opt_or() {
def test(x, y) = x | y
");
assert_contains_opcode("test", YARVINSN_opt_or);
- assert_snapshot!(inspect("[test(0b1000, 3), test([3, 2, 1], [1, 2, 3])]"), @"[11, [3, 2, 1]]");
+ assert_snapshot!(assert_compiles("[test(0b1000, 3), test([3, 2, 1], [1, 2, 3])]"), @"[11, [3, 2, 1]]");
}
#[test]
@@ -2086,7 +2086,7 @@ fn test_fixnum_and() {
def test(a, b) = a & b
");
assert_contains_opcode("test", YARVINSN_opt_and);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
[
test(5, 3),
test(0b011, 0b110),
@@ -2101,7 +2101,7 @@ fn test_fixnum_and_side_exit() {
def test(a, b) = a & b
");
assert_contains_opcode("test", YARVINSN_opt_and);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
[
test(2, 2),
test(0b011, 0b110),
@@ -2116,7 +2116,7 @@ fn test_fixnum_or() {
def test(a, b) = a | b
");
assert_contains_opcode("test", YARVINSN_opt_or);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
[
test(5, 3),
test(1, 2),
@@ -2131,7 +2131,7 @@ fn test_fixnum_or_side_exit() {
def test(a, b) = a | b
");
assert_contains_opcode("test", YARVINSN_opt_or);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
[
test(1, 2),
test(2, 2),
@@ -2173,7 +2173,7 @@ fn test_fixnum_mul() {
test(4)
");
assert_contains_opcode("test", YARVINSN_opt_mult);
- assert_snapshot!(inspect("test(4)"), @"12");
+ assert_snapshot!(assert_compiles("test(4)"), @"12");
}
#[test]
@@ -2184,7 +2184,7 @@ fn test_fixnum_div() {
test(4)
");
assert_contains_opcode("test", YARVINSN_opt_div);
- assert_snapshot!(inspect("test(4)"), @"12");
+ assert_snapshot!(assert_compiles("test(4)"), @"12");
}
#[test]
@@ -2195,7 +2195,7 @@ fn test_fixnum_floor() {
test(4)
");
assert_contains_opcode("test", YARVINSN_opt_div);
- assert_snapshot!(inspect("test(4)"), @"0");
+ assert_snapshot!(assert_compiles("test(4)"), @"0");
}
#[test]
@@ -2204,7 +2204,7 @@ fn test_opt_not() {
def test(obj) = !obj
");
assert_contains_opcode("test", YARVINSN_opt_not);
- assert_snapshot!(inspect("[test(nil), test(false), test(0)]"), @"[true, true, false]");
+ assert_snapshot!(assert_compiles("[test(nil), test(false), test(0)]"), @"[true, true, false]");
}
#[test]
@@ -2213,7 +2213,7 @@ fn test_opt_regexpmatch2() {
def test(haystack) = /needle/ =~ haystack
");
assert_contains_opcode("test", YARVINSN_opt_regexpmatch2);
- assert_snapshot!(inspect(r#"[test("kneedle"), test("")]"#), @"[1, nil]");
+ assert_snapshot!(assert_compiles(r#"[test("kneedle"), test("")]"#), @"[1, nil]");
}
#[test]
@@ -2223,7 +2223,7 @@ fn test_opt_ge() {
test(2, 3) # profile opt_ge
");
assert_contains_opcode("test", YARVINSN_opt_ge);
- assert_snapshot!(inspect("[test(0, 1), test(0, 0), test(1, 0)]"), @"[false, true, true]");
+ assert_snapshot!(assert_compiles("[test(0, 1), test(0, 0), test(1, 0)]"), @"[false, true, true]");
}
#[test]
@@ -2239,7 +2239,7 @@ fn test_opt_new_does_not_push_frame() {
test
");
assert_contains_opcode("test", YARVINSN_opt_new);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
foo = test
foo.backtrace.find { |frame| frame.include?('Class#new') }
"), @"nil");
@@ -2256,7 +2256,7 @@ fn test_opt_new_with_redefined() {
test
"#);
assert_contains_opcode("test", YARVINSN_opt_new);
- assert_snapshot!(inspect(r#"test"#), @r#""foo""#);
+ assert_snapshot!(assert_compiles(r#"test"#), @r#""foo""#);
}
#[test]
@@ -2267,7 +2267,7 @@ fn test_opt_new_invalidate_new() {
test
"#);
assert_contains_opcode("test", YARVINSN_opt_new);
- assert_snapshot!(inspect(r#"
+ assert_snapshot!(assert_compiles(r#"
result = [test.class.name]
def Foo.new = "foo"
result << test
@@ -2283,7 +2283,7 @@ fn test_opt_newarray_send_include_p() {
test(1)
");
assert_contains_opcode("test", YARVINSN_opt_newarray_send);
- assert_snapshot!(inspect("[test(1), test(\"n\")]"), @"[true, false]");
+ assert_snapshot!(assert_compiles("[test(1), test(\"n\")]"), @"[true, false]");
}
#[test]
@@ -2300,7 +2300,7 @@ fn test_opt_newarray_send_include_p_redefined() {
end
");
assert_contains_opcode("test", YARVINSN_opt_newarray_send);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
def test(x)
[:y, 1, Object.new].include?(x)
end
@@ -2318,7 +2318,7 @@ fn test_opt_duparray_send_include_p() {
test(1)
");
assert_contains_opcode("test", YARVINSN_opt_duparray_send);
- assert_snapshot!(inspect("[test(1), test(\"n\")]"), @"[true, false]");
+ assert_snapshot!(assert_compiles("[test(1), test(\"n\")]"), @"[true, false]");
}
#[test]
@@ -2335,7 +2335,7 @@ fn test_opt_duparray_send_include_p_redefined() {
end
");
assert_contains_opcode("test", YARVINSN_opt_duparray_send);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
def test(x)
[:y, 1].include?(x)
end
@@ -2353,7 +2353,7 @@ fn test_opt_newarray_send_pack_buffer() {
test(65, "")
"#);
assert_contains_opcode("test", YARVINSN_opt_newarray_send);
- assert_snapshot!(inspect(r#"
+ assert_snapshot!(assert_compiles(r#"
buf = ""
[test(65, buf), test(66, buf), test(67, buf), buf]
"#), @r#"["ABC", "ABC", "ABC", "ABC"]"#);
@@ -2374,7 +2374,7 @@ fn test_opt_newarray_send_pack_buffer_redefined() {
end
"#);
assert_contains_opcode("test", YARVINSN_opt_newarray_send);
- assert_snapshot!(inspect(r#"
+ assert_snapshot!(assert_compiles(r#"
def test(num, buffer)
[num].pack('C', buffer:)
end
@@ -2394,7 +2394,7 @@ fn test_opt_newarray_send_hash() {
test(20)
");
assert_contains_opcode("test", YARVINSN_opt_newarray_send);
- assert_snapshot!(inspect("test(20).class"), @"Integer");
+ assert_snapshot!(assert_compiles("test(20).class"), @"Integer");
}
#[test]
@@ -2407,7 +2407,7 @@ fn test_opt_newarray_send_hash_redefined() {
test(20)
");
assert_contains_opcode("test", YARVINSN_opt_newarray_send);
- assert_snapshot!(inspect("test(20)"), @"42");
+ assert_snapshot!(assert_compiles("test(20)"), @"42");
}
#[test]
@@ -2417,7 +2417,7 @@ fn test_opt_newarray_send_max() {
test(10, 20)
");
assert_contains_opcode("test", YARVINSN_opt_newarray_send);
- assert_snapshot!(inspect("[test(10, 20), test(40, 30)]"), @"[20, 40]");
+ assert_snapshot!(assert_compiles("[test(10, 20), test(40, 30)]"), @"[20, 40]");
}
#[test]
@@ -2432,7 +2432,7 @@ fn test_opt_newarray_send_max_redefined() {
def test(a,b) = [a,b].max
");
assert_contains_opcode("test", YARVINSN_opt_newarray_send);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
def test(a,b) = [a,b].max
test(15, 30)
[test(15, 30), test(45, 35)]
@@ -2446,7 +2446,7 @@ fn test_new_hash_empty() {
test
");
assert_contains_opcode("test", YARVINSN_newhash);
- assert_snapshot!(inspect("test"), @"{}");
+ assert_snapshot!(assert_compiles("test"), @"{}");
}
#[test]
@@ -2462,7 +2462,7 @@ fn test_new_hash_nonempty() {
test
"#);
assert_contains_opcode("test", YARVINSN_newhash);
- assert_snapshot!(inspect(r#"test"#), @r#"{"key" => "value", 42 => 100}"#);
+ assert_snapshot!(assert_compiles(r#"test"#), @r#"{"key" => "value", 42 => 100}"#);
}
#[test]
@@ -2472,7 +2472,7 @@ fn test_new_hash_single_key_value() {
test
"#);
assert_contains_opcode("test", YARVINSN_newhash);
- assert_snapshot!(inspect(r#"test"#), @r#"{"key" => "value"}"#);
+ assert_snapshot!(assert_compiles(r#"test"#), @r#"{"key" => "value"}"#);
}
#[test]
@@ -2484,7 +2484,7 @@ fn test_new_hash_with_computation() {
test(2, 3)
"#);
assert_contains_opcode("test", YARVINSN_newhash);
- assert_snapshot!(inspect(r#"test(2, 3)"#), @r#"{"sum" => 5, "product" => 6}"#);
+ assert_snapshot!(assert_compiles(r#"test(2, 3)"#), @r#"{"sum" => 5, "product" => 6}"#);
}
#[test]
@@ -2573,7 +2573,7 @@ fn test_opt_hash_freeze() {
test
");
assert_contains_opcode("test", YARVINSN_opt_hash_freeze);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
result = [test]
class Hash
def freeze = 5
@@ -2592,7 +2592,7 @@ fn test_opt_hash_freeze_rewritten() {
test
");
assert_contains_opcode("test", YARVINSN_opt_hash_freeze);
- assert_snapshot!(inspect("test"), @"5");
+ assert_snapshot!(assert_compiles("test"), @"5");
}
#[test]
@@ -2604,7 +2604,7 @@ fn test_opt_aset_hash() {
test({}, :key, 42)
");
assert_contains_opcode("test", YARVINSN_opt_aset);
- assert_snapshot!(inspect("h = {}; test(h, :key, 42); h[:key]"), @"42");
+ assert_snapshot!(assert_compiles("h = {}; test(h, :key, 42); h[:key]"), @"42");
}
#[test]
@@ -2678,7 +2678,7 @@ fn test_opt_ary_freeze() {
test
");
assert_contains_opcode("test", YARVINSN_opt_ary_freeze);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
result = [test]
class Array
def freeze = 5
@@ -2697,7 +2697,7 @@ fn test_opt_ary_freeze_rewritten() {
test
");
assert_contains_opcode("test", YARVINSN_opt_ary_freeze);
- assert_snapshot!(inspect("test"), @"5");
+ assert_snapshot!(assert_compiles("test"), @"5");
}
#[test]
@@ -2707,7 +2707,7 @@ fn test_opt_str_freeze() {
test
");
assert_contains_opcode("test", YARVINSN_opt_str_freeze);
- assert_snapshot!(inspect(r#"
+ assert_snapshot!(assert_compiles(r#"
result = [test]
class String
def freeze = 5
@@ -2726,7 +2726,7 @@ fn test_opt_str_freeze_rewritten() {
test
");
assert_contains_opcode("test", YARVINSN_opt_str_freeze);
- assert_snapshot!(inspect("test"), @"5");
+ assert_snapshot!(assert_compiles("test"), @"5");
}
#[test]
@@ -2736,7 +2736,7 @@ fn test_opt_str_uminus() {
test
");
assert_contains_opcode("test", YARVINSN_opt_str_uminus);
- assert_snapshot!(inspect(r#"
+ assert_snapshot!(assert_compiles(r#"
result = [test]
class String
def -@ = 5
@@ -2755,7 +2755,7 @@ fn test_opt_str_uminus_rewritten() {
test
");
assert_contains_opcode("test", YARVINSN_opt_str_uminus);
- assert_snapshot!(inspect("test"), @"5");
+ assert_snapshot!(assert_compiles("test"), @"5");
}
#[test]
@@ -2765,7 +2765,7 @@ fn test_new_array_empty() {
test
");
assert_contains_opcode("test", YARVINSN_newarray);
- assert_snapshot!(inspect("test"), @"[]");
+ assert_snapshot!(assert_compiles("test"), @"[]");
}
#[test]
@@ -2806,7 +2806,7 @@ fn test_array_fixnum_aref() {
test(2)
");
assert_contains_opcode("test", YARVINSN_opt_aref);
- assert_snapshot!(inspect("test(2)"), @"3");
+ assert_snapshot!(assert_compiles("test(2)"), @"3");
}
#[test]
@@ -2816,7 +2816,7 @@ fn test_array_fixnum_aref_negative_index() {
test(-1)
");
assert_contains_opcode("test", YARVINSN_opt_aref);
- assert_snapshot!(inspect("test(-1)"), @"3");
+ assert_snapshot!(assert_compiles("test(-1)"), @"3");
}
#[test]
@@ -2826,7 +2826,7 @@ fn test_array_fixnum_aref_out_of_bounds_positive() {
test(10)
");
assert_contains_opcode("test", YARVINSN_opt_aref);
- assert_snapshot!(inspect("test(10)"), @"nil");
+ assert_snapshot!(assert_compiles("test(10)"), @"nil");
}
#[test]
@@ -2836,7 +2836,7 @@ fn test_array_fixnum_aref_out_of_bounds_negative() {
test(-10)
");
assert_contains_opcode("test", YARVINSN_opt_aref);
- assert_snapshot!(inspect("test(-10)"), @"nil");
+ assert_snapshot!(assert_compiles("test(-10)"), @"nil");
}
#[test]
@@ -2847,7 +2847,7 @@ fn test_array_fixnum_aref_array_subclass() {
test(MyArray[1,2,3], 2)
");
assert_contains_opcode("test", YARVINSN_opt_aref);
- assert_snapshot!(inspect("test(MyArray[1,2,3], 2)"), @"3");
+ assert_snapshot!(assert_compiles("test(MyArray[1,2,3], 2)"), @"3");
}
#[test]
@@ -2873,7 +2873,7 @@ fn test_array_fixnum_aset() {
test([1,2,3], 2)
");
assert_contains_opcode("test", YARVINSN_opt_aset);
- assert_snapshot!(inspect("arr = [1,2,3]; test(arr, 2); arr"), @"[1, 2, 7]");
+ assert_snapshot!(assert_compiles("arr = [1,2,3]; test(arr, 2); arr"), @"[1, 2, 7]");
}
#[test]
@@ -2885,7 +2885,7 @@ fn test_array_fixnum_aset_returns_value() {
test([1,2,3], 2)
");
assert_contains_opcode("test", YARVINSN_opt_aset);
- assert_snapshot!(inspect("test([1,2,3], 2)"), @"7");
+ assert_snapshot!(assert_compiles("test([1,2,3], 2)"), @"7");
}
#[test]
@@ -2959,7 +2959,7 @@ fn test_array_fixnum_aset_array_subclass() {
test(MyArray.new, 0)
");
assert_contains_opcode("test", YARVINSN_opt_aset);
- assert_snapshot!(inspect("arr = MyArray.new; test(arr, 0); arr[0]"), @"7");
+ assert_snapshot!(assert_compiles("arr = MyArray.new; test(arr, 0); arr[0]"), @"7");
}
#[test]
@@ -3041,7 +3041,7 @@ fn test_new_range_fixnum_both_literals_inclusive() {
end
");
assert_contains_opcode("test", YARVINSN_newrange);
- assert_snapshot!(inspect("test; test"), @"1..2");
+ assert_snapshot!(assert_compiles("test; test"), @"1..2");
}
#[test]
@@ -3053,7 +3053,7 @@ fn test_new_range_fixnum_both_literals_exclusive() {
end
");
assert_contains_opcode("test", YARVINSN_newrange);
- assert_snapshot!(inspect("test; test"), @"1...2");
+ assert_snapshot!(assert_compiles("test; test"), @"1...2");
}
#[test]
@@ -3062,7 +3062,7 @@ fn test_new_range_fixnum_low_literal_inclusive() {
def test(a) = (1..a)
");
assert_contains_opcode("test", YARVINSN_newrange);
- assert_snapshot!(inspect("test(2); test(3)"), @"1..3");
+ assert_snapshot!(assert_compiles("test(2); test(3)"), @"1..3");
}
#[test]
@@ -3071,7 +3071,7 @@ fn test_new_range_fixnum_low_literal_exclusive() {
def test(a) = (1...a)
");
assert_contains_opcode("test", YARVINSN_newrange);
- assert_snapshot!(inspect("test(2); test(3)"), @"1...3");
+ assert_snapshot!(assert_compiles("test(2); test(3)"), @"1...3");
}
#[test]
@@ -3080,7 +3080,7 @@ fn test_new_range_fixnum_high_literal_inclusive() {
def test(a) = (a..10)
");
assert_contains_opcode("test", YARVINSN_newrange);
- assert_snapshot!(inspect("test(2); test(3)"), @"3..10");
+ assert_snapshot!(assert_compiles("test(2); test(3)"), @"3..10");
}
#[test]
@@ -3089,7 +3089,7 @@ fn test_new_range_fixnum_high_literal_exclusive() {
def test(a) = (a...10)
");
assert_contains_opcode("test", YARVINSN_newrange);
- assert_snapshot!(inspect("test(2); test(3)"), @"3...10");
+ assert_snapshot!(assert_compiles("test(2); test(3)"), @"3...10");
}
#[test]
@@ -3516,7 +3516,7 @@ fn test_attr_reader() {
test(C.new)
");
assert_contains_opcode("test", YARVINSN_opt_send_without_block);
- assert_snapshot!(inspect("c = C.new; [test(c), test(c)]"), @"[4, 4]");
+ assert_snapshot!(assert_compiles("c = C.new; [test(c), test(c)]"), @"[4, 4]");
}
#[test]
@@ -3532,7 +3532,7 @@ fn test_attr_accessor_getivar() {
test(C.new)
");
assert_contains_opcode("test", YARVINSN_opt_send_without_block);
- assert_snapshot!(inspect("c = C.new; [test(c), test(c)]"), @"[4, 4]");
+ assert_snapshot!(assert_compiles("c = C.new; [test(c), test(c)]"), @"[4, 4]");
}
#[test]
@@ -3551,7 +3551,7 @@ fn test_attr_accessor_setivar() {
test(C.new)
");
assert_contains_opcode("test", YARVINSN_opt_send_without_block);
- assert_snapshot!(inspect("c = C.new; [test(c), test(c)]"), @"[5, 5]");
+ assert_snapshot!(assert_compiles("c = C.new; [test(c), test(c)]"), @"[5, 5]");
}
#[test]
@@ -3571,7 +3571,7 @@ fn test_attr_writer() {
test(C.new)
");
assert_contains_opcode("test", YARVINSN_opt_send_without_block);
- assert_snapshot!(inspect("c = C.new; [test(c), test(c)]"), @"[5, 5]");
+ assert_snapshot!(assert_compiles("c = C.new; [test(c), test(c)]"), @"[5, 5]");
}
#[test]
@@ -3586,7 +3586,7 @@ fn test_getconstant() {
test(Foo)
");
assert_contains_opcode("test", YARVINSN_getconstant);
- assert_snapshot!(inspect("test(Foo)"), @"1");
+ assert_snapshot!(assert_compiles("test(Foo)"), @"1");
}
#[test]
@@ -3599,7 +3599,7 @@ fn test_expandarray_no_splat() {
test [3, 4]
");
assert_contains_opcode("test", YARVINSN_expandarray);
- assert_snapshot!(inspect("test [3, 4]"), @"[3, 4]");
+ assert_snapshot!(assert_compiles("test [3, 4]"), @"[3, 4]");
}
#[test]
@@ -3612,7 +3612,7 @@ fn test_expandarray_splat() {
test [3, 4]
");
assert_contains_opcode("test", YARVINSN_expandarray);
- assert_snapshot!(inspect("test [3, 4]"), @"[3, [4]]");
+ assert_snapshot!(assert_compiles("test [3, 4]"), @"[3, [4]]");
}
#[test]
@@ -3625,7 +3625,7 @@ fn test_expandarray_splat_post() {
test [3, 4, 5]
");
assert_contains_opcode("test", YARVINSN_expandarray);
- assert_snapshot!(inspect("test [3, 4, 5]"), @"[3, [4], 5]");
+ assert_snapshot!(assert_compiles("test [3, 4, 5]"), @"[3, [4], 5]");
}
#[test]
@@ -3638,7 +3638,7 @@ fn test_constant_invalidation() {
C = 123
");
assert_contains_opcode("test", YARVINSN_opt_getconstant_path);
- assert_snapshot!(inspect("test"), @"123");
+ assert_snapshot!(assert_compiles("test"), @"123");
}
#[test]
@@ -3654,7 +3654,7 @@ fn test_constant_path_invalidation() {
def test = A::B::C
");
assert_contains_opcode("test", YARVINSN_opt_getconstant_path);
- assert_snapshot!(inspect(r#"
+ assert_snapshot!(assert_compiles(r#"
module A
module B; end
end
@@ -3682,7 +3682,7 @@ fn test_dupn() {
test([1, 1])
");
assert_contains_opcode("test", YARVINSN_dupn);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
one = [1, 1]
start_empty = []
[test(one), one, test(start_empty), start_empty]
@@ -3711,7 +3711,7 @@ fn test_defined_with_defined_values() {
test
");
assert_contains_opcode("test", YARVINSN_defined);
- assert_snapshot!(inspect("test"), @r#"["constant", "method", "global-variable"]"#);
+ assert_snapshot!(assert_compiles("test"), @r#"["constant", "method", "global-variable"]"#);
}
#[test]
@@ -3721,7 +3721,7 @@ fn test_defined_with_undefined_values() {
test
");
assert_contains_opcode("test", YARVINSN_defined);
- assert_snapshot!(inspect("test"), @"[nil, nil, nil]");
+ assert_snapshot!(assert_compiles("test"), @"[nil, nil, nil]");
}
#[test]
@@ -3731,7 +3731,7 @@ fn test_defined_with_method_call() {
test
"#);
assert_contains_opcode("test", YARVINSN_defined);
- assert_snapshot!(inspect(r#"test"#), @r#"["method", nil]"#);
+ assert_snapshot!(assert_compiles(r#"test"#), @r#"["method", nil]"#);
}
#[test]
@@ -3762,7 +3762,7 @@ fn test_defined_yield() {
def test = defined?(yield)
");
assert_contains_opcode("test", YARVINSN_defined);
- assert_snapshot!(inspect("[test, test, test{}]"), @r#"[nil, nil, "yield"]"#);
+ assert_snapshot!(assert_compiles("[test, test, test{}]"), @r#"[nil, nil, "yield"]"#);
}
#[test]
@@ -3819,7 +3819,7 @@ fn test_putspecialobject_vm_core_and_cbase() {
test
");
assert_contains_opcode("test", YARVINSN_putspecialobject);
- assert_snapshot!(inspect("bar"), @"10");
+ assert_snapshot!(assert_compiles("bar"), @"10");
}
#[test]
@@ -3841,7 +3841,7 @@ fn test_branchnil() {
test(0)
");
assert_contains_opcode("test", YARVINSN_branchnil);
- assert_snapshot!(inspect("[test(1), test(nil)]"), @"[2, nil]");
+ assert_snapshot!(assert_compiles("[test(1), test(nil)]"), @"[2, nil]");
}
#[test]
@@ -3851,7 +3851,7 @@ fn test_nil_nil() {
test
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test"), @"true");
+ assert_snapshot!(assert_compiles("test"), @"true");
}
#[test]
@@ -3861,7 +3861,7 @@ fn test_non_nil_nil() {
test
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test"), @"false");
+ assert_snapshot!(assert_compiles("test"), @"false");
}
#[test]
@@ -3874,7 +3874,7 @@ fn test_getspecial_last_match() {
test("hello world")
"#);
assert_contains_opcode("test", YARVINSN_getspecial);
- assert_snapshot!(inspect(r#"test("hello world")"#), @r#""hello""#);
+ assert_snapshot!(assert_compiles(r#"test("hello world")"#), @r#""hello""#);
}
#[test]
@@ -3887,7 +3887,7 @@ fn test_getspecial_match_pre() {
test("hello world")
"#);
assert_contains_opcode("test", YARVINSN_getspecial);
- assert_snapshot!(inspect(r#"test("hello world")"#), @r#""hello ""#);
+ assert_snapshot!(assert_compiles(r#"test("hello world")"#), @r#""hello ""#);
}
#[test]
@@ -3900,7 +3900,7 @@ fn test_getspecial_match_post() {
test("hello world")
"#);
assert_contains_opcode("test", YARVINSN_getspecial);
- assert_snapshot!(inspect(r#"test("hello world")"#), @r#"" world""#);
+ assert_snapshot!(assert_compiles(r#"test("hello world")"#), @r#"" world""#);
}
#[test]
@@ -3913,7 +3913,7 @@ fn test_getspecial_match_last_group() {
test("hello world")
"#);
assert_contains_opcode("test", YARVINSN_getspecial);
- assert_snapshot!(inspect(r#"test("hello world")"#), @r#""world""#);
+ assert_snapshot!(assert_compiles(r#"test("hello world")"#), @r#""world""#);
}
#[test]
@@ -3926,7 +3926,7 @@ fn test_getspecial_numbered_match_1() {
test("hello world")
"#);
assert_contains_opcode("test", YARVINSN_getspecial);
- assert_snapshot!(inspect(r#"test("hello world")"#), @r#""hello""#);
+ assert_snapshot!(assert_compiles(r#"test("hello world")"#), @r#""hello""#);
}
#[test]
@@ -3939,7 +3939,7 @@ fn test_getspecial_numbered_match_2() {
test("hello world")
"#);
assert_contains_opcode("test", YARVINSN_getspecial);
- assert_snapshot!(inspect(r#"test("hello world")"#), @r#""world""#);
+ assert_snapshot!(assert_compiles(r#"test("hello world")"#), @r#""world""#);
}
#[test]
@@ -3952,7 +3952,7 @@ fn test_getspecial_numbered_match_nonexistent() {
test("hello world")
"#);
assert_contains_opcode("test", YARVINSN_getspecial);
- assert_snapshot!(inspect(r#"test("hello world")"#), @"nil");
+ assert_snapshot!(assert_compiles(r#"test("hello world")"#), @"nil");
}
#[test]
@@ -3965,7 +3965,7 @@ fn test_getspecial_no_match() {
test("hello world")
"#);
assert_contains_opcode("test", YARVINSN_getspecial);
- assert_snapshot!(inspect(r#"test("hello world")"#), @"nil");
+ assert_snapshot!(assert_compiles(r#"test("hello world")"#), @"nil");
}
#[test]
@@ -3978,7 +3978,7 @@ fn test_getspecial_complex_pattern() {
test("abc123def")
"#);
assert_contains_opcode("test", YARVINSN_getspecial);
- assert_snapshot!(inspect(r#"test("abc123def")"#), @r#""123""#);
+ assert_snapshot!(assert_compiles(r#"test("abc123def")"#), @r#""123""#);
}
#[test]
@@ -3991,7 +3991,7 @@ fn test_getspecial_multiple_groups() {
test("123-456")
"#);
assert_contains_opcode("test", YARVINSN_getspecial);
- assert_snapshot!(inspect(r#"test("123-456")"#), @r#""456""#);
+ assert_snapshot!(assert_compiles(r#"test("123-456")"#), @r#""456""#);
}
#[test]
@@ -4233,7 +4233,7 @@ fn test_nil_value_nil_opt_with_guard() {
test(nil)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(nil)"), @"true");
+ assert_snapshot!(assert_compiles("test(nil)"), @"true");
}
#[test]
@@ -4244,7 +4244,7 @@ fn test_nil_value_nil_opt_with_guard_side_exit() {
test(nil)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(1)"), @"false");
+ assert_snapshot!(assert_compiles("test(1)"), @"false");
}
#[test]
@@ -4254,7 +4254,7 @@ fn test_true_nil_opt_with_guard() {
test(true)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(true)"), @"false");
+ assert_snapshot!(assert_compiles("test(true)"), @"false");
}
#[test]
@@ -4265,7 +4265,7 @@ fn test_true_nil_opt_with_guard_side_exit() {
test(true)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(nil)"), @"true");
+ assert_snapshot!(assert_compiles("test(nil)"), @"true");
}
#[test]
@@ -4275,7 +4275,7 @@ fn test_false_nil_opt_with_guard() {
test(false)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(false)"), @"false");
+ assert_snapshot!(assert_compiles("test(false)"), @"false");
}
#[test]
@@ -4286,7 +4286,7 @@ fn test_false_nil_opt_with_guard_side_exit() {
test(false)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(nil)"), @"true");
+ assert_snapshot!(assert_compiles("test(nil)"), @"true");
}
#[test]
@@ -4296,7 +4296,7 @@ fn test_integer_nil_opt_with_guard() {
test(1)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(2)"), @"false");
+ assert_snapshot!(assert_compiles("test(2)"), @"false");
}
#[test]
@@ -4307,7 +4307,7 @@ fn test_integer_nil_opt_with_guard_side_exit() {
test(2)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(nil)"), @"true");
+ assert_snapshot!(assert_compiles("test(nil)"), @"true");
}
#[test]
@@ -4317,7 +4317,7 @@ fn test_float_nil_opt_with_guard() {
test(1.0)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(2.0)"), @"false");
+ assert_snapshot!(assert_compiles("test(2.0)"), @"false");
}
#[test]
@@ -4328,7 +4328,7 @@ fn test_float_nil_opt_with_guard_side_exit() {
test(2.0)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(nil)"), @"true");
+ assert_snapshot!(assert_compiles("test(nil)"), @"true");
}
#[test]
@@ -4338,7 +4338,7 @@ fn test_symbol_nil_opt_with_guard() {
test(:foo)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(:bar)"), @"false");
+ assert_snapshot!(assert_compiles("test(:bar)"), @"false");
}
#[test]
@@ -4349,7 +4349,7 @@ fn test_symbol_nil_opt_with_guard_side_exit() {
test(:bar)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(nil)"), @"true");
+ assert_snapshot!(assert_compiles("test(nil)"), @"true");
}
#[test]
@@ -4359,7 +4359,7 @@ fn test_class_nil_opt_with_guard() {
test(String)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(Integer)"), @"false");
+ assert_snapshot!(assert_compiles("test(Integer)"), @"false");
}
#[test]
@@ -4370,7 +4370,7 @@ fn test_class_nil_opt_with_guard_side_exit() {
test(Integer)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(nil)"), @"true");
+ assert_snapshot!(assert_compiles("test(nil)"), @"true");
}
#[test]
@@ -4380,7 +4380,7 @@ fn test_module_nil_opt_with_guard() {
test(Enumerable)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(Kernel)"), @"false");
+ assert_snapshot!(assert_compiles("test(Kernel)"), @"false");
}
#[test]
@@ -4391,7 +4391,7 @@ fn test_module_nil_opt_with_guard_side_exit() {
test(Kernel)
");
assert_contains_opcode("test", YARVINSN_opt_nil_p);
- assert_snapshot!(inspect("test(nil)"), @"true");
+ assert_snapshot!(assert_compiles("test(nil)"), @"true");
}
#[test]
@@ -4423,7 +4423,7 @@ fn test_string_concat() {
test
"##);
assert_contains_opcode("test", YARVINSN_concatstrings);
- assert_snapshot!(inspect(r##"test"##), @r#""123""#);
+ assert_snapshot!(assert_compiles(r##"test"##), @r#""123""#);
}
#[test]
@@ -4433,7 +4433,7 @@ fn test_string_concat_empty() {
test
"##);
assert_contains_opcode("test", YARVINSN_concatstrings);
- assert_snapshot!(inspect(r##"test"##), @r#""""#);
+ assert_snapshot!(assert_compiles(r##"test"##), @r#""""#);
}
#[test]
@@ -4443,7 +4443,7 @@ fn test_regexp_interpolation() {
test
"##);
assert_contains_opcode("test", YARVINSN_toregexp);
- assert_snapshot!(inspect(r##"test"##), @"/123/");
+ assert_snapshot!(assert_compiles(r##"test"##), @"/123/");
}
#[test]
@@ -4504,7 +4504,7 @@ fn test_opt_case_dispatch() {
test(:warmup)
");
assert_contains_opcode("test", YARVINSN_opt_case_dispatch);
- assert_snapshot!(inspect("[test(:foo), test(1)]"), @"[true, false]");
+ assert_snapshot!(assert_compiles("[test(:foo), test(1)]"), @"[true, false]");
}
#[test]
@@ -4520,7 +4520,7 @@ fn test_checkmatch_case() {
end
"#);
assert_contains_opcode("test", YARVINSN_checkmatch);
- assert_snapshot!(inspect(r#"[test(1), test(2), test("3")]"#), @"[1, 1, 2]");
+ assert_snapshot!(assert_compiles(r#"[test(1), test(2), test("3")]"#), @"[1, 1, 2]");
}
#[test]
@@ -4536,7 +4536,7 @@ fn test_checkmatch_case_splat_array() {
end
"#);
assert_contains_opcode("test", YARVINSN_checkmatch);
- assert_snapshot!(inspect("[test(1), test(2), test(3)]"), @"[1, 1, 2]");
+ assert_snapshot!(assert_compiles("[test(1), test(2), test(3)]"), @"[1, 1, 2]");
}
#[test]
@@ -4552,7 +4552,7 @@ fn test_checkmatch_when_splat_array() {
end
"#);
assert_contains_opcode("test", YARVINSN_checkmatch);
- assert_snapshot!(inspect("[test, test]"), @"[1, 1]");
+ assert_snapshot!(assert_compiles("[test, test]"), @"[1, 1]");
}
#[test]
@@ -4568,7 +4568,7 @@ fn test_checkmatch_rescue() {
end
end
"#);
- assert_snapshot!(inspect("[test, test]"), @"[1, 1]");
+ assert_snapshot!(assert_compiles("[test, test]"), @"[1, 1]");
}
#[test]
@@ -4582,7 +4582,7 @@ fn test_checkmatch_rescue_splat_array() {
end
end
"#);
- assert_snapshot!(inspect("[test, test]"), @"[1, 1]");
+ assert_snapshot!(assert_compiles("[test, test]"), @"[1, 1]");
}
#[test]
@@ -4611,7 +4611,7 @@ fn test_invokeblock() {
test { 41 }
");
assert_contains_opcode("test", YARVINSN_invokeblock);
- assert_snapshot!(inspect("test { 42 }"), @"42");
+ assert_snapshot!(assert_compiles("test { 42 }"), @"42");
}
#[test]
@@ -4623,7 +4623,7 @@ fn test_invokeblock_with_args() {
test(1, 2) { |a, b| a + b }
");
assert_contains_opcode("test", YARVINSN_invokeblock);
- assert_snapshot!(inspect("test(1, 2) { |a, b| a + b }"), @"3");
+ assert_snapshot!(assert_compiles("test(1, 2) { |a, b| a + b }"), @"3");
}
#[test]
@@ -4635,7 +4635,7 @@ fn test_invokeblock_no_block_given() {
test { }
");
assert_contains_opcode("test", YARVINSN_invokeblock);
- assert_snapshot!(inspect("test"), @":error");
+ assert_snapshot!(assert_compiles("test"), @":error");
}
#[test]
@@ -4649,7 +4649,7 @@ fn test_invokeblock_multiple_yields() {
test { |x| x }
");
assert_contains_opcode("test", YARVINSN_invokeblock);
- assert_snapshot!(inspect("
+ assert_snapshot!(assert_compiles("
results = []
test { |x| results << x }
results
@@ -4667,7 +4667,7 @@ fn test_ccall_variadic_with_multiple_args() {
test
");
assert_contains_opcode("test", YARVINSN_opt_send_without_block);
- assert_snapshot!(inspect("test"), @"[1, 2, 3]");
+ assert_snapshot!(assert_compiles("test"), @"[1, 2, 3]");
}
#[test]
@@ -4680,7 +4680,7 @@ fn test_ccall_variadic_with_no_args() {
test
");
assert_contains_opcode("test", YARVINSN_opt_send_without_block);
- assert_snapshot!(inspect("test"), @"[1]");
+ assert_snapshot!(assert_compiles("test"), @"[1]");
}
#[test]
@@ -4694,7 +4694,7 @@ fn test_ccall_variadic_with_no_args_causing_argument_error() {
test
");
assert_contains_opcode("test", YARVINSN_opt_send_without_block);
- assert_snapshot!(inspect("test"), @":error");
+ assert_snapshot!(assert_compiles("test"), @":error");
}
#[test]
@@ -4712,7 +4712,7 @@ fn test_allocating_in_hir_c_method_is() {
second
");
assert_contains_opcode("test", YARVINSN_opt_new);
- assert_snapshot!(inspect("a(Foo)"), @":k");
+ assert_snapshot!(assert_compiles("a(Foo)"), @":k");
}
#[test]
@@ -4839,7 +4839,7 @@ fn test_fixnum_div_zero() {
test(0)
");
assert_contains_opcode("test", YARVINSN_opt_div);
- assert_snapshot!(inspect(r#"test(0)"#), @r#""divided by 0""#);
+ assert_snapshot!(assert_compiles(r#"test(0)"#), @r#""divided by 0""#);
}
#[test]
diff --git a/zjit/src/cruby.rs b/zjit/src/cruby.rs
index b92df55d48..6ca9a97b83 100644
--- a/zjit/src/cruby.rs
+++ b/zjit/src/cruby.rs
@@ -1267,6 +1267,15 @@ pub mod test_utils {
ruby_str_to_rust_string(eval(&inspect))
}
+ /// Like inspect, but also asserts that all compilations triggered by this program succeed.
+ pub fn assert_compiles(program: &str) -> String {
+ use crate::state::ZJITState;
+ ZJITState::enable_assert_compiles();
+ let result = inspect(program);
+ ZJITState::disable_assert_compiles();
+ result
+ }
+
/// Get IseqPtr for a specified method
pub fn get_method_iseq(recv: &str, name: &str) -> *const rb_iseq_t {
get_proc_iseq(&format!("{}.method(:{})", recv, name))
diff --git a/zjit/src/state.rs b/zjit/src/state.rs
index b9f8033e7f..6c61bc77ef 100644
--- a/zjit/src/state.rs
+++ b/zjit/src/state.rs
@@ -201,6 +201,12 @@ impl ZJITState {
instance.assert_compiles = true;
}
+ /// Stop asserting successful compilation
+ pub fn disable_assert_compiles() {
+ let instance = ZJITState::get_instance();
+ instance.assert_compiles = false;
+ }
+
/// Get a mutable reference to counters for ZJIT stats
pub fn get_counters() -> &'static mut Counters {
&mut ZJITState::get_instance().counters