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.
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 rand::{Rng, SeedableRng};
50 // Make sure in-crate tests with dev-dependencies work
53 let mut rng = rand::rngs::StdRng::seed_from_u64(0xcafebeef);
54 let x: u32 = rng.gen();
55 let y: usize = rng.gen();
56 let z: u128 = rng.gen();
57 assert_ne!(x as usize, y);
58 assert_ne!(y as u128, z);