use std::{path::PathBuf, sync::LazyLock};
use crate::{
common::{
self, BASE_64_CT, CL_CONTRACT, CL_ENGINE_TEST_SUPPORT, CL_EXECUTION_ENGINE, CL_TYPES,
PATCH_SECTION,
},
ARGS,
};
const PACKAGE_NAME: &str = "tests";
static CONTRACT_PACKAGE_ROOT: LazyLock<PathBuf> =
LazyLock::new(|| ARGS.root_path().join(PACKAGE_NAME));
static CARGO_TOML: LazyLock<PathBuf> = LazyLock::new(|| CONTRACT_PACKAGE_ROOT.join("Cargo.toml"));
static INTEGRATION_TESTS_RS: LazyLock<PathBuf> =
LazyLock::new(|| CONTRACT_PACKAGE_ROOT.join("src/integration_tests.rs"));
pub static TEST_DEPENDENCIES: LazyLock<String> = LazyLock::new(|| {
format!(
"{}{}{}{}{}",
CL_CONTRACT.display_with_features(false, vec!["test-support"]),
CL_ENGINE_TEST_SUPPORT.display_with_features(true, vec![]),
CL_EXECUTION_ENGINE.display_with_features(true, vec![]),
CL_TYPES.display_with_features(true, vec![]),
BASE_64_CT.display_with_features(true, vec![])
)
});
static CARGO_TOML_CONTENTS: LazyLock<String> = LazyLock::new(|| {
format!(
r#"[package]
name = "tests"
version = "0.1.0"
edition = "2021"
[dev-dependencies]
{}
[[bin]]
name = "integration-tests"
path = "src/integration_tests.rs"
bench = false
doctest = false
{}"#,
&*TEST_DEPENDENCIES, &*PATCH_SECTION
)
});
const INTEGRATION_TESTS_RS_CONTENTS: &str = include_str!("../resources/integration_tests.rs.in");
pub fn create() {
let tests_folder = INTEGRATION_TESTS_RS.parent().expect("should have parent");
common::create_dir_all(tests_folder);
common::write_file(&*INTEGRATION_TESTS_RS, INTEGRATION_TESTS_RS_CONTENTS);
common::write_file(&*CARGO_TOML, &*CARGO_TOML_CONTENTS);
}