Translate types and utilities tests
Some checks failed
Rust API gates / api-gates (push) Has been cancelled

This commit is contained in:
2026-08-08 17:11:04 +02:00
parent 8ddbac8eea
commit 7ac910d07c
12 changed files with 1744 additions and 977 deletions

View File

@@ -1,11 +1,34 @@
//! Shared deterministic fixtures used by translated compatibility tests.
use std::collections::BTreeMap;
use std::future::Future;
use std::io;
use std::path::{Component, Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll, Wake, Waker};
use std::time::Duration;
/// Runs one test future without choosing an async runtime for the library.
pub fn block_on<F: Future>(future: F) -> F::Output {
struct ThreadWake(std::thread::Thread);
impl Wake for ThreadWake {
fn wake(self: Arc<Self>) {
self.0.unpark();
}
}
let waker = Waker::from(Arc::new(ThreadWake(std::thread::current())));
let mut context = Context::from_waker(&waker);
let mut future = std::pin::pin!(future);
loop {
match future.as_mut().poll(&mut context) {
Poll::Ready(output) => return output,
Poll::Pending => std::thread::park(),
}
}
}
/// Asserts equality within the exact absolute tolerance carried by an upstream test.
///
/// # Panics
@@ -231,6 +254,7 @@ mod tests {
#[test]
fn deterministic_harness_covers_clock_network_and_bytes() {
assert_eq!(block_on(std::future::ready(7)), 7);
assert_close(1.001, 1.0, 0.01);
assert_bytes_eq(&decode_hex("00 ff 2A").unwrap(), &[0, 255, 42]);
assert!(decode_hex("é").is_err());