Skip to content

Commit

Permalink
#148 End 2 End tests
Browse files Browse the repository at this point in the history
  • Loading branch information
la10736 committed Jun 19, 2022
1 parent 94229f7 commit 8429e03
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
6 changes: 6 additions & 0 deletions rstest/tests/integration.rs
Expand Up @@ -16,6 +16,12 @@ lazy_static! {
static ref ROOT_PROJECT: Project = Project::new(ROOT_DIR.as_ref());
}

pub fn base_prj() -> Project {
let prj_name = sanitize_name(testname());

ROOT_PROJECT.subproject(&prj_name)
}

pub fn prj() -> Project {
let prj_name = sanitize_name(testname());

Expand Down
17 changes: 17 additions & 0 deletions rstest/tests/resources/rstest/timeout_async.rs
@@ -0,0 +1,17 @@
use rstest::*;
use std::time::Duration;

fn ms(ms: u32) -> Duration {
Duration::from_millis(ms.into())
}

async fn delayed_sum(a: u32, b: u32,delay: Duration) -> u32 {
async_std::task::sleep(delay).await;
a + b
}

#[rstest]
#[timeout(ms(80))]
async fn single_pass() {
assert_eq!(4, delayed_sum(2, 2, ms(10)).await);
}
55 changes: 51 additions & 4 deletions rstest/tests/rstest/mod.rs
@@ -1,14 +1,16 @@
use std::path::Path;

use super::resources;

use mytest::*;
use rstest_test::*;
use unindent::Unindent;

fn prj(res: impl AsRef<Path>) -> Project {
pub fn resources(res: impl AsRef<Path>) -> std::path::PathBuf {
let path = Path::new("rstest").join(res.as_ref());
crate::prj().set_code_file(resources(path))
super::resources(path)
}

fn prj(res: impl AsRef<Path>) -> Project {
crate::prj().set_code_file(resources(res))
}

fn run_test(res: impl AsRef<Path>) -> (std::process::Output, String) {
Expand Down Expand Up @@ -933,6 +935,51 @@ fn timeout() {
.assert(output);
}

mod async_timeout_feature {
use super::*;

fn build_prj(features: &[&str]) -> Project {
let prj = crate::base_prj();
let features = match features.is_empty() {
true => String::new(),
false => format!(r#", features=["{}"]"#, features.join(r#"",""#)),
};
prj.add_dependency(
"rstest",
&format!(
r#"{{path="{}", default-features = false {}}}"#,
prj.exec_dir_str().as_str(),
features
),
);
prj.add_dependency("async-std", r#"{version="*", features=["attributes"]}"#);
prj
}

#[test]
fn should_not_compile_if_feature_disable() {
let prj = build_prj(&[]);
let output = prj
.set_code_file(resources("timeout_async.rs"))
.run_tests()
.unwrap();

assert_in!(output.stderr.str(), "error: Enable async-timeout feature");
}

#[test]
fn should_work_if_feature_enabled() {
let prj = build_prj(&["async-timeout"]);

let output = prj
.set_code_file(resources("timeout_async.rs"))
.run_tests()
.unwrap();

TestResults::new().ok("single_pass").assert(output);
}
}

mod should_show_correct_errors {
use std::process::Output;

Expand Down

0 comments on commit 8429e03

Please sign in to comment.