Skip to content

Commit 69c17ac

Browse files
authored
Merge pull request #428 from rustcoreutils/updates
Updates
2 parents 3b05152 + 7c676d9 commit 69c17ac

File tree

47 files changed

+785
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+785
-295
lines changed

CONTRIBUTING.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,18 @@ There are several ways to contribute to posixutils-rs:
3939
Code should be readable by unfamiliar developers. Avoid dense,
4040
uncommented code.
4141

42-
### Testing, POSIX compliance and programmaticgoals
42+
### Testing, POSIX compliance and programmatic goals
4343

4444
* All utilities should have tests.
45+
* Use plib's TestPlan framework for integration tests.
46+
* Test pattern:
47+
1. Pre-generate input data files.
48+
2. Run system OS utility on input data files,
49+
generating known-good output.
50+
3. Store input and output in-tree, as known-good data.
51+
4. Write a TestPlan that executes our utility, using
52+
static input data, and compares output with
53+
static output data.
4554
* Only "quick" tests should be run automatically in `cargo test`
4655
* Longer tests, or tests requiring root access, should be triggered
4756
via special environment variables.
@@ -50,7 +59,9 @@ There are several ways to contribute to posixutils-rs:
5059
* If a system has an OS-specific feature that _must_ be
5160
exposed through a given utility, do so.
5261
* Race-free userland. See `ftw` internal crate.
53-
* Push small crates out: Create tiny, light-dep crates from common functionality (such as Lex or Yacc file parsing), and publish via cargo. Remove from main posixutils tree and set of crates.
62+
* Push small crates out: Create tiny, light-dep crates from common
63+
functionality (such as Lex or Yacc file parsing), and publish via cargo.
64+
Remove from main posixutils tree and set of crates.
5465

5566
### Testing and Bug Reporting: Info to provide in GH issue
5667

Cargo.lock

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

