2014-02-23 17:08:46 +11:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-07-10 18:21:16 +02:00
|
|
|
use std::{char, os};
|
2014-05-05 14:33:55 -07:00
|
|
|
use std::io::{File, Command};
|
std: Recreate a `rand` module
This commit shuffles around some of the `rand` code, along with some
reorganization. The new state of the world is as follows:
* The librand crate now only depends on libcore. This interface is experimental.
* The standard library has a new module, `std::rand`. This interface will
eventually become stable.
Unfortunately, this entailed more of a breaking change than just shuffling some
names around. The following breaking changes were made to the rand library:
* Rng::gen_vec() was removed. This has been replaced with Rng::gen_iter() which
will return an infinite stream of random values. Previous behavior can be
regained with `rng.gen_iter().take(n).collect()`
* Rng::gen_ascii_str() was removed. This has been replaced with
Rng::gen_ascii_chars() which will return an infinite stream of random ascii
characters. Similarly to gen_iter(), previous behavior can be emulated with
`rng.gen_ascii_chars().take(n).collect()`
* {IsaacRng, Isaac64Rng, XorShiftRng}::new() have all been removed. These all
relied on being able to use an OSRng for seeding, but this is no longer
available in librand (where these types are defined). To retain the same
functionality, these types now implement the `Rand` trait so they can be
generated with a random seed from another random number generator. This allows
the stdlib to use an OSRng to create seeded instances of these RNGs.
* Rand implementations for `Box<T>` and `@T` were removed. These seemed to be
pretty rare in the codebase, and it allows for librand to not depend on
liballoc. Additionally, other pointer types like Rc<T> and Arc<T> were not
supported. If this is undesirable, librand can depend on liballoc and regain
these implementations.
* The WeightedChoice structure is no longer built with a `Vec<Weighted<T>>`,
but rather a `&mut [Weighted<T>]`. This means that the WeightedChoice
structure now has a lifetime associated with it.
* The `sample` method on `Rng` has been moved to a top-level function in the
`rand` module due to its dependence on `Vec`.
cc #13851
[breaking-change]
2014-05-25 01:39:37 -07:00
|
|
|
use std::rand::{task_rng, Rng};
|
2014-02-23 16:40:04 +11:00
|
|
|
|
|
|
|
// creates unicode_input_multiple_files_{main,chars}.rs, where the
|
|
|
|
// former imports the latter. `_chars` just contains an indentifier
|
|
|
|
// made up of random characters, because will emit an error message
|
|
|
|
// about the ident being in the wrong place, with a span (and creating
|
|
|
|
// this span used to upset the compiler).
|
|
|
|
|
|
|
|
fn random_char() -> char {
|
|
|
|
let mut rng = task_rng();
|
|
|
|
// a subset of the XID_start unicode table (ensuring that the
|
|
|
|
// compiler doesn't fail with an "unrecognised token" error)
|
2014-04-21 17:58:52 -04:00
|
|
|
let (lo, hi): (u32, u32) = match rng.gen_range(1u32, 4u32 + 1) {
|
2014-02-23 16:40:04 +11:00
|
|
|
1 => (0x41, 0x5a),
|
|
|
|
2 => (0xf8, 0x1ba),
|
|
|
|
3 => (0x1401, 0x166c),
|
|
|
|
_ => (0x10400, 0x1044f)
|
|
|
|
};
|
|
|
|
|
|
|
|
char::from_u32(rng.gen_range(lo, hi + 1)).unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args = os::args();
|
2014-05-04 13:20:47 -07:00
|
|
|
let rustc = args.get(1).as_slice();
|
|
|
|
let tmpdir = Path::new(args.get(2).as_slice());
|
2014-02-23 16:40:04 +11:00
|
|
|
|
|
|
|
let main_file = tmpdir.join("unicode_input_multiple_files_main.rs");
|
|
|
|
{
|
|
|
|
let _ = File::create(&main_file).unwrap()
|
|
|
|
.write_str("mod unicode_input_multiple_files_chars;");
|
|
|
|
}
|
|
|
|
|
2014-04-21 17:58:52 -04:00
|
|
|
for _ in range(0u, 100) {
|
2014-02-23 16:40:04 +11:00
|
|
|
{
|
2014-02-23 17:08:46 +11:00
|
|
|
let randoms = tmpdir.join("unicode_input_multiple_files_chars.rs");
|
|
|
|
let mut w = File::create(&randoms).unwrap();
|
2014-04-21 17:58:52 -04:00
|
|
|
for _ in range(0u, 30) {
|
2014-02-23 16:40:04 +11:00
|
|
|
let _ = w.write_char(random_char());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// rustc is passed to us with --out-dir and -L etc., so we
|
|
|
|
// can't exec it directly
|
2014-05-05 14:33:55 -07:00
|
|
|
let result = Command::new("sh")
|
2014-05-19 23:19:56 -07:00
|
|
|
.arg("-c")
|
|
|
|
.arg(format!("{} {}",
|
|
|
|
rustc,
|
|
|
|
main_file.as_str()
|
|
|
|
.unwrap()).as_slice())
|
2014-05-05 14:33:55 -07:00
|
|
|
.output().unwrap();
|
2014-07-10 18:21:16 +02:00
|
|
|
let err = String::from_utf8_lossy(result.error.as_slice());
|
2014-02-23 16:40:04 +11:00
|
|
|
|
|
|
|
// positive test so that this test will be updated when the
|
|
|
|
// compiler changes.
|
|
|
|
assert!(err.as_slice().contains("expected item but found"))
|
|
|
|
}
|
|
|
|
}
|