mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Add tests for readlink.
This commit is contained in:
parent
b2063d6d73
commit
481fdd744a
2 changed files with 89 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -172,6 +172,7 @@ TEST_PROGS := \
|
||||||
nl \
|
nl \
|
||||||
paste \
|
paste \
|
||||||
pwd \
|
pwd \
|
||||||
|
readlink \
|
||||||
seq \
|
seq \
|
||||||
sort \
|
sort \
|
||||||
split \
|
split \
|
||||||
|
|
88
test/readlink.rs
Normal file
88
test/readlink.rs
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
use std::env;
|
||||||
|
use std::process::Command;
|
||||||
|
use std::str;
|
||||||
|
|
||||||
|
static PROGNAME: &'static str = "./readlink";
|
||||||
|
static GIBBERISH: &'static str = "supercalifragilisticexpialidocious";
|
||||||
|
|
||||||
|
fn current_directory() -> String {
|
||||||
|
env::current_dir().unwrap().into_os_string().into_string().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn repeat_str(s: &str, n: u32) -> String {
|
||||||
|
let mut repeated = String::new();
|
||||||
|
for _ in 0 .. n {
|
||||||
|
repeated.push_str(s);
|
||||||
|
}
|
||||||
|
repeated
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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, "/");
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue