]> git.lizzy.rs Git - rust.git/blob - src/test/run-make/unicode-input/multiple_files.rs
3711503ee2b590889380d019d74225d55cb583f5
[rust.git] / src / test / run-make / unicode-input / multiple_files.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 use std::{char, os, str};
12 use std::io::{File, Command};
13 use std::rand::{task_rng, Rng};
14
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).
20
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) {
26         1 => (0x41, 0x5a),
27         2 => (0xf8, 0x1ba),
28         3 => (0x1401, 0x166c),
29         _ => (0x10400, 0x1044f)
30     };
31
32     char::from_u32(rng.gen_range(lo, hi + 1)).unwrap()
33 }
34
35 fn main() {
36     let args = os::args();
37     let rustc = args.get(1).as_slice();
38     let tmpdir = Path::new(args.get(2).as_slice());
39
40     let main_file = tmpdir.join("unicode_input_multiple_files_main.rs");
41     {
42         let _ = File::create(&main_file).unwrap()
43             .write_str("mod unicode_input_multiple_files_chars;");
44     }
45
46     for _ in range(0, 100) {
47         {
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());
52             }
53         }
54
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")
58                              .arg("-c")
59                              .arg(format!("{} {}",
60                                           rustc,
61                                           main_file.as_str()
62                                                    .unwrap()).as_slice())
63                              .output().unwrap();
64         let err = str::from_utf8_lossy(result.error.as_slice());
65
66         // positive test so that this test will be updated when the
67         // compiler changes.
68         assert!(err.as_slice().contains("expected item but found"))
69     }
70 }