Skip to content

Commit

Permalink
first infrastructure for unit-level tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 2, 2019
1 parent 6d82a72 commit 1c53865
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ help:
$(info lint | run lints with clippy)
$(info benchmark | just for fun, really)
$(info profile | only on linux - run callgrind and annotate it)
$(info unit-tests | run all unit test)
$(info continuous-unit-tests | run all unit test whenever something changes)
$(info journey-tests | run all stateless journey test)
$(info continuous-journey-tests | run all stateless journey test whenever something changes)
$(info -- Use docker for all dependencies - run make interactively from there ----------------)
Expand Down Expand Up @@ -33,6 +35,12 @@ profile: target/release/dua
benchmark: target/release/dua
hyperfine '$<'

unit-tests:
cargo test --test interactive

continuous-unit-tests:
watchexec $(MAKE) unit-tests

journey-tests: target/debug/dua
./tests/stateless-journey.sh $<

Expand Down
2 changes: 1 addition & 1 deletion src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod app {
pub struct App {}

impl App {
pub fn event_loop<B, R>(
pub fn process_events<B, R>(
&mut self,
terminal: &mut Terminal<B>,
keys: Keys<R>,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn run() -> Result<(), Error> {
.with_context(|_| "Interactive mode requires a connected terminal")?
};
let mut app = dua::interactive::App::initialize(&mut terminal, walk_options, input)?;
app.event_loop(&mut terminal, io::stdin().keys())?
app.process_events(&mut terminal, io::stdin().keys())?
}
Some(Aggregate {
input,
Expand Down
25 changes: 25 additions & 0 deletions tests/interactive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
mod app {
use dua::interactive::App;
use dua::{ByteFormat, Color, WalkOptions};
use failure::Error;
use std::path::Path;
use tui::backend::TestBackend;
use tui::Terminal;

#[test]
fn journey_with_single_path() -> Result<(), Error> {
let mut terminal = Terminal::new(TestBackend::new(40, 20))?;
let input = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/sample-01");

let app = App::initialize(
&mut terminal,
WalkOptions {
threads: 1,
byte_format: ByteFormat::Metric,
color: Color::None,
},
vec![input],
)?;
Ok(())
}
}

0 comments on commit 1c53865

Please sign in to comment.