simplify defining suites

This commit is contained in:
Dustin J. Mitchell 2022-01-26 00:56:48 +00:00
parent f8cffb798c
commit dd87f7da1e
4 changed files with 34 additions and 31 deletions

View file

@ -26,7 +26,5 @@ Keep the `RUN_TEST`s in the same order as the functions they call.
To add a suite,
1. Add a new C file in `integration-tests/src/bindings_tests/`.
1. Add a new `.file(..)` to build that file in `integration-tests/build.rs`.
1. Add a `suite!(..)` to `integration-tests/src/bindings_tests/mod.rs`.
1. Add a `suite!(..)` to `integration-tests/tests/bindings.rs`.
1. Add a new C file in `integration-tests/src/bindings_tests/`, based off of one of hte others.
1. Add a the suite name to `suites` in `integration-tests/build.rs`.

View file

@ -1,36 +1,50 @@
fn main() {
use std::env;
use std::fs;
use std::path::Path;
fn build_libtaskchampion(suites: &[&'static str]) {
// This crate has taskchampion-lib in its build-dependencies, so
// libtaskchampion.so should be built already. Hopefully it's in target/$PROFILE, and hopefully
// it's named libtaskchampion.so and not something else
let mut libtaskchampion = std::env::current_dir().unwrap();
let mut libtaskchampion = env::current_dir().unwrap();
libtaskchampion.pop();
libtaskchampion.push("target");
libtaskchampion.push(std::env::var("PROFILE").unwrap());
libtaskchampion.push(env::var("PROFILE").unwrap());
libtaskchampion.push("deps");
libtaskchampion.push("libtaskchampion.so");
println!("cargo:rerun-if-changed=build.rs");
let mut build = cc::Build::new();
build.object(libtaskchampion);
build.include("../lib");
build.include("src/bindings_tests/unity");
build.file("src/bindings_tests/unity/unity.c");
let files = &[
"src/bindings_tests/test.c",
// keep this list in sync with integration-tests/src/bindings_tests/mod.rs and
// integration-tests/tests/bindings.rs
"src/bindings_tests/uuid.c",
"src/bindings_tests/string.c",
"src/bindings_tests/task.c",
"src/bindings_tests/replica.c",
];
let mut files = vec!["src/bindings_tests/test.c".to_string()];
for suite in suites {
files.push(format!("src/bindings_tests/{}.c", suite));
}
for file in files {
build.file(file);
build.file(&file);
println!("cargo:rerun-if-changed={}", file);
}
build.compile("bindings-tests");
}
fn make_suite_file(suites: &[&'static str]) {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("bindings_test_suites.rs");
let mut content = String::new();
for suite in suites {
content.push_str(format!("suite!({}_tests);\n", suite).as_ref());
}
fs::write(&dest_path, content).unwrap();
}
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let suites = &["uuid", "string", "task", "replica"];
build_libtaskchampion(suites);
make_suite_file(suites);
}

View file

@ -13,8 +13,4 @@ macro_rules! suite(
};
);
// keep this list in sync with integration-tests/build.rs and integration-tests/tests/bindings.rs.
suite!(uuid_tests);
suite!(string_tests);
suite!(task_tests);
suite!(replica_tests);
include!(concat!(env!("OUT_DIR"), "/bindings_test_suites.rs"));

View file

@ -7,9 +7,4 @@ macro_rules! suite(
};
);
// keep this list in sync with integration-tests/build.rs and
// integration-tests/src/bindings_tests/mod.rs
suite!(uuid_tests);
suite!(string_tests);
suite!(task_tests);
suite!(replica_tests);
include!(concat!(env!("OUT_DIR"), "/bindings_test_suites.rs"));