From 1c538654fba3caf7f7d601d6bf8a4af24faf19c8 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 2 Jun 2019 13:20:05 +0530 Subject: first infrastructure for unit-level tests --- Makefile | 8 ++++++++ src/interactive.rs | 2 +- src/main.rs | 2 +- tests/interactive.rs | 25 +++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/interactive.rs diff --git a/Makefile b/Makefile index 405efb0..8dd4eba 100644 --- a/Makefile +++ b/Makefile @@ -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 ----------------) @@ -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 $< diff --git a/src/interactive.rs b/src/interactive.rs index e7b4d59..317f815 100644 --- a/src/interactive.rs +++ b/src/interactive.rs @@ -9,7 +9,7 @@ mod app { pub struct App {} impl App { - pub fn event_loop( + pub fn process_events( &mut self, terminal: &mut Terminal, keys: Keys, diff --git a/src/main.rs b/src/main.rs index 6c0d89b..758d975 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, diff --git a/tests/interactive.rs b/tests/interactive.rs new file mode 100644 index 0000000..52ae8bc --- /dev/null +++ b/tests/interactive.rs @@ -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(()) + } +} -- cgit v1.2.3