]> git.proxmox.com Git - rustc.git/blob - src/test/run-make/cannot-read-embedded-idents/create_and_compile.rs
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / test / run-make / cannot-read-embedded-idents / create_and_compile.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(old_io, old_path)]
12
13 use std::env;
14 use std::fs::File;
15 use std::process::Command;
16 use std::io::Write;
17 use std::path::Path;
18
19 // creates broken.rs, which has the Ident \x00name_0,ctxt_0\x00
20 // embedded within it, and then attempts to compile broken.rs with the
21 // provided `rustc`
22
23 fn main() {
24 let args: Vec<String> = env::args().collect();
25 let rustc = &args[1];
26 let tmpdir = Path::new(&args[2]);
27
28 let main_file = tmpdir.join("broken.rs");
29 let _ = File::create(&main_file).unwrap()
30 .write_all(b"pub fn main() {
31 let \x00name_0,ctxt_0\x00 = 3;
32 println!(\"{}\", \x00name_0,ctxt_0\x00);
33 }").unwrap();
34
35 // rustc is passed to us with --out-dir and -L etc., so we
36 // can't exec it directly
37 let result = Command::new("sh")
38 .arg("-c")
39 .arg(&format!("{} {}", rustc, main_file.display()))
40 .output().unwrap();
41 let err = String::from_utf8_lossy(&result.stderr);
42
43 // positive test so that this test will be updated when the
44 // compiler changes.
45 assert!(err.contains("unknown start of token"))
46 }