mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +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"
|
||||
|
||||
[target.'cfg(unix)'.dev-dependencies]
|
||||
rust-users = { git = "https://github.com/uutils/rust-users" }
|
||||
unix_socket = "0.5.0"
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -18,8 +18,11 @@ mod platform {
|
|||
fn 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 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();
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
exit!(1);
|
||||
}
|
||||
|
||||
let who = Who {
|
||||
let mut who = Who {
|
||||
do_lookup: do_lookup,
|
||||
short_list: short_list,
|
||||
short_output: short_output,
|
||||
|
@ -216,6 +216,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
need_runlevel: need_runlevel,
|
||||
need_users: need_users,
|
||||
my_line_only: my_line_only,
|
||||
has_records: false,
|
||||
args: matches.free,
|
||||
};
|
||||
|
||||
|
@ -240,6 +241,7 @@ struct Who {
|
|||
need_runlevel: bool,
|
||||
need_users: bool,
|
||||
my_line_only: bool,
|
||||
has_records: bool,
|
||||
args: Vec<String>,
|
||||
}
|
||||
|
||||
|
@ -282,7 +284,7 @@ fn current_tty() -> String {
|
|||
}
|
||||
|
||||
impl Who {
|
||||
fn exec(&self) {
|
||||
fn exec(&mut self) {
|
||||
let f = if self.args.len() == 1 {
|
||||
self.args[0].as_ref()
|
||||
} else {
|
||||
|
@ -297,6 +299,9 @@ impl Who {
|
|||
println!("{}", users.join(" "));
|
||||
println!("# users={}", users.len());
|
||||
} else {
|
||||
let mut records = Utmpx::iter_all_records().read_from(f).peekable();
|
||||
self.has_records = records.peek().is_some();
|
||||
|
||||
if self.include_heading {
|
||||
self.print_heading()
|
||||
}
|
||||
|
@ -306,7 +311,7 @@ impl Who {
|
|||
"".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.need_users && ut.is_user_process() {
|
||||
self.print_user(&ut);
|
||||
|
@ -486,7 +491,11 @@ impl Who {
|
|||
}
|
||||
buf.push_str(&format!(" {:<12}", line));
|
||||
// "%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.include_idle {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use common::util::*;
|
||||
|
||||
use rust_users::*;
|
||||
|
||||
#[test]
|
||||
fn test_invalid_option() {
|
||||
|
@ -14,23 +14,26 @@ static DIR: &'static str = "/tmp";
|
|||
#[test]
|
||||
fn test_invalid_group() {
|
||||
new_ucmd!()
|
||||
.arg("nosuchgroup")
|
||||
.arg("__nosuchgroup__")
|
||||
.arg("/")
|
||||
.fails()
|
||||
.stderr_is("chgrp: invalid group: nosuchgroup");
|
||||
.stderr_is("chgrp: invalid group: __nosuchgroup__");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_1() {
|
||||
if get_effective_gid() != 0 {
|
||||
new_ucmd!()
|
||||
.arg("bin")
|
||||
.arg(DIR)
|
||||
.fails()
|
||||
.stderr_is("chgrp: changing group of '/tmp': Operation not permitted (os error 1)");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fail_silently() {
|
||||
if get_effective_gid() != 0 {
|
||||
for opt in &["-f", "--silent", "--quiet"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
|
@ -39,6 +42,7 @@ fn test_fail_silently() {
|
|||
.run()
|
||||
.fails_silently();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -94,6 +98,7 @@ fn test_preserve_root_symlink() {
|
|||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_reference() {
|
||||
if get_effective_gid() != 0 {
|
||||
new_ucmd!()
|
||||
.arg("-v")
|
||||
.arg("--reference=/etc/passwd")
|
||||
|
@ -101,6 +106,7 @@ fn test_reference() {
|
|||
.fails()
|
||||
.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]
|
||||
|
@ -116,17 +122,20 @@ fn test_reference() {
|
|||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_big_p() {
|
||||
if get_effective_gid() != 0 {
|
||||
new_ucmd!()
|
||||
.arg("-RP")
|
||||
.arg("bin")
|
||||
.arg("/proc/self/cwd")
|
||||
.fails()
|
||||
.stderr_is("chgrp: changing group of '/proc/self/cwd': Operation not permitted (os error 1)\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_big_h() {
|
||||
if get_effective_gid() != 0 {
|
||||
assert!(new_ucmd!()
|
||||
.arg("-RH")
|
||||
.arg("bin")
|
||||
|
@ -135,4 +144,5 @@ fn test_big_h() {
|
|||
.stderr
|
||||
.lines()
|
||||
.fold(0, |acc, _| acc + 1) > 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ mod common;
|
|||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
#[cfg(unix)]
|
||||
extern crate rust_users;
|
||||
|
||||
// For conditional compilation
|
||||
macro_rules! unix_only {
|
||||
($($fea:expr, $m:ident);+) => {
|
||||
|
|
Loading…
Reference in a new issue