Skip to content

Commit 4606c1c

Browse files
committed
fix: Change run_function to return byte vector
We were returning a Value which we made private.
1 parent 7cd8074 commit 4606c1c

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

snapcrab/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod value;
2222

2323
use crate::interpreter::function::invoke_fn;
2424
use crate::memory::ThreadMemory;
25-
use crate::value::{TypedValue, Value};
25+
use crate::value::TypedValue;
2626
use anyhow::{Context, Result, bail};
2727
use rustc_public::mir::mono::Instance;
2828
use rustc_public::{CrateDef, CrateItem, entry_fn, local_crate};
@@ -47,7 +47,7 @@ use tracing::info;
4747
/// // Execute a function named "my_test"
4848
/// let result = run_function("my_test")?;
4949
/// ```
50-
pub fn run_function(fn_name: &str) -> Result<Value> {
50+
pub fn run_function(fn_name: &str) -> Result<Vec<u8>> {
5151
// Find function definition by name
5252
let crate_def = local_crate();
5353
let fn_def = crate_def
@@ -92,7 +92,7 @@ pub fn run_function(fn_name: &str) -> Result<Value> {
9292

9393
info!("Function '{}' returned: {}", fn_name, typed_result);
9494

95-
Ok(result)
95+
Ok(result.as_bytes().to_vec())
9696
}
9797

9898
pub fn run_main() -> Result<ExitCode> {

snapcrab/tests/common/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ extern crate rustc_interface;
55
extern crate rustc_middle;
66
extern crate rustc_public;
77

8-
use snapcrab::value::Value;
98
use std::path::Path;
109
use std::process::ExitCode;
1110

1211
#[derive(Debug)]
1312
pub enum TestResult {
1413
Success,
15-
SuccessWithValue(Value),
14+
SuccessWithValue(Vec<u8>),
1615
Error(String),
1716
ErrorRegex(String),
1817
}

snapcrab/tests/integration_tests.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
mod common;
55

66
use common::TestResult;
7-
use snapcrab::value::Value;
87

98
check_interpreter!(
109
test_simple_success,
@@ -29,7 +28,7 @@ check_custom_start!(
2928
test_valid_custom_start,
3029
input = "valid_custom_start.rs",
3130
start_fn = "my_custom_start",
32-
result = TestResult::SuccessWithValue(Value::from_type(123))
31+
result = TestResult::SuccessWithValue(vec![123, 0, 0, 0])
3332
);
3433

3534
check_custom_start!(
@@ -50,56 +49,56 @@ check_custom_start!(
5049
test_tuple_creation,
5150
input = "tuple_function.rs",
5251
start_fn = "simple_tuple",
53-
result = TestResult::SuccessWithValue(Value::from_bytes(&[1, 42, 0, 0, 232, 3, 0, 0]))
52+
result = TestResult::SuccessWithValue(vec![1, 42, 0, 0, 232, 3, 0, 0])
5453
);
5554

5655
check_custom_start!(
5756
test_simple_tuple_ops,
5857
input = "tuple_operations.rs",
5958
start_fn = "simple_tuple",
60-
result = TestResult::SuccessWithValue(Value::from_bytes(&[1, 42, 0, 0, 232, 3, 0, 0]))
59+
result = TestResult::SuccessWithValue(vec![1, 42, 0, 0, 232, 3, 0, 0])
6160
);
6261

6362
check_custom_start!(
6463
test_unit_tuple,
6564
input = "tuple_operations.rs",
6665
start_fn = "unit_tuple",
67-
result = TestResult::SuccessWithValue(Value::unit().clone())
66+
result = TestResult::SuccessWithValue(vec![])
6867
);
6968

7069
check_custom_start!(
7170
test_single_element_tuple,
7271
input = "tuple_operations.rs",
7372
start_fn = "single_element_tuple",
74-
result = TestResult::SuccessWithValue(Value::from_type(42))
73+
result = TestResult::SuccessWithValue(vec![42, 0, 0, 0])
7574
);
7675

7776
check_custom_start!(
7877
test_reordered_tuple,
7978
input = "tuple_operations.rs",
8079
start_fn = "reordered_tuple",
81-
result = TestResult::SuccessWithValue(Value::from_bytes(&[232, 3, 0, 0, 42, 1, 0, 0]))
80+
result = TestResult::SuccessWithValue(vec![232, 3, 0, 0, 42, 1, 0, 0])
8281
);
8382

8483
check_custom_start!(
8584
test_another_order,
8685
input = "tuple_operations.rs",
8786
start_fn = "another_order",
88-
result = TestResult::SuccessWithValue(Value::from_bytes(&[232, 3, 0, 0, 1, 42, 0, 0]))
87+
result = TestResult::SuccessWithValue(vec![232, 3, 0, 0, 1, 42, 0, 0])
8988
);
9089

9190
check_custom_start!(
9291
test_bool_return,
9392
input = "bool_function.rs",
9493
start_fn = "returns_true",
95-
result = TestResult::SuccessWithValue(Value::from_bool(true))
94+
result = TestResult::SuccessWithValue(vec![1])
9695
);
9796

9897
check_custom_start!(
9998
test_mut_reference,
10099
input = "reference_test.rs",
101100
start_fn = "test_mut_ref",
102-
result = TestResult::SuccessWithValue(Value::from_type(100i32))
101+
result = TestResult::SuccessWithValue(vec![100, 0, 0, 0])
103102
);
104103

105104
check_custom_start!(
@@ -120,22 +119,22 @@ check_custom_start!(
120119
test_mutable_reference_chain,
121120
input = "reference_test.rs",
122121
start_fn = "test_mut_ref_chain",
123-
result = TestResult::SuccessWithValue(Value::from_type(15i32))
122+
result = TestResult::SuccessWithValue(vec![15, 0, 0, 0])
124123
);
125124

126125
check_custom_start!(
127126
test_basic_reference,
128127
input = "reference_test.rs",
129128
start_fn = "test_basic_ref",
130-
result = TestResult::SuccessWithValue(Value::from_type(42i32))
129+
result = TestResult::SuccessWithValue(vec![42, 0, 0, 0])
131130
);
132131

133132
#[cfg(target_endian = "little")]
134133
check_custom_start!(
135134
test_tuple_field_ref,
136135
input = "reference_test.rs",
137136
start_fn = "test_tuple_field_ref",
138-
result = TestResult::SuccessWithValue(Value::from_bytes(&[52, 10]))
137+
result = TestResult::SuccessWithValue(vec![52, 10])
139138
);
140139

141140
check_custom_start!(
@@ -149,7 +148,7 @@ check_custom_start!(
149148
test_tuple_field_sub,
150149
input = "tuple_operations.rs",
151150
start_fn = "tuple_field_sub",
152-
result = TestResult::SuccessWithValue(Value::from_type(42i8))
151+
result = TestResult::SuccessWithValue(vec![42])
153152
);
154153

155154
check_custom_start!(
@@ -163,7 +162,7 @@ check_custom_start!(
163162
test_ptr_compare,
164163
input = "raw_pointer_test.rs",
165164
start_fn = "ptr_compare",
166-
result = TestResult::SuccessWithValue(Value::from_bool(true))
165+
result = TestResult::SuccessWithValue(vec![1])
167166
);
168167

169168
check_custom_start!(
@@ -186,14 +185,14 @@ check_custom_start!(
186185
test_check_size_of,
187186
input = "size_align_test.rs",
188187
start_fn = "check_size_of",
189-
result = TestResult::SuccessWithValue(Value::from_bool(true))
188+
result = TestResult::SuccessWithValue(vec![1])
190189
);
191190

192191
check_custom_start!(
193192
test_check_align_of,
194193
input = "size_align_test.rs",
195194
start_fn = "check_align_of",
196-
result = TestResult::SuccessWithValue(Value::from_bool(true))
195+
result = TestResult::SuccessWithValue(vec![1])
197196
);
198197

199198
check_custom_start!(

0 commit comments

Comments
 (0)