Skip to content

Commit b802c8c

Browse files
authored
Merge branch 'main' into clippy2
2 parents 02ab93c + 0695437 commit b802c8c

File tree

8 files changed

+112
-83
lines changed

8 files changed

+112
-83
lines changed

.github/workflows/CICD.yml

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -82,56 +82,6 @@ jobs:
8282
grep --ignore-case "all deps seem to have been used" udeps.log || { printf "%s\n" "::${fault_type} ::${fault_prefix}: \`cargo udeps\`: style violation (unused dependency found)" ; fault=true ; }
8383
if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
8484
85-
fuzz:
86-
name: Run the fuzzers
87-
runs-on: ubuntu-latest
88-
env:
89-
RUN_FOR: 60
90-
steps:
91-
- uses: actions/checkout@v4
92-
- uses: dtolnay/rust-toolchain@nightly
93-
- name: Install `cargo-fuzz`
94-
run: cargo install cargo-fuzz
95-
- uses: Swatinem/rust-cache@v2
96-
- name: Run fuzz_date for XX seconds
97-
shell: bash
98-
run: |
99-
## Run it
100-
cd fuzz
101-
cargo +nightly fuzz run fuzz_date -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
102-
- name: Run fuzz_test for XX seconds
103-
continue-on-error: true
104-
shell: bash
105-
run: |
106-
## Run it
107-
cd fuzz
108-
cargo +nightly fuzz run fuzz_test -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
109-
- name: Run fuzz_expr for XX seconds
110-
continue-on-error: true
111-
shell: bash
112-
run: |
113-
## Run it
114-
cd fuzz
115-
cargo +nightly fuzz run fuzz_expr -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
116-
- name: Run fuzz_parse_glob for XX seconds
117-
shell: bash
118-
run: |
119-
## Run it
120-
cd fuzz
121-
cargo +nightly fuzz run fuzz_parse_glob -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
122-
- name: Run fuzz_parse_size for XX seconds
123-
shell: bash
124-
run: |
125-
## Run it
126-
cd fuzz
127-
cargo +nightly fuzz run fuzz_parse_size -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
128-
- name: Run fuzz_parse_time for XX seconds
129-
shell: bash
130-
run: |
131-
## Run it
132-
cd fuzz
133-
cargo +nightly fuzz run fuzz_parse_time -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
134-
13585
doc_warnings:
13686
name: Documentation/warnings
13787
runs-on: ${{ matrix.job.os }}

.github/workflows/fuzzing.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Fuzzing
2+
3+
# spell-checker:ignore fuzzer
4+
5+
on: [push, pull_request]
6+
7+
permissions:
8+
contents: read # to fetch code (actions/checkout)
9+
10+
# End the current execution if there is a new changeset in the PR.
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
14+
15+
jobs:
16+
fuzz:
17+
name: Run the fuzzers
18+
runs-on: ubuntu-latest
19+
env:
20+
RUN_FOR: 60
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: dtolnay/rust-toolchain@nightly
24+
- name: Install `cargo-fuzz`
25+
run: cargo install cargo-fuzz
26+
- uses: Swatinem/rust-cache@v2
27+
- name: Run fuzz_date for XX seconds
28+
shell: bash
29+
run: |
30+
## Run it
31+
cd fuzz
32+
cargo +nightly fuzz run fuzz_date -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
33+
- name: Run fuzz_test for XX seconds
34+
continue-on-error: true
35+
shell: bash
36+
run: |
37+
## Run it
38+
cd fuzz
39+
cargo +nightly fuzz run fuzz_test -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
40+
- name: Run fuzz_expr for XX seconds
41+
continue-on-error: true
42+
shell: bash
43+
run: |
44+
## Run it
45+
cd fuzz
46+
cargo +nightly fuzz run fuzz_expr -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
47+
- name: Run fuzz_parse_glob for XX seconds
48+
shell: bash
49+
run: |
50+
## Run it
51+
cd fuzz
52+
cargo +nightly fuzz run fuzz_parse_glob -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
53+
- name: Run fuzz_parse_size for XX seconds
54+
shell: bash
55+
run: |
56+
## Run it
57+
cd fuzz
58+
cargo +nightly fuzz run fuzz_parse_size -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
59+
- name: Run fuzz_parse_time for XX seconds
60+
shell: bash
61+
run: |
62+
## Run it
63+
cd fuzz
64+
cargo +nightly fuzz run fuzz_parse_time -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0

Cargo.lock

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

