mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #1143 from Arcterus/containers
Fix tests when using containers
This commit is contained in:
commit
3969b431a9
6 changed files with 311 additions and 253 deletions
456
Cargo.lock
generated
456
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -252,6 +252,7 @@ unindent = "0.1.0"
|
||||||
lazy_static = "0.2.2"
|
lazy_static = "0.2.2"
|
||||||
|
|
||||||
[target.'cfg(unix)'.dev-dependencies]
|
[target.'cfg(unix)'.dev-dependencies]
|
||||||
|
rust-users = { git = "https://github.com/uutils/rust-users" }
|
||||||
unix_socket = "0.5.0"
|
unix_socket = "0.5.0"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -18,8 +18,11 @@ mod platform {
|
||||||
fn main() {
|
fn main() {
|
||||||
mkmain::main();
|
mkmain::main();
|
||||||
|
|
||||||
|
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("Could not find manifest dir");
|
||||||
|
let profile = env::var("PROFILE").expect("Could not determine profile");
|
||||||
|
|
||||||
let out_dir = env::var("OUT_DIR").unwrap();
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
let libstdbuf = format!("{}/../../{}/{}/deps/liblibstdbuf{}", env::var("CARGO_MANIFEST_DIR").unwrap(), env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string()), env::var("PROFILE").unwrap(), platform::DYLIB_EXT);
|
let libstdbuf = format!("{}/../../{}/{}/deps/liblibstdbuf{}", manifest_dir, env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string()), profile, platform::DYLIB_EXT);
|
||||||
|
|
||||||
fs::copy(libstdbuf, Path::new(&out_dir).join("libstdbuf.so")).unwrap();
|
fs::copy(libstdbuf, Path::new(&out_dir).join("libstdbuf.so")).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,7 +200,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
exit!(1);
|
exit!(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let who = Who {
|
let mut who = Who {
|
||||||
do_lookup: do_lookup,
|
do_lookup: do_lookup,
|
||||||
short_list: short_list,
|
short_list: short_list,
|
||||||
short_output: short_output,
|
short_output: short_output,
|
||||||
|
@ -216,6 +216,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
need_runlevel: need_runlevel,
|
need_runlevel: need_runlevel,
|
||||||
need_users: need_users,
|
need_users: need_users,
|
||||||
my_line_only: my_line_only,
|
my_line_only: my_line_only,
|
||||||
|
has_records: false,
|
||||||
args: matches.free,
|
args: matches.free,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -240,6 +241,7 @@ struct Who {
|
||||||
need_runlevel: bool,
|
need_runlevel: bool,
|
||||||
need_users: bool,
|
need_users: bool,
|
||||||
my_line_only: bool,
|
my_line_only: bool,
|
||||||
|
has_records: bool,
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +284,7 @@ fn current_tty() -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Who {
|
impl Who {
|
||||||
fn exec(&self) {
|
fn exec(&mut self) {
|
||||||
let f = if self.args.len() == 1 {
|
let f = if self.args.len() == 1 {
|
||||||
self.args[0].as_ref()
|
self.args[0].as_ref()
|
||||||
} else {
|
} else {
|
||||||
|
@ -297,6 +299,9 @@ impl Who {
|
||||||
println!("{}", users.join(" "));
|
println!("{}", users.join(" "));
|
||||||
println!("# users={}", users.len());
|
println!("# users={}", users.len());
|
||||||
} else {
|
} else {
|
||||||
|
let mut records = Utmpx::iter_all_records().read_from(f).peekable();
|
||||||
|
self.has_records = records.peek().is_some();
|
||||||
|
|
||||||
if self.include_heading {
|
if self.include_heading {
|
||||||
self.print_heading()
|
self.print_heading()
|
||||||
}
|
}
|
||||||
|
@ -306,7 +311,7 @@ impl Who {
|
||||||
"".to_owned()
|
"".to_owned()
|
||||||
};
|
};
|
||||||
|
|
||||||
for ut in Utmpx::iter_all_records().read_from(f) {
|
for ut in records {
|
||||||
if !self.my_line_only || cur_tty == ut.tty_device() {
|
if !self.my_line_only || cur_tty == ut.tty_device() {
|
||||||
if self.need_users && ut.is_user_process() {
|
if self.need_users && ut.is_user_process() {
|
||||||
self.print_user(&ut);
|
self.print_user(&ut);
|
||||||
|
@ -486,7 +491,11 @@ impl Who {
|
||||||
}
|
}
|
||||||
buf.push_str(&format!(" {:<12}", line));
|
buf.push_str(&format!(" {:<12}", line));
|
||||||
// "%Y-%m-%d %H:%M"
|
// "%Y-%m-%d %H:%M"
|
||||||
buf.push_str(&format!(" {:<1$}", time, 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2));
|
let mut time_size = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2;
|
||||||
|
if !self.has_records {
|
||||||
|
time_size -= 4;
|
||||||
|
}
|
||||||
|
buf.push_str(&format!(" {:<1$}", time, time_size));
|
||||||
|
|
||||||
if !self.short_output {
|
if !self.short_output {
|
||||||
if self.include_idle {
|
if self.include_idle {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use common::util::*;
|
use common::util::*;
|
||||||
|
use rust_users::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_option() {
|
fn test_invalid_option() {
|
||||||
|
@ -14,30 +14,34 @@ static DIR: &'static str = "/tmp";
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_group() {
|
fn test_invalid_group() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.arg("nosuchgroup")
|
.arg("__nosuchgroup__")
|
||||||
.arg("/")
|
.arg("/")
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_is("chgrp: invalid group: nosuchgroup");
|
.stderr_is("chgrp: invalid group: __nosuchgroup__");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_1() {
|
fn test_1() {
|
||||||
new_ucmd!()
|
if get_effective_gid() != 0 {
|
||||||
.arg("bin")
|
new_ucmd!()
|
||||||
.arg(DIR)
|
.arg("bin")
|
||||||
.fails()
|
.arg(DIR)
|
||||||
.stderr_is("chgrp: changing group of '/tmp': Operation not permitted (os error 1)");
|
.fails()
|
||||||
|
.stderr_is("chgrp: changing group of '/tmp': Operation not permitted (os error 1)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fail_silently() {
|
fn test_fail_silently() {
|
||||||
for opt in &["-f", "--silent", "--quiet"] {
|
if get_effective_gid() != 0 {
|
||||||
new_ucmd!()
|
for opt in &["-f", "--silent", "--quiet"] {
|
||||||
.arg(opt)
|
new_ucmd!()
|
||||||
.arg("bin")
|
.arg(opt)
|
||||||
.arg(DIR)
|
.arg("bin")
|
||||||
.run()
|
.arg(DIR)
|
||||||
.fails_silently();
|
.run()
|
||||||
|
.fails_silently();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,13 +98,15 @@ fn test_preserve_root_symlink() {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn test_reference() {
|
fn test_reference() {
|
||||||
new_ucmd!()
|
if get_effective_gid() != 0 {
|
||||||
.arg("-v")
|
new_ucmd!()
|
||||||
.arg("--reference=/etc/passwd")
|
.arg("-v")
|
||||||
.arg("/etc")
|
.arg("--reference=/etc/passwd")
|
||||||
.fails()
|
.arg("/etc")
|
||||||
.stderr_is("chgrp: changing group of '/etc': Operation not permitted (os error 1)\n")
|
.fails()
|
||||||
.stdout_is("failed to change group of /etc from root to root\n");
|
.stderr_is("chgrp: changing group of '/etc': Operation not permitted (os error 1)\n")
|
||||||
|
.stdout_is("failed to change group of /etc from root to root\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -116,23 +122,27 @@ fn test_reference() {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn test_big_p() {
|
fn test_big_p() {
|
||||||
new_ucmd!()
|
if get_effective_gid() != 0 {
|
||||||
.arg("-RP")
|
new_ucmd!()
|
||||||
.arg("bin")
|
.arg("-RP")
|
||||||
.arg("/proc/self/cwd")
|
.arg("bin")
|
||||||
.fails()
|
.arg("/proc/self/cwd")
|
||||||
.stderr_is("chgrp: changing group of '/proc/self/cwd': Operation not permitted (os error 1)\n");
|
.fails()
|
||||||
|
.stderr_is("chgrp: changing group of '/proc/self/cwd': Operation not permitted (os error 1)\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn test_big_h() {
|
fn test_big_h() {
|
||||||
assert!(new_ucmd!()
|
if get_effective_gid() != 0 {
|
||||||
.arg("-RH")
|
assert!(new_ucmd!()
|
||||||
.arg("bin")
|
.arg("-RH")
|
||||||
.arg("/proc/self/fd")
|
.arg("bin")
|
||||||
.fails()
|
.arg("/proc/self/fd")
|
||||||
.stderr
|
.fails()
|
||||||
.lines()
|
.stderr
|
||||||
.fold(0, |acc, _| acc + 1) > 1);
|
.lines()
|
||||||
|
.fold(0, |acc, _| acc + 1) > 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,9 @@ mod common;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
extern crate rust_users;
|
||||||
|
|
||||||
// For conditional compilation
|
// For conditional compilation
|
||||||
macro_rules! unix_only {
|
macro_rules! unix_only {
|
||||||
($($fea:expr, $m:ident);+) => {
|
($($fea:expr, $m:ident);+) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue