Skip to content

Commit

Permalink
Add --test-panic
Browse files Browse the repository at this point in the history
To test the debug handler
  • Loading branch information
th1000s committed Nov 26, 2024
1 parent 0bf9f1f commit 7cefe63
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,13 @@ pub struct Opt {
/// Second file to be compared when delta is being used to diff two files.
pub plus_file: Option<PathBuf>,

/*
Panic on purpose. When a `diff -u a b` (without a `git diff` header) is encountered
then panic early, otherwise panic after processing all input.
*/
#[arg(hide = true, long = "test-panic")]
pub test_panic: bool,

#[arg(skip)]
pub computed: ComputedValues,

Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub struct Config {
pub syntax_set: SyntaxSet,
pub syntax_theme: Option<SyntaxTheme>,
pub tab_cfg: utils::tabs::TabCfg,
pub test_panic: bool,
pub tokenization_regex: Regex,
pub true_color: bool,
pub truncation_symbol: String,
Expand Down Expand Up @@ -419,6 +420,7 @@ impl From<cli::Opt> for Config {
plus_file: opt.plus_file,
plus_non_emph_style: styles["plus-non-emph-style"],
plus_style: styles["plus-style"],
test_panic: opt.test_panic,
git_minus_style: styles["git-minus-style"],
git_plus_style: styles["git-plus-style"],
relative_paths: opt.relative_paths,
Expand Down
3 changes: 3 additions & 0 deletions src/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ impl<'a> StateMachine<'a> {
// to introduce and handle a Source::DiffUnifiedAmbiguous variant everywhere.
if self.line.starts_with("--- ") {
self.minus_line_counter = AmbiguousDiffMinusCounter::prepare_to_count();
if self.config.test_panic {
panic!("An early panic as requested by --test-panic");
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ pub fn run_app(

let res = delta(io::stdin().lock().byte_lines(), &mut writer, &config);

if config.test_panic {
panic!("A panic before the exit as requested by --test-panic");
}

if let Err(error) = res {
match error.kind() {
ErrorKind::BrokenPipe => return Ok(0),
Expand Down

0 comments on commit 7cefe63

Please sign in to comment.