Skip to content

Commit 2086db4

Browse files
authored
Merge branch 'rustcoreutils:main' into default
2 parents afb781e + 199f206 commit 2086db4

File tree

10 files changed

+49
-49
lines changed

10 files changed

+49
-49
lines changed

Cargo.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

awk/src/interpreter/io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl WritePipes {
286286
Entry::Vacant(e) => {
287287
let command: CString = command.try_into()?;
288288
let file = unsafe {
289-
let file = libc::popen(command.as_ptr(), "w\0".as_ptr() as *const i8);
289+
let file = libc::popen(command.as_ptr(), c"w".as_ptr());
290290
if file.is_null() {
291291
return Err("failed to open pipe".to_string());
292292
}
@@ -351,7 +351,7 @@ impl PipeRecordReader {
351351
pub fn open(command: &str) -> Result<Self, String> {
352352
let command = CString::new(command).map_err(|e| e.to_string())?;
353353
let file = unsafe {
354-
let file = libc::popen(command.as_ptr(), "r\0".as_ptr() as *const i8);
354+
let file = libc::popen(command.as_ptr(), c"r".as_ptr());
355355
if file.is_null() {
356356
return Err("failed to open pipe".to_string());
357357
}

i18n/gencat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ impl MessageCatalog {
553553
}
554554

555555
/// Read the **GNU based** binary catalog file and build [MessageCatalog]
556+
#[allow(clippy::needless_range_loop)]
556557
pub fn read_catfile<T: Read>(
557558
mut input: T,
558559
) -> Result<MessageCatalog, Box<dyn std::error::Error>> {
@@ -590,7 +591,7 @@ impl MessageCatalog {
590591
ptr += 4;
591592
}
592593

593-
// note: probably compare be_array and le_array as they should be the same
594+
// TODO: probably compare be_array and le_array as they should be the same
594595

595596
let string_pool = &buf[ptr..];
596597

plib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub mod sccsfile;
1818
pub mod testing;
1919
pub mod utmpx;
2020

21-
pub const PROJECT_NAME: &'static str = "posixutils-rs";
21+
pub const PROJECT_NAME: &str = "posixutils-rs";
2222

2323
pub const BUFSZ: usize = 8 * 1024;
2424

screen/stty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use termios::{
2323
Termios, TCSANOW,
2424
};
2525

26-
const HDR_SAVE: &'static str = "pfmt1";
26+
const HDR_SAVE: &str = "pfmt1";
2727

2828
#[derive(Parser)]
2929
#[command(version, about = gettext("stty - set the options for a terminal"))]

text/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ regex.workspace = true
1515
chrono.workspace = true
1616
libc.workspace = true
1717
notify-debouncer-full = "0.3"
18-
ctor = "0.2"
1918
diff = "0.1"
2019
dirs = "5.0"
2120
deunicode = "1.6"

text/join.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,28 @@ fn process_files2(
103103
let mut res: Vec<String> = Vec::new();
104104
for num in order {
105105
let f_num: Vec<&str> = num.split('.').collect();
106+
assert_eq!(f_num.len(), 2);
107+
let mut n: usize = f_num[1].parse()?;
108+
n -= 1;
106109
if f_num[0] == "1" {
107-
if fields1.len() <= f_num[1].parse::<usize>()? - 1 {
110+
if fields1.len() <= n {
108111
if let Some(e) = &e {
109112
res.push(e.to_string());
110113
}
111114
} else {
112-
res.push(fields1[f_num[1].parse::<usize>()? - 1].clone());
115+
res.push(fields1[n].clone());
113116
}
114117
} else if f_num[0] == "2" {
115-
if fields2.len() <= f_num[1].parse::<usize>()? - 1 {
118+
if fields2.len() <= n {
116119
if let Some(e) = &e {
117120
res.push(e.to_string());
118121
}
119122
} else {
120-
res.push(fields2[f_num[1].parse::<usize>()? - 1].clone());
123+
res.push(fields2[n].clone());
121124
}
125+
} else {
126+
// TODO:
127+
panic!("f_num[0] not in (1, 2)");
122128
}
123129
}
124130
if v == 0 {

text/tests/diff-tests.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ mod constants;
1313

1414
use constants::{EXIT_STATUS_DIFFERENCE, EXIT_STATUS_NO_DIFFERENCE};
1515
use plib::{run_test, TestPlan};
16+
use std::{collections::HashMap, path::PathBuf, process::Stdio, sync::LazyLock};
1617

1718
fn diff_test(args: &[&str], expected_output: &str, expected_diff_exit_status: u8) {
18-
let str_args: Vec<String> = args.iter().map(|s| String::from(*s)).collect();
19+
let str_args = args.iter().cloned().map(str::to_owned).collect();
1920

2021
run_test(TestPlan {
2122
cmd: String::from("diff"),
@@ -27,8 +28,6 @@ fn diff_test(args: &[&str], expected_output: &str, expected_diff_exit_status: u8
2728
});
2829
}
2930

30-
use std::{path::PathBuf, process::Stdio};
31-
3231
fn diff_base_path() -> PathBuf {
3332
PathBuf::from("tests").join("diff")
3433
}
@@ -74,14 +73,13 @@ fn f1_txt_with_eol_spaces_path() -> String {
7473
}
7574

7675
struct DiffTestHelper {
77-
pub key: String,
7876
content: String,
7977
file1_path: String,
8078
file2_path: String,
8179
}
8280

8381
impl DiffTestHelper {
84-
fn new(options: &str, file1_path: String, file2_path: String, key: String) -> Self {
82+
fn new(options: &str, file1_path: String, file2_path: String) -> Self {
8583
let args = format!(
8684
"run --release --bin diff --{} {} {}",
8785
options, file1_path, file2_path
@@ -99,7 +97,6 @@ impl DiffTestHelper {
9997
let content = String::from_utf8(output.stdout).expect("Failed to read output of Command!");
10098

10199
Self {
102-
key,
103100
file1_path,
104101
file2_path,
105102
content,
@@ -119,20 +116,7 @@ impl DiffTestHelper {
119116
}
120117
}
121118

122-
static mut DIFF_TEST_INPUT: Vec<DiffTestHelper> = vec![];
123-
124-
fn input_by_key(key: &str) -> &DiffTestHelper {
125-
unsafe {
126-
DIFF_TEST_INPUT
127-
.iter()
128-
.filter(|data| data.key == key)
129-
.nth(0)
130-
.unwrap()
131-
}
132-
}
133-
134-
#[ctor::ctor]
135-
fn diff_tests_setup() {
119+
fn get_diff_test_helper_hash_map() -> HashMap<String, DiffTestHelper> {
136120
let diff_test_helper_init_data = [
137121
("", f1_txt_path(), f2_txt_path(), "test_diff_normal"),
138122
(" -c", f1_txt_path(), f2_txt_path(), "test_diff_context3"),
@@ -210,14 +194,33 @@ fn diff_tests_setup() {
210194
),
211195
];
212196

213-
for row in diff_test_helper_init_data {
214-
unsafe { DIFF_TEST_INPUT.push(DiffTestHelper::new(row.0, row.1, row.2, row.3.to_string())) }
197+
let mut diff_test_helper_hash_map =
198+
HashMap::<String, DiffTestHelper>::with_capacity(diff_test_helper_init_data.len());
199+
200+
for (options, file1_path, file2_path, key) in diff_test_helper_init_data {
201+
let insert_option = diff_test_helper_hash_map.insert(
202+
key.to_owned(),
203+
DiffTestHelper::new(options, file1_path, file2_path),
204+
);
205+
206+
assert!(insert_option.is_none());
215207
}
208+
209+
diff_test_helper_hash_map
210+
}
211+
212+
fn input_by_key(key: &str) -> &'static DiffTestHelper {
213+
static DIFF_TEST_INPUT: LazyLock<HashMap<String, DiffTestHelper>> =
214+
LazyLock::new(get_diff_test_helper_hash_map);
215+
216+
// Initialized on first access
217+
DIFF_TEST_INPUT.get(key).unwrap()
216218
}
217219

218220
#[test]
219221
fn test_diff_normal() {
220222
let data = input_by_key("test_diff_normal");
223+
221224
diff_test(
222225
&[data.file1_path(), data.file2_path()],
223226
data.content(),
@@ -316,6 +319,7 @@ fn test_diff_unified10() {
316319
#[test]
317320
fn test_diff_file_directory() {
318321
let data = input_by_key("test_diff_file_directory");
322+
319323
diff_test(
320324
&[data.file1_path(), data.file2_path()],
321325
data.content(),
@@ -326,6 +330,7 @@ fn test_diff_file_directory() {
326330
#[test]
327331
fn test_diff_directories() {
328332
let data = input_by_key("test_diff_directories");
333+
329334
diff_test(
330335
&[data.file1_path(), data.file2_path()],
331336
data.content(),
@@ -391,6 +396,7 @@ fn test_diff_directories_recursive_unified() {
391396
#[test]
392397
fn test_diff_counting_eol_spaces() {
393398
let data = input_by_key("test_diff_counting_eol_spaces");
399+
394400
diff_test(
395401
&[data.file1_path(), data.file2_path()],
396402
data.content(),

text/wc.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,8 @@ const BYTE_TABLE: [bool; 256] = create_table();
7373
fn build_display_str(args: &Args, count: &CountInfo, filename: &OsStr) -> String {
7474
let mut output = String::with_capacity(filename.len() + (3 * 10));
7575

76-
let multi_file = args.files.len() > 1;
77-
let only_lines = (args.words == false) && (args.bytes == false) && (args.chars == false);
78-
let only_words = (args.lines == false) && (args.bytes == false) && (args.chars == false);
79-
let only_bytechars = (args.lines == false) && (args.words == false);
80-
8176
if args.lines {
77+
let only_lines = !args.words && !args.bytes && !args.chars;
8278
let numstr = match only_lines {
8379
true => format!("{}", count.nl),
8480
false => format!("{:>8}", count.nl),
@@ -89,6 +85,7 @@ fn build_display_str(args: &Args, count: &CountInfo, filename: &OsStr) -> String
8985
if !output.is_empty() {
9086
output.push(' ');
9187
}
88+
let only_words = !args.lines && !args.bytes && !args.chars;
9289
let numstr = match only_words {
9390
true => format!("{}", count.words),
9491
false => format!("{:>8}", count.words),
@@ -99,13 +96,15 @@ fn build_display_str(args: &Args, count: &CountInfo, filename: &OsStr) -> String
9996
if !output.is_empty() {
10097
output.push(' ');
10198
}
99+
let only_bytechars = !args.lines && !args.words;
102100
let numstr = match only_bytechars {
103101
true => format!("{}", count.chars),
104102
false => format!("{:>8}", count.chars),
105103
};
106104
output.push_str(&numstr);
107105
}
108106

107+
let multi_file = args.files.len() > 1;
109108
if multi_file {
110109
output.push(' ');
111110

users/pwd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use plib::PROJECT_NAME;
1616
use std::ffi::OsStr;
1717
use std::path::{Component, Path};
1818

19-
const PWD_ENV: &'static str = "PWD";
19+
const PWD_ENV: &str = "PWD";
2020

2121
/// pwd - return working directory name
2222
#[derive(Parser)]

0 commit comments

Comments
 (0)