Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit 04dce2d

Browse files
committed
fix & add tests
1 parent 320e9aa commit 04dce2d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/lib.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,41 @@ mod tests {
273273

274274
use super::*;
275275

276+
/// Validate the version and return out with the first line (version) removed
277+
fn validate_and_remove_version<'a>(out: &'a [u8], expected: Option<&str>) -> &'a [u8] {
278+
let mut split = out.splitn(2, |&b| b == b'\n');
279+
let version = split.next().unwrap();
280+
let out = split.next().unwrap();
281+
282+
assert!(version.starts_with(b"rustc "));
283+
284+
if let Some(expectation) = expected {
285+
assert!(String::from_utf8_lossy(version).contains(expectation));
286+
}
287+
288+
out
289+
}
290+
291+
#[test]
292+
fn versions() {
293+
fn check(chan: ReleaseChannel, expectation: Option<&str>) {
294+
let cache = Cache::new();
295+
let input = r#"fn main() {}"#;
296+
297+
let (status, out) = cache.exec(chan, "/usr/local/bin/evaluate.sh",
298+
vec![], vec![], input.into()).unwrap();
299+
300+
assert!(status.success());
301+
validate_and_remove_version(&out.as_ref(), expectation);
302+
}
303+
304+
drop(env_logger::init());
305+
306+
check(ReleaseChannel::Stable, None);
307+
check(ReleaseChannel::Beta, Some("-beta"));
308+
check(ReleaseChannel::Nightly, Some("-nightly"));
309+
}
310+
276311
#[test]
277312
fn eval() {
278313
drop(env_logger::init());
@@ -285,6 +320,7 @@ mod tests {
285320
Vec::new(),
286321
input.to_string()).unwrap();
287322
assert!(status.success());
323+
let out = validate_and_remove_version(&out.as_ref(), None);
288324
assert_eq!(out, &[0xff, b'H', b'e', b'l', b'l', b'o', b'\n']);
289325
}
290326

@@ -320,6 +356,7 @@ mod tests {
320356
input.to_string()).unwrap();
321357

322358
assert!(status.success());
359+
let out = validate_and_remove_version(&out, None);
323360
let mut split = out.splitn(2, |b| *b == b'\xff');
324361
let empty: &[u8] = &[];
325362
assert_eq!(split.next().unwrap(), empty);

0 commit comments

Comments
 (0)