2015-11-16 05:25:01 +00:00
|
|
|
use common::util::*;
|
|
|
|
|
|
|
|
static UTIL_NAME: &'static str = "readlink";
|
2016-07-29 21:26:32 +00:00
|
|
|
fn at_and_ucmd() -> (AtPath, UCommand) {
|
|
|
|
let ts = TestScenario::new(UTIL_NAME);
|
|
|
|
let ucmd = ts.ucmd();
|
|
|
|
(ts.fixtures, ucmd)
|
|
|
|
}
|
|
|
|
fn new_ucmd() -> UCommand {
|
|
|
|
TestScenario::new(UTIL_NAME).ucmd()
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
static GIBBERISH: &'static str = "supercalifragilisticexpialidocious";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_canonicalize() {
|
2016-07-29 21:26:32 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd();
|
2015-11-16 05:25:01 +00:00
|
|
|
let out = ucmd.arg("-f")
|
|
|
|
.arg(".")
|
|
|
|
.run()
|
|
|
|
.stdout;
|
|
|
|
|
2016-01-10 10:47:57 +00:00
|
|
|
assert_eq!(out.trim_right(), at.root_dir_resolved());
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_canonicalize_existing() {
|
2016-07-29 21:26:32 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd();
|
2015-11-16 05:25:01 +00:00
|
|
|
let out = ucmd.arg("-e")
|
|
|
|
.arg(".")
|
|
|
|
.run()
|
|
|
|
.stdout;
|
|
|
|
|
2016-01-10 10:47:57 +00:00
|
|
|
assert_eq!(out.trim_right(), at.root_dir_resolved());
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_canonicalize_missing() {
|
2016-07-29 21:26:32 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd();
|
2016-03-29 01:06:31 +00:00
|
|
|
let expected = path_concat!(at.root_dir_resolved(), GIBBERISH);
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
let out = ucmd.arg("-m")
|
|
|
|
.arg(GIBBERISH)
|
|
|
|
.run()
|
|
|
|
.stdout;
|
|
|
|
|
2016-01-10 10:47:57 +00:00
|
|
|
assert_eq!(out.trim_right(), expected);
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_long_redirection_to_current_dir() {
|
2016-07-29 21:26:32 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd();
|
2015-11-16 05:25:01 +00:00
|
|
|
// Create a 256-character path to current directory
|
2016-03-29 01:06:31 +00:00
|
|
|
let dir = path_concat!(".", ..128);
|
2015-11-16 05:25:01 +00:00
|
|
|
let out = ucmd.arg("-n")
|
|
|
|
.arg("-m")
|
|
|
|
.arg(dir)
|
|
|
|
.run()
|
|
|
|
.stdout;
|
|
|
|
|
2016-01-10 10:47:57 +00:00
|
|
|
assert_eq!(out, at.root_dir_resolved());
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_long_redirection_to_root() {
|
|
|
|
// Create a 255-character path to root
|
2016-03-29 01:06:31 +00:00
|
|
|
let dir = path_concat!("..", ..85);
|
2016-07-29 21:26:32 +00:00
|
|
|
let out = new_ucmd()
|
|
|
|
.arg("-n")
|
2015-11-16 05:25:01 +00:00
|
|
|
.arg("-m")
|
|
|
|
.arg(dir)
|
|
|
|
.run()
|
|
|
|
.stdout;
|
|
|
|
|
2016-03-29 01:06:31 +00:00
|
|
|
assert_eq!(out, get_root_path());
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|