calc/bc_util/interpreter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl Interpreter {
201201
.ok_or("array index is too large")? as usize;
202202
if let Some(call_frame) = self.call_frames.last_mut() {
203203
if let Some(array) = &mut call_frame.array_variables[name_index(*name)] {
204-
return Ok(get_or_extend(array, index as usize));
204+
return Ok(get_or_extend(array, index));
205205
}
206206
}
207207
Ok(get_or_extend(

calc/expr.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ fn token_display(t: &Token) -> String {
6666

6767
// is token an lval?
6868
fn token_is_lval(t: &Token) -> bool {
69-
match t {
70-
Token::Integer(_) => true,
71-
Token::Str(_) => true,
72-
_ => false,
73-
}
69+
matches!(t, Token::Integer(_) | Token::Str(_))
7470
}
7571

7672
// is token zero?

display/more.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl SeekPositions {
591591
let reader = BufReader::new(&mut self.buffer).lines();
592592
for line in reader {
593593
if let Ok(line) = line {
594-
seek_pos += line.as_bytes().len();
594+
seek_pos += line.len();
595595
}
596596
i += 1;
597597
if i >= n {

file/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn get_magic_files(args: &Args) -> Vec<PathBuf> {
110110
magic_files
111111
}
112112

113-
fn analyze_file(mut path: String, args: &Args, magic_files: &Vec<PathBuf>) {
113+
fn analyze_file(mut path: String, args: &Args, magic_files: &[PathBuf]) {
114114
if path == "-" {
115115
path = String::new();
116116
io::stdin().read_line(&mut path).unwrap();

file/magic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl RawMagicFileLine {
426426
fn string_test(&self, tf_reader: &mut BufReader<File>) -> bool {
427427
if let Value::String(val) = &self.value {
428428
let mut buf = vec![0u8; val.len()];
429-
if let Err(_) = tf_reader.read_exact(&mut buf) {
429+
if tf_reader.read_exact(&mut buf).is_err() {
430430
return false;
431431
}
432432

@@ -439,7 +439,7 @@ impl RawMagicFileLine {
439439

440440
fn number_test(&self, size: u64, mask: Option<u64>, tf_reader: &mut BufReader<File>) -> bool {
441441
let mut buf = vec![0; size as usize];
442-
if let Err(_) = tf_reader.read_exact(&mut buf) {
442+
if tf_reader.read_exact(&mut buf).is_err() {
443443
return false;
444444
}
445445

i18n/iconv_lib/utf_16.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,13 @@ pub fn from_ucs4<I: Iterator<Item = u32> + 'static>(
170170
let high_surrogate = ((code_point >> 10) as u16) + 0xD800;
171171
let low_surrogate = ((code_point & 0x3FF) as u16) + 0xDC00;
172172
utf16.extend_from_slice(&[high_surrogate, low_surrogate]);
173+
} else if !omit_invalid {
174+
return Vec::new();
173175
} else {
174-
if !omit_invalid {
175-
return Vec::new();
176-
} else {
177-
if !suppress_error {
178-
eprintln!("Error: Invalid Unicode code point U+{:X}", code_point);
179-
}
180-
exit(1)
176+
if !suppress_error {
177+
eprintln!("Error: Invalid Unicode code point U+{:X}", code_point);
181178
}
179+
exit(1)
182180
}
183181

184182
to_bytes(&utf16, variant)

i18n/iconv_lib/utf_32.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,20 @@ pub fn to_ucs4<I: Iterator<Item = u8> + 'static>(
4242

4343
if !bom_checked {
4444
let first_word = BigEndian::read_u32(&buffer);
45-
match variant {
46-
UTF32Variant::UTF32 => {
47-
if first_word == BOM {
48-
variant = UTF32Variant::UTF32BE;
49-
buffer.clear();
50-
} else if first_word == BOM_OE {
51-
variant = UTF32Variant::UTF32LE;
52-
buffer.clear();
45+
if variant == UTF32Variant::UTF32 {
46+
if first_word == BOM {
47+
variant = UTF32Variant::UTF32BE;
48+
buffer.clear();
49+
} else if first_word == BOM_OE {
50+
variant = UTF32Variant::UTF32LE;
51+
buffer.clear();
52+
} else {
53+
variant = if cfg!(target_endian = "little") {
54+
UTF32Variant::UTF32LE
5355
} else {
54-
variant = if cfg!(target_endian = "little") {
55-
UTF32Variant::UTF32LE
56-
} else {
57-
UTF32Variant::UTF32BE
58-
};
59-
}
56+
UTF32Variant::UTF32BE
57+
};
6058
}
61-
_ => {}
6259
}
6360
bom_checked = true;
6461
if buffer.is_empty() {

i18n/iconv_lib/utf_8.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,14 @@ pub fn to_ucs4<I: Iterator<Item = u8> + 'static>(
168168
}
169169
buffer.drain(0..4);
170170
return Some(code_point);
171+
} else if omit_invalid {
172+
buffer.drain(0..1);
173+
continue;
171174
} else {
172-
if omit_invalid {
173-
buffer.drain(0..1);
174-
continue;
175-
} else {
176-
if !suppress_error {
177-
eprintln!("Error: Invalid byte");
178-
}
179-
exit(1);
175+
if !suppress_error {
176+
eprintln!("Error: Invalid byte");
180177
}
178+
exit(1);
181179
}
182180
}
183181
});
@@ -225,19 +223,17 @@ pub fn from_ucs4<I: Iterator<Item = u32> + 'static>(
225223
0x80 | (((code_point >> 6) & 0x3F) as u8),
226224
0x80 | ((code_point & 0x3F) as u8),
227225
])
226+
} else if omit_invalid {
227+
None
228228
} else {
229-
if omit_invalid {
230-
None
231-
} else {
232-
if !suppress_error {
233-
eprintln!(
234-
"Error: Code point U+{:X} is out of valid Unicode range",
235-
code_point
236-
);
237-
exit(1)
238-
}
239-
Some(vec![])
229+
if !suppress_error {
230+
eprintln!(
231+
"Error: Code point U+{:X} is out of valid Unicode range",
232+
code_point
233+
);
234+
exit(1)
240235
}
236+
Some(vec![])
241237
}
242238
});
243239
Box::new(iter.flatten())

0 commit comments

Comments
 (0)