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.
11 use std::{char, os, str};
12 use std::io::{File, Command};
13 use std::rand::{task_rng, Rng};
15 // creates unicode_input_multiple_files_{main,chars}.rs, where the
16 // former imports the latter. `_chars` just contains an indentifier
17 // made up of random characters, because will emit an error message
18 // about the ident being in the wrong place, with a span (and creating
19 // this span used to upset the compiler).
21 fn random_char() -> char {
22 let mut rng = task_rng();
23 // a subset of the XID_start unicode table (ensuring that the
24 // compiler doesn't fail with an "unrecognised token" error)
25 let (lo, hi): (u32, u32) = match rng.gen_range(1, 4 + 1) {
28 3 => (0x1401, 0x166c),
29 _ => (0x10400, 0x1044f)
32 char::from_u32(rng.gen_range(lo, hi + 1)).unwrap()
36 let args = os::args();
37 let rustc = args.get(1).as_slice();
38 let tmpdir = Path::new(args.get(2).as_slice());
40 let main_file = tmpdir.join("unicode_input_multiple_files_main.rs");
42 let _ = File::create(&main_file).unwrap()
43 .write_str("mod unicode_input_multiple_files_chars;");
46 for _ in range(0, 100) {
48 let randoms = tmpdir.join("unicode_input_multiple_files_chars.rs");
49 let mut w = File::create(&randoms).unwrap();
50 for _ in range(0, 30) {
51 let _ = w.write_char(random_char());
55 // rustc is passed to us with --out-dir and -L etc., so we
56 // can't exec it directly
57 let result = Command::new("sh")
62 .unwrap()).as_slice())
64 let err = str::from_utf8_lossy(result.error.as_slice());
66 // positive test so that this test will be updated when the
68 assert!(err.as_slice().contains("expected item but found"))