src/uu/expr/src/syntax_tree.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ pub enum AstNode {
3131
operands: OperandsList,
3232
},
3333
}
34+
3435
impl AstNode {
3536
fn debug_dump(&self) {
3637
self.debug_dump_impl(1);
3738
}
39+
3840
fn debug_dump_impl(&self, depth: usize) {
3941
for _ in 0..depth {
4042
print!("\t",);
@@ -52,7 +54,7 @@ impl AstNode {
5254
operands,
5355
} => {
5456
println!(
55-
"Node( {} ) at #{} (evaluate -> {:?})",
57+
"Node( {} ) at #{} ( evaluate -> {:?} )",
5658
op_type,
5759
token_idx,
5860
self.evaluate()
@@ -71,12 +73,14 @@ impl AstNode {
7173
operands,
7274
})
7375
}
76+
7477
fn new_leaf(token_idx: usize, value: &str) -> Box<Self> {
7578
Box::new(Self::Leaf {
7679
token_idx,
7780
value: value.into(),
7881
})
7982
}
83+
8084
pub fn evaluate(&self) -> Result<String, String> {
8185
match self {
8286
Self::Leaf { value, .. } => Ok(value.clone()),
@@ -154,9 +158,27 @@ impl AstNode {
154158
},
155159
}
156160
}
161+
157162
pub fn operand_values(&self) -> Result<Vec<String>, String> {
158-
if let Self::Node { operands, .. } = self {
163+
if let Self::Node {
164+
operands, op_type, ..
165+
} = self
166+
{
159167
let mut out = Vec::with_capacity(operands.len());
168+
let mut operands = operands.iter();
169+
// check the first value before `|`, stop evaluate and return directly if it is true.
170+
// push dummy to pass the check of `len() == 2`
171+
if op_type == "|" {
172+
if let Some(value) = operands.next() {
173+
let value = value.evaluate()?;
174+
out.push(value.clone());
175+
if value_as_bool(&value) {
176+
out.push(String::from("dummy"));
177+
return Ok(out);
178+
}
179+
}
180+
}
181+
160182
for operand in operands {
161183
let value = operand.evaluate()?;
162184
out.push(value);
@@ -240,6 +262,7 @@ fn ast_from_rpn(rpn: &mut TokenStack) -> Result<Box<AstNode>, String> {
240262
}
241263
}
242264
}
265+
243266
fn maybe_ast_node(
244267
token_idx: usize,
245268
op_type: &str,
@@ -503,13 +526,15 @@ fn prefix_operator_substr(values: &[String]) -> String {
503526
fn bool_as_int(b: bool) -> u8 {
504527
u8::from(b)
505528
}
529+
506530
fn bool_as_string(b: bool) -> String {
507531
if b {
508532
"1".to_string()
509533
} else {
510534
"0".to_string()
511535
}
512536
}
537+
513538
fn value_as_bool(s: &str) -> bool {
514539
if s.is_empty() {
515540
return false;

src/uu/expr/src/tokens.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub enum Token {
3838
value: String,
3939
},
4040
}
41+
4142
impl Token {
4243
fn new_infix_op(v: &str, left_assoc: bool, precedence: u8) -> Self {
4344
Self::InfixOp {
@@ -46,6 +47,7 @@ impl Token {
4647
value: v.into(),
4748
}
4849
}
50+
4951
fn new_value(v: &str) -> Self {
5052
Self::Value { value: v.into() }
5153
}
@@ -56,12 +58,14 @@ impl Token {
5658
_ => false,
5759
}
5860
}
61+
5962
fn is_a_number(&self) -> bool {
6063
match self {
6164
Self::Value { value, .. } => value.parse::<BigInt>().is_ok(),
6265
_ => false,
6366
}
6467
}
68+
6569
fn is_a_close_paren(&self) -> bool {
6670
matches!(*self, Self::ParClose)
6771
}

src/uucore/src/lib/features/tokenize/num_format/format_field.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ pub enum FieldType {
1717
Charf,
1818
}
1919

20-
// #[allow(non_camel_case_types)]
21-
// pub enum FChar {
22-
// d,
23-
// e,
24-
// E,
25-
// i,
26-
// f,
27-
// F,
28-
// g,
29-
// G,
30-
// u,
31-
// x,
32-
// X,
33-
// o
34-
// }
35-
//
36-
3720
// a Sub Tokens' fields are stored
3821
// as a single object so they can be more simply
3922
// passed by ref to num_format in a Sub method

src/uucore/src/lib/features/tokenize/sub.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::iter::Peekable;
1818
use std::process::exit;
1919
use std::slice::Iter;
2020
use std::str::Chars;
21-
// use std::collections::HashSet;
2221

2322
use super::num_format::format_field::{FieldType, FormatField};
2423
use super::num_format::num_format;

tests/by-util/test_expr.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ fn test_or() {
123123
.args(&["-14", "|", "1"])
124124
.succeeds()
125125
.stdout_only("-14\n");
126+
127+
new_ucmd!()
128+
.args(&["1", "|", "a", "/", "5"])
129+
.succeeds()
130+
.stdout_only("1\n");
131+
132+
new_ucmd!()
133+
.args(&["foo", "|", "a", "/", "5"])
134+
.succeeds()
135+
.stdout_only("foo\n");
136+
137+
new_ucmd!()
138+
.args(&["0", "|", "10", "/", "5"])
139+
.succeeds()
140+
.stdout_only("2\n");
126141
}
127142

128143
#[test]

0 commit comments

Comments
 (0)