coreutils/test/readlink.rs

81 lines
1.9 KiB
Rust
Raw Normal View History

2015-05-12 21:09:41 +00:00
use std::process::Command;
use std::str;
2015-06-04 04:04:10 +00:00
use util::*;
2015-05-12 21:09:41 +00:00
static PROGNAME: &'static str = "./readlink";
static GIBBERISH: &'static str = "supercalifragilisticexpialidocious";
2015-06-04 04:04:10 +00:00
#[path = "common/util.rs"]
#[macro_use]
mod util;
2015-05-12 21:09:41 +00:00
#[test]
fn test_canonicalize() {
let po = Command::new(PROGNAME)
.arg("-f")
.arg(".")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
assert_eq!(out, current_directory());
}
#[test]
fn test_canonicalize_existing() {
let po = Command::new(PROGNAME)
.arg("-e")
.arg(".")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
assert_eq!(out, current_directory());
}
#[test]
fn test_canonicalize_missing() {
let mut expected = current_directory();
expected.push_str("/");
expected.push_str(GIBBERISH);
let po = Command::new(PROGNAME)
.arg("-m")
.arg(GIBBERISH)
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
assert_eq!(out, expected);
}
#[test]
fn test_long_redirection_to_current_dir() {
// Create a 256-character path to current directory
let dir = repeat_str("./", 128);
let po = Command::new(PROGNAME)
.arg("-n")
.arg("-m")
.arg(dir)
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, current_directory());
}
#[test]
fn test_long_redirection_to_root() {
// Create a 255-character path to root
let dir = repeat_str("../", 85);
let po = Command::new(PROGNAME)
.arg("-n")
.arg("-m")
.arg(dir)
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "/");
}