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.
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.
12 use rand::{task_rng, Rng};
14 use std::{char, os, str};
15 use std::io::{File, Process};
17 // creates unicode_input_multiple_files_{main,chars}.rs, where the
18 // former imports the latter. `_chars` just contains an indentifier
19 // made up of random characters, because will emit an error message
20 // about the ident being in the wrong place, with a span (and creating
21 // this span used to upset the compiler).
23 fn random_char() -> char {
24 let mut rng = task_rng();
25 // a subset of the XID_start unicode table (ensuring that the
26 // compiler doesn't fail with an "unrecognised token" error)
27 let (lo, hi): (u32, u32) = match rng.gen_range(1, 4 + 1) {
30 3 => (0x1401, 0x166c),
31 _ => (0x10400, 0x1044f)
34 char::from_u32(rng.gen_range(lo, hi + 1)).unwrap()
38 let args = os::args();
39 let rustc = args[1].as_slice();
40 let tmpdir = Path::new(args[2].as_slice());
42 let main_file = tmpdir.join("unicode_input_multiple_files_main.rs");
43 let main_file_str = main_file.as_str().unwrap();
45 let _ = File::create(&main_file).unwrap()
46 .write_str("mod unicode_input_multiple_files_chars;");
49 for _ in range(0, 100) {
51 let randoms = tmpdir.join("unicode_input_multiple_files_chars.rs");
52 let mut w = File::create(&randoms).unwrap();
53 for _ in range(0, 30) {
54 let _ = w.write_char(random_char());
58 // rustc is passed to us with --out-dir and -L etc., so we
59 // can't exec it directly
60 let result = Process::output("sh", ["-c".to_owned(), rustc + " " + main_file_str]).unwrap();
61 let err = str::from_utf8_lossy(result.error.as_slice());
63 // positive test so that this test will be updated when the
65 assert!(err.as_slice().contains("expected item but found"))