Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c53865

Browse files
author
Sebastian Thiel
committed
first infrastructure for unit-level tests
1 parent 6d82a72 commit 1c53865

4 files changed

Lines changed: 35 additions & 2 deletions

File tree

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ help:
66
$(info lint | run lints with clippy)
77
$(info benchmark | just for fun, really)
88
$(info profile | only on linux - run callgrind and annotate it)
9+
$(info unit-tests | run all unit test)
10+
$(info continuous-unit-tests | run all unit test whenever something changes)
911
$(info journey-tests | run all stateless journey test)
1012
$(info continuous-journey-tests | run all stateless journey test whenever something changes)
1113
$(info -- Use docker for all dependencies - run make interactively from there ----------------)
@@ -33,6 +35,12 @@ profile: target/release/dua
3335
benchmark: target/release/dua
3436
hyperfine '$<'
3537

38+
unit-tests:
39+
cargo test --test interactive
40+
41+
continuous-unit-tests:
42+
watchexec $(MAKE) unit-tests
43+
3644
journey-tests: target/debug/dua
3745
./tests/stateless-journey.sh $<
3846

src/interactive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod app {
99
pub struct App {}
1010

1111
impl App {
12-
pub fn event_loop<B, R>(
12+
pub fn process_events<B, R>(
1313
&mut self,
1414
terminal: &mut Terminal<B>,
1515
keys: Keys<R>,

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn run() -> Result<(), Error> {
3939
.with_context(|_| "Interactive mode requires a connected terminal")?
4040
};
4141
let mut app = dua::interactive::App::initialize(&mut terminal, walk_options, input)?;
42-
app.event_loop(&mut terminal, io::stdin().keys())?
42+
app.process_events(&mut terminal, io::stdin().keys())?
4343
}
4444
Some(Aggregate {
4545
input,

tests/interactive.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
mod app {
2+
use dua::interactive::App;
3+
use dua::{ByteFormat, Color, WalkOptions};
4+
use failure::Error;
5+
use std::path::Path;
6+
use tui::backend::TestBackend;
7+
use tui::Terminal;
8+
9+
#[test]
10+
fn journey_with_single_path() -> Result<(), Error> {
11+
let mut terminal = Terminal::new(TestBackend::new(40, 20))?;
12+
let input = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/sample-01");
13+
14+
let app = App::initialize(
15+
&mut terminal,
16+
WalkOptions {
17+
threads: 1,
18+
byte_format: ByteFormat::Metric,
19+
color: Color::None,
20+
},
21+
vec![input],
22+
)?;
23+
Ok(())
24+
}
25+
}

0 commit comments

Comments
 (0)