Skip to content

Commit

Permalink
Merge branch 'main' into tail_notify
Browse files Browse the repository at this point in the history
  • Loading branch information
jhscheer committed Apr 21, 2022
2 parents 4a56d29 + 4ea443b commit 6c09626
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 20 deletions.
31 changes: 23 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ Both can also be generated locally, the instructions for that can be found in th
uutils follows Rust's release channels and is tested against stable, beta and nightly.
The current oldest supported version of the Rust compiler is `1.56`.

On both Windows and Redox, only the nightly version is tested currently.

## Building

There are currently two methods to build the uutils binaries: either Cargo
Expand Down
4 changes: 4 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ highlight = "all"
# introduces it.
# spell-checker: disable
skip = [
# getrandom
{ name = "wasi", version="0.10.2+wasi-snapshot-preview1" },
# blake2d_simd
{ name = "arrayvec", version = "=0.7.2" },
# flimit/unix_socket
Expand All @@ -76,6 +78,8 @@ skip = [
{ name = "cpp_common", version = "=0.4.0" },
# quickcheck
{ name = "env_logger", version = "=0.8.4" },
# tempfile
{ name = "remove_dir_all", version = "=0.5.3" },
# cpp_*
{ name = "memchr", version = "=1.0.2" },
{ name = "quote", version = "=0.3.15" },
Expand Down
1 change: 1 addition & 0 deletions src/uu/df/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ path = "src/df.rs"
clap = { version = "3.1", features = ["wrap_help", "cargo"] }
number_prefix = "0.4"
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["libc", "fsext"] }
unicode-width = "0.1.9"

[[bin]]
name = "df"
Expand Down
3 changes: 2 additions & 1 deletion src/uu/df/src/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ fn get_all_filesystems(opt: &Options) -> Vec<Filesystem> {
mounts
.into_iter()
.filter_map(|m| Filesystem::new(m, None))
.filter(|fs| opt.show_all_fs || fs.usage.blocks > 0)
.collect()
}

Expand Down Expand Up @@ -362,7 +363,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let filesystems = get_all_filesystems(&opt);

if filesystems.is_empty() {
return Err(USimpleError::new(1, "No file systems processed"));
return Err(USimpleError::new(1, "no file systems processed"));
}

filesystems
Expand Down
18 changes: 14 additions & 4 deletions src/uu/df/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! A table ([`Table`]) comprises a header row ([`Header`]) and a
//! collection of data rows ([`Row`]), one per filesystem.
use number_prefix::NumberPrefix;
use unicode_width::UnicodeWidthStr;

use crate::columns::{Alignment, Column};
use crate::filesystem::Filesystem;
Expand Down Expand Up @@ -362,8 +363,8 @@ impl Table {
total += row;

for (i, value) in values.iter().enumerate() {
if value.len() > widths[i] {
widths[i] = value.len();
if UnicodeWidthStr::width(value.as_str()) > widths[i] {
widths[i] = UnicodeWidthStr::width(value.as_str());
}
}

Expand Down Expand Up @@ -400,12 +401,21 @@ impl fmt::Display for Table {
while let Some(row) = row_iter.next() {
let mut col_iter = row.iter().enumerate().peekable();
while let Some((i, elem)) = col_iter.next() {
let is_last_col = col_iter.peek().is_none();

match self.alignments[i] {
Alignment::Left => write!(f, "{:<width$}", elem, width = self.widths[i])?,
Alignment::Left => {
if is_last_col {
// no trailing spaces in last column
write!(f, "{}", elem)?;
} else {
write!(f, "{:<width$}", elem, width = self.widths[i])?;
}
}
Alignment::Right => write!(f, "{:>width$}", elem, width = self.widths[i])?,
}

if col_iter.peek().is_some() {
if !is_last_col {
// column separator
write!(f, " ")?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/rm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ path = "src/rm.rs"
[dependencies]
clap = { version = "3.1", features = ["wrap_help", "cargo"] }
walkdir = "2.2"
remove_dir_all = "0.5.1"
remove_dir_all = "0.7.0"
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["fs"] }

[target.'cfg(windows)'.dependencies]
Expand Down
46 changes: 42 additions & 4 deletions tests/by-util/test_df.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// spell-checker:ignore udev pcent iuse itotal iused ipcent
use std::collections::HashSet;

use crate::common::util::*;

#[test]
Expand Down Expand Up @@ -165,6 +167,7 @@ fn test_output_mp_repeat() {
assert_eq!(3, output1.len());
assert_eq!(output1[1], output1[2]);
}

#[test]
fn test_output_conflict_options() {
for option in ["-i", "-T", "-P"] {
Expand Down Expand Up @@ -204,6 +207,27 @@ fn test_exclude_type_option() {
new_ucmd!().args(&["-x", "ext4", "-x", "ext3"]).succeeds();
}

#[test]
fn test_exclude_all_types() {
let fs_types = new_ucmd!()
.arg("--output=fstype")
.succeeds()
.stdout_move_str();
let fs_types: HashSet<_> = fs_types.lines().skip(1).collect();

let mut args = Vec::new();

for fs_type in fs_types {
args.push("-x");
args.push(fs_type.trim_end());
}

new_ucmd!()
.args(&args)
.fails()
.stderr_contains("no file systems processed");
}

#[test]
fn test_include_exclude_same_type() {
new_ucmd!()
Expand Down Expand Up @@ -349,7 +373,7 @@ fn test_output_selects_columns() {
.args(&["--output=source"])
.succeeds()
.stdout_move_str();
assert_eq!(output.lines().next().unwrap().trim_end(), "Filesystem");
assert_eq!(output.lines().next().unwrap(), "Filesystem");

let output = new_ucmd!()
.args(&["--output=source,target"])
Expand Down Expand Up @@ -408,7 +432,7 @@ fn test_output_file_all_filesystems() {
let mut lines = output.lines();
assert_eq!(lines.next().unwrap(), "File");
for line in lines {
assert_eq!(line, "- ");
assert_eq!(line, "-");
}
}

Expand All @@ -427,7 +451,21 @@ fn test_output_file_specific_files() {
.succeeds()
.stdout_move_str();
let actual: Vec<&str> = output.lines().collect();
assert_eq!(actual, vec!["File", "a ", "b ", "c "]);
assert_eq!(actual, vec!["File", "a", "b", "c"]);
}

#[test]
fn test_file_column_width_if_filename_contains_unicode_chars() {
let (at, mut ucmd) = at_and_ucmd!();
at.touch("äöü.txt");

let output = ucmd
.args(&["--output=file,target", "äöü.txt"])
.succeeds()
.stdout_move_str();
let actual = output.lines().next().unwrap();
// expected width: 7 chars (length of äöü.txt) + 1 char (column separator)
assert_eq!(actual, "File Mounted on");
}

#[test]
Expand All @@ -448,5 +486,5 @@ fn test_nonexistent_file() {
.args(&["--output=file", "does-not-exist", "."])
.fails()
.stderr_is("df: does-not-exist: No such file or directory\n")
.stdout_is("File\n. \n");
.stdout_is("File\n.\n");
}

0 comments on commit 6c09626

Please sign in to comment.