summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2019-06-02 13:20:05 +0530
committerSebastian Thiel <sthiel@thoughtworks.com>2019-06-02 13:20:05 +0530
commit1c538654fba3caf7f7d601d6bf8a4af24faf19c8 (patch)
treed384f68b43bb482a735ffa49d5ccd31d7ce29367
parent6d82a724b0452e417e20cbe8a02e3bed647e9674 (diff)
first infrastructure for unit-level tests
-rw-r--r--Makefile8
-rw-r--r--src/interactive.rs2
-rw-r--r--src/main.rs2
-rw-r--r--tests/interactive.rs25
4 files changed, 35 insertions, 2 deletions
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<B, R>(
+ pub fn process_events<B, R>(
&mut self,
terminal: &mut Terminal<B>,
keys: Keys<R>,
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(())
+ }
+}