mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #1534 from sylvestre/logname
Logname - add test and simplify the code a bit
This commit is contained in:
commit
358af0939c
2 changed files with 29 additions and 7 deletions
|
@ -39,14 +39,10 @@ static LONG_HELP: &str = "";
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
app!(SYNTAX, SUMMARY, LONG_HELP).parse(args);
|
app!(SYNTAX, SUMMARY, LONG_HELP).parse(args);
|
||||||
|
|
||||||
exec();
|
|
||||||
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn exec() {
|
|
||||||
match get_userlogin() {
|
match get_userlogin() {
|
||||||
Some(userlogin) => println!("{}", userlogin),
|
Some(userlogin) => println!("{}", userlogin),
|
||||||
None => show_error!("no login name"),
|
None => show_error!("no login name"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
0
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,27 @@
|
||||||
// ToDO: add tests
|
use crate::common::util::*;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_normal() {
|
||||||
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
|
let result = ucmd.run();
|
||||||
|
println!("result.stdout = {}", result.stdout);
|
||||||
|
println!("result.stderr = {}", result.stderr);
|
||||||
|
println!("env::var(CI).is_ok() = {}", env::var("CI").is_ok());
|
||||||
|
|
||||||
|
for (key, value) in env::vars() {
|
||||||
|
println!("{}: {}", key, value);
|
||||||
|
}
|
||||||
|
if env::var("USER").is_ok()
|
||||||
|
&& env::var("USER").unwrap() == "runner"
|
||||||
|
&& result.stderr.contains("error: no login name")
|
||||||
|
{
|
||||||
|
// In the CI, some server are failing to return logname.
|
||||||
|
// As seems to be a configuration issue, ignoring it
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert!(result.success);
|
||||||
|
assert!(!result.stdout.trim().is_empty());
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue