Initial BDD testing setup

pull/48/head
Arijit Basu 3 years ago committed by Arijit Basu
parent 080e1686f3
commit d34dc77ea5

488
Cargo.lock generated

@ -2,6 +2,24 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "anyhow"
version = "1.0.40"
@ -20,6 +38,38 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "async-stream"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3670df70cbc01729f901f94c887814b3c68db038aad1329a418bae178bc5295c"
dependencies = [
"async-stream-impl",
"futures-core",
]
[[package]]
name = "async-stream-impl"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3548b8efc9f8e8a5a0a2808c5bd8451a9031b9e5b879a79590304ae928b0a70"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "async-trait"
version = "0.1.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36ea56748e10732c49404c153638a15ec3d6211ec5ff35d9bb20e13b93576adf"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -111,6 +161,12 @@ version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "bytes"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040"
[[package]]
name = "cassowary"
version = "0.3.0"
@ -158,9 +214,13 @@ version = "2.33.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"textwrap",
"strsim",
"textwrap 0.11.0",
"unicode-width",
"vec_map",
]
[[package]]
@ -297,6 +357,39 @@ dependencies = [
"memchr",
]
[[package]]
name = "cucumber_rust"
version = "0.8.4"
source = "git+https://github.com/bbqsrc/cucumber-rust?branch=main#93bdaaf0b358fd34a682e3b8f6bc0ac75f794e77"
dependencies = [
"async-stream",
"async-trait",
"clap",
"cute_custom_default",
"futures",
"futures-timer",
"gherkin_rust",
"globwalk",
"once_cell",
"pathdiff",
"regex",
"shh",
"termcolor",
"textwrap 0.12.1",
"thiserror",
"tracing",
]
[[package]]
name = "cute_custom_default"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed431abf442833fd62ad7cc527a3833d969155c803f0dcf7f8a68db8adddc4c5"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "digest"
version = "0.8.1"
@ -356,6 +449,12 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "fsevent"
version = "0.4.0"
@ -391,6 +490,104 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "futures"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815"
[[package]]
name = "futures-executor"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10f6cb7042eda00f0049b1d2080aa4b93442997ee507eb3828e8bd7577f94c9d"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04"
[[package]]
name = "futures-macro"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "668c6733a182cd7deb4f1de7ba3bf2120823835b3bcfbeacf7d2c4a773c1bb8b"
dependencies = [
"proc-macro-hack",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23"
[[package]]
name = "futures-task"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc"
[[package]]
name = "futures-timer"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c"
[[package]]
name = "futures-util"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"pin-utils",
"proc-macro-hack",
"proc-macro-nested",
"slab",
]
[[package]]
name = "generic-array"
version = "0.12.4"
@ -411,6 +608,47 @@ dependencies = [
"wasi 0.9.0+wasi-snapshot-preview1",
]
[[package]]
name = "gherkin_rust"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ff71b5e012707c7c18bdb710e07736898aba0451f6ffbd435c892dd993053c"
dependencies = [
"heck",
"peg",
"quote",
"serde",
"serde_json",
"syn",
"textwrap 0.12.1",
"thiserror",
"typed-builder",
]
[[package]]
name = "globset"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c152169ef1e421390738366d2f796655fec62621dabbd0fd476f905934061e4a"
dependencies = [
"aho-corasick",
"bstr",
"fnv",
"log",
"regex",
]
[[package]]
name = "globwalk"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc"
dependencies = [
"bitflags",
"ignore",
"walkdir",
]
[[package]]
name = "half"
version = "1.7.1"
@ -431,6 +669,15 @@ dependencies = [
"serde_json",
]
[[package]]
name = "heck"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.1.18"
@ -440,6 +687,24 @@ dependencies = [
"libc",
]
[[package]]
name = "ignore"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b287fb45c60bb826a0dc68ff08742b9d88a2fea13d6e0c286b3172065aaf878c"
dependencies = [
"crossbeam-utils",
"globset",
"lazy_static",
"log",
"memchr",
"regex",
"same-file",
"thread_local",
"walkdir",
"winapi-util",
]
[[package]]
name = "inotify"
version = "0.7.1"
@ -738,6 +1003,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
[[package]]
name = "once_cell"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
[[package]]
name = "oorandom"
version = "11.1.3"
@ -775,6 +1046,39 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "pathdiff"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877630b3de15c0b64cc52f659345724fbf6bdad9bd9566699fc53688f3c34a34"
[[package]]
name = "peg"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f76678828272f177ac33b7e2ac2e3e73cc6c1cd1e3e387928aa69562fa51367"
dependencies = [
"peg-macros",
"peg-runtime",
]
[[package]]
name = "peg-macros"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "636d60acf97633e48d266d7415a9355d4389cea327a193f87df395d88cd2b14d"
dependencies = [
"peg-runtime",
"proc-macro2",
"quote",
]
[[package]]
name = "peg-runtime"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9555b1514d2d99d78150d3c799d4c357a3e2c2a8062cd108e93a06d9057629c5"
[[package]]
name = "pest"
version = "2.1.3"
@ -818,6 +1122,18 @@ dependencies = [
"sha-1",
]
[[package]]
name = "pin-project-lite"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "plotters"
version = "0.3.0"
@ -846,6 +1162,18 @@ dependencies = [
"plotters-backend",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]]
name = "proc-macro-nested"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
[[package]]
name = "proc-macro2"
version = "1.0.26"
@ -936,6 +1264,8 @@ version = "1.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
@ -1076,6 +1406,16 @@ dependencies = [
"opaque-debug",
]
[[package]]
name = "shh"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5205eb079ac8be8ec77b7470aff4a050610d42c32819deee362ca414c926d3ab"
dependencies = [
"libc",
"winapi 0.3.9",
]
[[package]]
name = "signal-hook"
version = "0.1.17"
@ -1108,6 +1448,12 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "syn"
version = "1.0.68"
@ -1119,6 +1465,25 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "terminal_size"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406"
dependencies = [
"libc",
"winapi 0.3.9",
]
[[package]]
name = "termion"
version = "1.5.6"
@ -1140,6 +1505,45 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "textwrap"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
dependencies = [
"terminal_size",
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "thread_local"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd"
dependencies = [
"once_cell",
]
[[package]]
name = "time"
version = "0.1.44"
@ -1161,6 +1565,69 @@ dependencies = [
"serde_json",
]
[[package]]
name = "tokio"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722"
dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
"mio 0.7.11",
"num_cpus",
"once_cell",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"tokio-macros",
"winapi 0.3.9",
]
[[package]]
name = "tokio-macros"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f"
dependencies = [
"cfg-if 1.0.0",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f"
dependencies = [
"lazy_static",
]
[[package]]
name = "tui"
version = "0.14.0"
@ -1175,6 +1642,17 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "typed-builder"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f85f4270f4f449a3f2c0cf2aecc8415e388a597aeacc7d55fc749c5c968c8533"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "typenum"
version = "1.13.0"
@ -1214,6 +1692,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.3"
@ -1368,6 +1852,7 @@ dependencies = [
"chrono",
"criterion",
"crossterm",
"cucumber_rust",
"dirs",
"handlebars",
"lazy_static",
@ -1376,6 +1861,7 @@ dependencies = [
"serde",
"serde_yaml",
"termion",
"tokio",
"tui",
]

@ -27,7 +27,13 @@ lazy_static = "1.4.0"
[dev-dependencies]
criterion = "0.3"
cucumber_rust = { git = "https://github.com/bbqsrc/cucumber-rust", branch = "main" }
tokio = { version = "1.4.0", features = ["full"] }
[[bench]]
name = "navigation"
harness = false
[[test]]
name = "cucumber"
harness = false # Allows Cucumber to print output instead of libtest

@ -0,0 +1,16 @@
Feature: Default key bindings
Scenario: xplr exits with debug info when we press '#'
Given xplr is running
When I press "#"
And xplr processes the tasks
Then xplr performs "PrintAppStateAndQuit"
And xplr quits or waits for the next event
Scenario: xplr prints result and quits when I gress 'enter'
Given xplr is running
When I press "enter"
And xplr processes the tasks
Then xplr performs "PrintResultAndQuit"
And xplr quits or waits for the next event

@ -0,0 +1,54 @@
use cucumber_rust::{async_trait, criteria::feature, futures::FutureExt, Cucumber, World};
use std::convert::Infallible;
use std::fs;
use xplr::app;
mod steps;
pub enum MyWorld {
Nothing,
App(app::App),
MsgOutList(Vec<app::MsgOut>),
}
#[async_trait(?Send)]
impl World for MyWorld {
type Error = Infallible;
async fn new() -> Result<Self, Infallible> {
Ok(Self::Nothing)
}
}
#[tokio::main]
async fn main() {
Cucumber::<MyWorld>::new()
// Specifies where our feature files exist
.features(&["./features"])
// Adds the implementation of our steps to the runner
.steps(steps::key_bindings::steps())
// Add some lifecycle functions to manage our database nightmare
.before(feature("Example feature"), |_| {
async move {
fs::create_dir_all("/tmp/xplr_bdd").unwrap();
(1..100).for_each(|i| {
fs::File::create(format!("/tmp/xplr_bdd/{}", i)).unwrap();
})
}
.boxed()
})
.after(feature("Example feature"), |_| {
async move {
fs::create_dir_all("/tmp/xplr_bench").unwrap();
(1..100).for_each(|i| {
fs::remove_file(format!("/tmp/xplr_bdd/{}", i)).unwrap();
})
}
.boxed()
})
// Parses the command line arguments if passed
.cli()
// Runs the Cucumber tests and then exists
.run_and_exit()
.await
}

@ -0,0 +1,82 @@
use cucumber_rust::Steps;
use crate::MyWorld;
use xplr::app;
use xplr::input::Key;
pub fn steps() -> Steps<MyWorld> {
let mut steps: Steps<MyWorld> = Steps::new();
steps.given("xplr is running", |_world, _ctx| {
let app = app::App::create("/tmp/xplr_bdd".into()).unwrap();
std::thread::sleep(std::time::Duration::from_millis(500));
MyWorld::App(app)
});
steps.when_regex(r#"I press "(.*)"$"#, |world, ctx| match world {
MyWorld::App(app) => {
let k = &ctx.matches[1];
let key: Key = serde_yaml::from_str(&k).unwrap_or_else(|_| k.clone().into());
let msg = app::MsgIn::Internal(app::InternalMsg::HandleKey(key.clone()));
let task = app::Task::new(msg, Some(key));
MyWorld::App(app.handle_task(task).unwrap())
}
_ => {
panic!("invalid world state")
}
});
steps.when("xplr processes the tasks", |world, _ctx| match world {
MyWorld::App(app) => {
let mut app = app;
let mut msgs = vec![];
while let Some(msg) = app.pop_msg_out() {
match msg {
app::MsgOut::Enque(task) => {
app = app.handle_task(task).unwrap();
}
msg => {
msgs.push(msg);
}
}
}
MyWorld::MsgOutList(msgs)
}
_ => {
panic!("invalid world state")
}
});
steps.then_regex(r#"xplr performs "(.*)"$"#, |world, ctx| {
let mstr = &ctx.matches[1];
let msg = serde_yaml::from_str(&mstr).unwrap();
match world {
MyWorld::MsgOutList(msgs) => {
let mut msgs = msgs.into_iter();
assert_eq!(msgs.next(), Some(msg));
MyWorld::MsgOutList(msgs.collect())
}
_ => {
panic!("invalid world state")
}
}
});
steps.then(
"xplr quits or waits for the next event",
|world, _ctx| match world {
MyWorld::MsgOutList(msgs) => {
let mut msgs = msgs.into_iter();
assert_eq!(msgs.next(), None);
MyWorld::Nothing
}
_ => {
panic!("invalid world state")
}
},
);
steps
}

@ -0,0 +1 @@
pub mod key_bindings;
Loading…
Cancel
Save