Skip to content

Commit ee31775

Browse files
committed
refactor(tests): share plain oracle line transport
1 parent 9d81688 commit ee31775

5 files changed

Lines changed: 10 additions & 108 deletions

File tree

tests/oracle/object/oracle_objects.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use std::ffi::OsStr;
2-
use std::process::Command;
3-
41
use quickjs_oxide::{
52
CompleteOrdinaryPropertyDescriptor, Context, DescriptorField, JsString,
63
OrdinaryPropertyDescriptor, PropertyKey, Runtime, Value, WellKnownSymbol,
@@ -89,7 +86,10 @@ fn ordinary_object_core_matches_quickjs_oracle() {
8986
eprintln!("SKIP object oracle differential: set QJS_ORACLE to upstream qjs");
9087
return;
9188
};
92-
assert_eq!(rust_observations(), oracle_observations(&oracle));
89+
assert_eq!(
90+
rust_observations(),
91+
super::quickjs_oracle::eval_std_lines(&oracle, ORACLE_PROBE, "ordinary object core",)
92+
);
9393
}
9494

9595
fn rust_observations() -> Vec<String> {
@@ -304,24 +304,6 @@ fn rust_observations() -> Vec<String> {
304304
output
305305
}
306306

307-
fn oracle_observations(oracle: &OsStr) -> Vec<String> {
308-
let output = Command::new(oracle)
309-
.args(["-e", ORACLE_PROBE])
310-
.output()
311-
.unwrap_or_else(|error| panic!("could not run object oracle: {error}"));
312-
assert!(
313-
output.status.success(),
314-
"object oracle failed with {}:\n{}",
315-
output.status,
316-
String::from_utf8_lossy(&output.stderr)
317-
);
318-
String::from_utf8(output.stdout)
319-
.expect("object oracle emitted UTF-8")
320-
.lines()
321-
.map(str::to_owned)
322-
.collect()
323-
}
324-
325307
fn set(
326308
context: &mut Context,
327309
runtime: &Runtime,

tests/oracle/string/oracle_string_conversion_core.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use std::ffi::OsStr;
2-
use std::process::Command;
3-
41
use quickjs_oxide::{
52
AccessorValue, CallableRef, CompleteOrdinaryPropertyDescriptor, Context, DescriptorField,
63
JsString, ObjectRef, OrdinaryPropertyDescriptor, PropertyKey, Runtime, RuntimeError, Value,
@@ -117,7 +114,7 @@ fn string_conversion_core_matches_pinned_quickjs() {
117114
};
118115
assert_eq!(
119116
rust_observations(),
120-
oracle_observations(&oracle),
117+
super::quickjs_oracle::eval_std_lines(&oracle, ORACLE_PROBE, "String conversion-core",),
121118
"String conversion-core behavior differed from pinned QuickJS"
122119
);
123120
}
@@ -654,20 +651,3 @@ fn hex(value: &JsString) -> String {
654651
.map(|unit| format!("{unit:04x}"))
655652
.collect()
656653
}
657-
658-
fn oracle_observations(oracle: &OsStr) -> Vec<String> {
659-
let output = Command::new(oracle)
660-
.args(["-e", ORACLE_PROBE])
661-
.output()
662-
.expect("run QuickJS String conversion-core oracle");
663-
assert!(
664-
output.status.success(),
665-
"QuickJS String conversion-core oracle failed: {}",
666-
String::from_utf8_lossy(&output.stderr)
667-
);
668-
String::from_utf8(output.stdout)
669-
.expect("QuickJS String conversion-core oracle emitted non-UTF-8 output")
670-
.lines()
671-
.map(str::to_owned)
672-
.collect()
673-
}

tests/oracle/string/oracle_string_exotic.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use std::ffi::OsStr;
2-
use std::process::Command;
3-
41
use quickjs_oxide::{
52
AccessorValue, CallableRef, CompleteOrdinaryPropertyDescriptor, Context, DescriptorField,
63
JsString, ObjectRef, OrdinaryPropertyDescriptor, PropertyKey, Runtime, Value,
@@ -132,7 +129,7 @@ fn string_wrapper_exotic_matches_pinned_quickjs() {
132129
};
133130
assert_eq!(
134131
rust,
135-
oracle_observations(&oracle),
132+
super::quickjs_oracle::eval_std_lines(&oracle, ORACLE_PROBE, "String exotic object"),
136133
"String wrapper exotic behavior differed from pinned QuickJS"
137134
);
138135
}
@@ -632,20 +629,3 @@ fn render_value(value: &Value) -> String {
632629
.expect("String exotic observation must stringify")
633630
.to_utf8_lossy()
634631
}
635-
636-
fn oracle_observations(oracle: &OsStr) -> Vec<String> {
637-
let output = Command::new(oracle)
638-
.args(["-e", ORACLE_PROBE])
639-
.output()
640-
.expect("run QuickJS String exotic oracle");
641-
assert!(
642-
output.status.success(),
643-
"QuickJS String exotic oracle failed: {}",
644-
String::from_utf8_lossy(&output.stderr)
645-
);
646-
String::from_utf8(output.stdout)
647-
.expect("QuickJS String exotic oracle emitted non-UTF-8 output")
648-
.lines()
649-
.map(str::to_owned)
650-
.collect()
651-
}

tests/oracle/string/oracle_string_rope.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use std::ffi::OsStr;
2-
use std::process::Command;
3-
41
use quickjs_oxide::{
52
CallableRef, Context, DescriptorField, JsString, ObjectRef, OrdinaryPropertyDescriptor,
63
Runtime, RuntimeError, Value,
@@ -133,7 +130,8 @@ fn string_rope_matches_pinned_quickjs() {
133130
};
134131

135132
let rust = rust_observations();
136-
let upstream = oracle_observations(&oracle);
133+
let source = format!("{ORACLE_SETUP}\nprint({PROBE});");
134+
let upstream = super::quickjs_oracle::eval_std_lines(&oracle, &source, "String rope semantics");
137135
assert_eq!(rust.len(), 6, "Rust String rope probe breadth changed");
138136
assert_eq!(
139137
upstream.len(),
@@ -500,22 +498,3 @@ fn error_string(
500498
};
501499
value
502500
}
503-
504-
fn oracle_observations(oracle: &OsStr) -> Vec<String> {
505-
let source = format!("{ORACLE_SETUP}\nprint({PROBE});");
506-
let output = Command::new(oracle)
507-
.arg("-e")
508-
.arg(source)
509-
.output()
510-
.expect("run QuickJS String rope oracle");
511-
assert!(
512-
output.status.success(),
513-
"QuickJS String rope oracle failed: {}",
514-
String::from_utf8_lossy(&output.stderr)
515-
);
516-
String::from_utf8(output.stdout)
517-
.expect("QuickJS String rope oracle emitted non-UTF-8 output")
518-
.lines()
519-
.map(str::to_owned)
520-
.collect()
521-
}

tests/oracle/string/oracle_string_utf16_prefix.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use std::ffi::OsStr;
2-
use std::process::Command;
3-
41
use quickjs_oxide::{
52
CallableRef, CompleteOrdinaryPropertyDescriptor, Context, DescriptorField, JsBigInt, JsString,
63
ObjectRef, OrdinaryPropertyDescriptor, PropertyKey, Runtime, RuntimeError, Value,
@@ -137,7 +134,8 @@ fn string_utf16_prefix_matches_pinned_quickjs() {
137134
return;
138135
};
139136
let rust = rust_observations();
140-
let upstream = oracle_observations(&oracle);
137+
let upstream =
138+
super::quickjs_oracle::eval_std_lines(&oracle, ORACLE_PROBE, "String UTF-16 prefix");
141139
assert_eq!(rust.len(), 11, "Rust probe breadth changed unexpectedly");
142140
assert_eq!(
143141
upstream.len(),
@@ -862,20 +860,3 @@ fn hex(value: &JsString) -> String {
862860
.map(|unit| format!("{unit:04x}"))
863861
.collect()
864862
}
865-
866-
fn oracle_observations(oracle: &OsStr) -> Vec<String> {
867-
let output = Command::new(oracle)
868-
.args(["-e", ORACLE_PROBE])
869-
.output()
870-
.expect("run QuickJS String UTF-16 prefix oracle");
871-
assert!(
872-
output.status.success(),
873-
"QuickJS String UTF-16 prefix oracle failed: {}",
874-
String::from_utf8_lossy(&output.stderr)
875-
);
876-
String::from_utf8(output.stdout)
877-
.expect("QuickJS String UTF-16 prefix oracle emitted non-UTF-8 output")
878-
.lines()
879-
.map(str::to_owned)
880-
.collect()
881-
}

0 commit comments

Comments
 (0)