summary refs log tree commit diff
path: root/tests/run-make/stdin-rustc/rmake.rs
blob: c07a6df4d84a20c14b4c16f98922f9e263739514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//! This test checks rustc `-` (stdin) support

use run_make_support::{is_windows, rustc, tmp_dir};

const HELLO_WORLD: &str = r#"
fn main() {
    println!("Hello world!");
}
"#;

const NOT_UTF8: &[u8] = &[0xff, 0xff, 0xff];

fn main() {
    let out_dir = tmp_dir();

    // echo $HELLO_WORLD | rustc -
    rustc().arg("-").stdin(HELLO_WORLD).run();
    assert!(
        out_dir.join(if !is_windows() { "rust_out" } else { "rust_out.exe" }).try_exists().unwrap()
    );

    // echo $NOT_UTF8 | rustc -
    let output = rustc().arg("-").stdin(NOT_UTF8).run_fail();
    let stderr = String::from_utf8(output.stderr).unwrap();
    assert!(stderr.contains("error: couldn't read from stdin, as it did not contain valid UTF-8"));
}