1 use byteorder::{BigEndian, ByteOrder};
4 use std::io::{self, BufRead};
7 // Check env var set by `build.rs`.
8 assert_eq!(env!("MIRITESTVAR"), "testval");
10 // Exercise external crate, printing to stdout.
11 let buf = &[1, 2, 3, 4];
12 let n = <BigEndian as ByteOrder>::read_u32(buf);
13 assert_eq!(n, 0x01020304);
14 println!("{:#010x}", n);
16 // Access program arguments, printing to stderr.
17 for arg in std::env::args() {
21 // If there were no arguments, access stdin and test working dir.
22 // (We rely on the test runner to always disable isolation when passing no arguments.)
23 if std::env::args().len() <= 1 {
24 // CWD should be crate root.
25 // We have to normalize slashes, as the env var might be set for a different target's conventions.
26 let env_dir = env::current_dir().unwrap();
27 let env_dir = env_dir.to_string_lossy().replace("\\", "/");
28 let crate_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
29 let crate_dir = crate_dir.to_string_lossy().replace("\\", "/");
30 assert_eq!(env_dir, crate_dir);
33 for line in io::stdin().lock().lines() {
34 let num: i32 = line.unwrap().parse().unwrap();
35 println!("{}", 2 * num);
37 // On non-Unix, reading from stdin is not supported. So we hard-code the right answer.
48 use byteorder_2::{BigEndian, ByteOrder};
50 // Make sure in-crate tests with dev-dependencies work
53 let _n = <BigEndian as ByteOrder>::read_u64(&[1, 2, 3, 4, 5, 6, 7, 8]);
57 fn exported_symbol() {
58 extern crate cargo_miri_test;
59 extern crate exported_symbol;
60 extern crate issue_rust_86261;
61 // Test calling exported symbols in (transitive) dependencies.
62 // Repeat calls to make sure the `Instance` cache is not broken.
65 fn exported_symbol() -> i32;
66 fn assoc_fn_as_exported_symbol() -> i32;
67 fn make_true() -> bool;
69 fn no_mangle_generic();
71 assert_eq!(unsafe { exported_symbol() }, 123456);
72 assert_eq!(unsafe { assoc_fn_as_exported_symbol() }, -123456);
73 assert!(unsafe { make_true() });
74 unsafe { NoMangleStruct() }
75 unsafe { no_mangle_generic() }