diff --git a/src/bin/tuc.rs b/src/bin/tuc.rs index 988a11e..d510265 100644 --- a/src/bin/tuc.rs +++ b/src/bin/tuc.rs @@ -167,6 +167,13 @@ fn parse_args() -> Result { 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()); } diff --git a/tests/cli.rs b/tests/cli.rs index 5c58fd1..0a172d0 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -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(); @@ -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(); @@ -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();