Skip to content

Commit

Permalink
Ensure that we accept --charactesr only with regex enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
riquito committed Feb 19, 2024
1 parent 275011b commit 42954ee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/bin/tuc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ fn parse_args() -> Result<Opt, pico_args::Error> {
std::process::exit(1);
}

if bounds_type == BoundsType::Characters && cfg!(not(feature = "regex")) {
eprintln!(
"tuc: runtime error. The use of --characters requires `tuc` to be compiled with `regex` support"
);
std::process::exit(1);
}

if bounds_type == BoundsType::Characters {
replace_delimiter = Some("".into());
}
Expand Down
14 changes: 14 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fn it_compresses_delimiters_when_requested_and_handles_boundaries() {
assert.success().stdout("-foo-bar-\n");
}

#[cfg(feature = "regex")]
#[test]
fn it_cuts_on_characters() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
Expand Down Expand Up @@ -404,6 +405,7 @@ fn it_emit_output_as_json() {
);
}

#[cfg(feature = "regex")]
#[test]
fn it_emit_output_as_json_even_when_cutting_on_chars() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
Expand Down Expand Up @@ -441,6 +443,18 @@ fn it_is_not_allowed_to_use_character_with_nojoin() {
);
}

#[cfg(not(feature = "regex"))]
#[test]
fn it_cannot_use_characters_without_regex() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();

let assert = cmd.args(["-c", "1"]).assert();

assert.failure().stderr(
"tuc: runtime error. The use of --characters requires `tuc` to be compiled with `regex` support\n",
);
}

#[test]
fn it_does_not_support_json_on_lines() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
Expand Down

0 comments on commit 42954ee

Please sign in to comment.