* Add custom panic hook. Print backtrace and thread, error info on panic. * use sync_channel and SyncSender * nit fixes and cleanup * disable custom panic hook while running tests * make separate errors.rs file and address other review comments * improve panic message * debug: does increasing time between snapshots make tests pass? (this is temporary) * fix(tests): suspend before sending quit command * fix(tests): add missing use * style(format): commas are important apparently * fix(tests): can we get away with reducing the QUIT suspense time? * fix(tests): can we get away with 50? Co-authored-by: Aram Drevekenin <aram@poor.dev>
573 lines
20 KiB
Rust
573 lines
20 KiB
Rust
use insta::assert_snapshot;
|
|
|
|
use crate::terminal_pane::PositionAndSize;
|
|
use crate::tests::fakes::FakeInputOutput;
|
|
use crate::tests::utils::get_output_frame_snapshots;
|
|
use crate::{start, Opt};
|
|
|
|
use crate::tests::utils::commands::{
|
|
COMMAND_TOGGLE, MOVE_FOCUS, QUIT, RESIZE_DOWN, RESIZE_LEFT, SPLIT_HORIZONTALLY,
|
|
SPLIT_VERTICALLY,
|
|
};
|
|
|
|
fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput {
|
|
FakeInputOutput::new(*fake_win_size)
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_pane_above() {
|
|
// ┌───────────┐ ┌───────────┐
|
|
// │ │ │ │
|
|
// │ │ │ │
|
|
// ├───────────┤ ==resize=down==> │ │
|
|
// │███████████│ ├───────────┤
|
|
// │███████████│ │███████████│
|
|
// │███████████│ │███████████│
|
|
// └───────────┘ └───────────┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 20,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_HORIZONTALLY,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_pane_below() {
|
|
// ┌───────────┐ ┌───────────┐
|
|
// │███████████│ │███████████│
|
|
// │███████████│ │███████████│
|
|
// ├───────────┤ ==resize=down==> │███████████│
|
|
// │ │ ├───────────┤
|
|
// │ │ │ │
|
|
// └───────────┘ └───────────┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 20,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_panes_above_and_below() {
|
|
// ┌───────────┐ ┌───────────┐
|
|
// │ │ │ │
|
|
// │ │ │ │
|
|
// ├───────────┤ │ │
|
|
// │███████████│ ==resize=down==> ├───────────┤
|
|
// │███████████│ │███████████│
|
|
// ├───────────┤ ├───────────┤
|
|
// │ │ │ │
|
|
// │ │ │ │
|
|
// └───────────┘ └───────────┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 20,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_HORIZONTALLY,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_multiple_panes_above() {
|
|
//
|
|
// ┌─────┬─────┐ ┌─────┬─────┐
|
|
// │ │ │ │ │ │
|
|
// ├─────┴─────┤ ==resize=down==> │ │ │
|
|
// │███████████│ ├─────┴─────┤
|
|
// │███████████│ │███████████│
|
|
// └───────────┘ └───────────┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 20,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_VERTICALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_panes_above_aligned_left_with_current_pane() {
|
|
// ┌─────┬─────┐ ┌─────┬─────┐
|
|
// │ │ │ │ │ │
|
|
// │ │ │ │ │ │
|
|
// ├─────┼─────┤ ==resize=down==> ├─────┤ │
|
|
// │ │█████│ │ ├─────┤
|
|
// │ │█████│ │ │█████│
|
|
// └─────┴─────┘ └─────┴─────┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 20,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_panes_below_aligned_left_with_current_pane() {
|
|
// ┌─────┬─────┐ ┌─────┬─────┐
|
|
// │ │█████│ │ │█████│
|
|
// │ │█████│ │ │█████│
|
|
// ├─────┼─────┤ ==resize=down==> ├─────┤█████│
|
|
// │ │ │ │ ├─────┤
|
|
// │ │ │ │ │ │
|
|
// └─────┴─────┘ └─────┴─────┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 20,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_panes_above_aligned_right_with_current_pane() {
|
|
// ┌─────┬─────┐ ┌─────┬─────┐
|
|
// │ │ │ │ │ │
|
|
// │ │ │ │ │ │
|
|
// ├─────┼─────┤ ==resize=down==> │ ├─────┤
|
|
// │█████│ │ ├─────┤ │
|
|
// │█████│ │ │█████│ │
|
|
// └─────┴─────┘ └─────┴─────┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 20,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_panes_below_aligned_right_with_current_pane() {
|
|
// ┌─────┬─────┐ ┌─────┬─────┐
|
|
// │█████│ │ │█████│ │
|
|
// │█████│ │ │█████│ │
|
|
// ├─────┼─────┤ ==resize=down==> │█████├─────┤
|
|
// │ │ │ ├─────┤ │
|
|
// │ │ │ │ │ │
|
|
// └─────┴─────┘ └─────┴─────┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 20,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_panes_above_aligned_left_and_right_with_current_pane() {
|
|
// ┌───┬───┬───┐ ┌───┬───┬───┐
|
|
// │ │ │ │ │ │ │ │
|
|
// │ │ │ │ │ │ │ │
|
|
// ├───┼───┼───┤ ==resize=down==> ├───┤ ├───┤
|
|
// │ │███│ │ │ ├───┤ │
|
|
// │ │███│ │ │ │███│ │
|
|
// └───┴───┴───┘ └───┴───┴───┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 20,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_panes_below_aligned_left_and_right_with_current_pane() {
|
|
// ┌───┬───┬───┐ ┌───┬───┬───┐
|
|
// │ │███│ │ │ │███│ │
|
|
// │ │███│ │ │ │███│ │
|
|
// ├───┼───┼───┤ ==resize=down==> ├───┤███├───┤
|
|
// │ │ │ │ │ ├───┤ │
|
|
// │ │ │ │ │ │ │ │
|
|
// └───┴───┴───┘ └───┴───┴───┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 20,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_panes_above_aligned_left_and_right_with_panes_to_the_left_and_right() {
|
|
// ┌─┬───────┬─┐ ┌─┬───────┬─┐
|
|
// │ │ │ │ │ │ │ │
|
|
// │ │ │ │ │ │ │ │
|
|
// ├─┼─┬───┬─┼─┤ ==resize=down==> ├─┤ ├─┤
|
|
// │ │ │███│ │ │ │ ├─┬───┬─┤ │
|
|
// │ │ │███│ │ │ │ │ │███│ │ │
|
|
// └─┴─┴───┴─┴─┘ └─┴─┴───┴─┴─┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 40,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_VERTICALLY,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_LEFT,
|
|
&RESIZE_LEFT,
|
|
&RESIZE_LEFT,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_VERTICALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_LEFT,
|
|
&RESIZE_LEFT,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn resize_down_with_panes_below_aligned_left_and_right_with_to_the_left_and_right() {
|
|
// ┌─┬─┬───┬─┬─┐ ┌─┬─┬───┬─┬─┐
|
|
// │ │ │███│ │ │ │ │ │███│ │ │
|
|
// │ │ │███│ │ │ │ │ │███│ │ │
|
|
// ├─┼─┴───┴─┼─┤ ==resize=down==> ├─┤ │███│ ├─┤
|
|
// │ │ │ │ │ ├─┴───┴─┤ │
|
|
// │ │ │ │ │ │ │ │
|
|
// └─┴───────┴─┘ └─┴───────┴─┘
|
|
// █ == focused pane
|
|
let fake_win_size = PositionAndSize {
|
|
columns: 121,
|
|
rows: 40,
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
|
|
|
fake_input_output.add_terminal_input(&[
|
|
&COMMAND_TOGGLE,
|
|
&COMMAND_TOGGLE,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_VERTICALLY,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_LEFT,
|
|
&RESIZE_LEFT,
|
|
&RESIZE_LEFT,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_HORIZONTALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&SPLIT_VERTICALLY,
|
|
&SPLIT_VERTICALLY,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_LEFT,
|
|
&RESIZE_LEFT,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&MOVE_FOCUS,
|
|
&RESIZE_DOWN,
|
|
&QUIT,
|
|
]);
|
|
|
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
|
|
|
let output_frames = fake_input_output
|
|
.stdout_writer
|
|
.output_frames
|
|
.lock()
|
|
.unwrap();
|
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
|
for snapshot in snapshots {
|
|
assert_snapshot!(snapshot);
|
|
}
|
|
}
|