Skip to content

Commit fae78e3

Browse files
committed
refactor(tests): share array completion oracle
1 parent 9c34cc2 commit fae78e3

1 file changed

Lines changed: 4 additions & 27 deletions

File tree

tests/oracle_array_methods.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Keep the Array-method oracle implementations in separate modules so their
22
// private helpers remain isolated while Cargo builds one integration target.
33

4+
#[path = "support/quickjs_completion.rs"]
5+
mod quickjs_completion;
6+
47
mod support {
58
use std::ffi::OsStr;
6-
use std::process::Command;
79

810
use quickjs_oxide::{
911
CallableRef, CompleteOrdinaryPropertyDescriptor, Context, ObjectRef, Runtime, RuntimeError,
@@ -64,32 +66,7 @@ mod support {
6466
}
6567

6668
pub(super) fn observe_oracle(oracle: &OsStr, source: &str, description: &str) -> String {
67-
let wrapper = r#"
68-
try {
69-
var value = std.evalScript(scriptArgs[0]);
70-
print('return|' + typeof value + '|' + String(value));
71-
} catch (error) {
72-
if (error !== null && typeof error === 'object')
73-
print('throw|object|' + error.name + '|' + error.message);
74-
else
75-
print('throw|' + typeof error + '|' + String(error));
76-
}
77-
"#;
78-
let output = Command::new(oracle)
79-
.args(["--std", "-e", wrapper, source])
80-
.output()
81-
.unwrap_or_else(|error| panic!("could not run QuickJS for {description}: {error}"));
82-
assert!(
83-
output.status.success(),
84-
"QuickJS observer failed for {description}: {}",
85-
String::from_utf8_lossy(&output.stderr),
86-
);
87-
String::from_utf8(output.stdout)
88-
.unwrap_or_else(|error| {
89-
panic!("QuickJS output was not UTF-8 for {description}: {error}")
90-
})
91-
.trim_end()
92-
.to_owned()
69+
super::quickjs_completion::observe(oracle, source, description)
9370
}
9471

9572
pub(super) fn data_descriptor_bits(descriptor: &CompleteOrdinaryPropertyDescriptor) -> String {

0 commit comments

Comments
 (0)