Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devenv: split out library #1263

Merged
merged 10 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 10 additions & 114 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,36 @@ members = [
"devenv",
"devenv-run-tests",
]

[workspace.package]
edition = "2021"
license = "APACHE-2.0"
license_file = "LICENSE"
homepage = "https://devenv.sh/"
repository = "https://github.com/cachix/devenv/"

[workspace.dependencies]
ansiterm = "0.12.2"
clap = { version = "4.5.1", features = ["derive", "cargo"] }
cli-table = "0.4.7"
dotlock = "0.5.0"
fs2 = "0.4.3"
hex = "0.4.3"
include_dir = "0.7.3"
indoc = "2.0.4"
miette = { version = "7.1.0", features = ["fancy"] }
nix = { version = "0.28.0", features = ["signal"] }
regex = "1.10.3"
reqwest = "0.11.26"
schematic = { version = "0.14.3", features = ["schema", "yaml", "renderer_template", "renderer_json_schema"] }
serde = "1.0.197"
serde_json = "1.0.114"
serde_yaml = "0.9.32"
sha2 = "0.10.8"
tempdir = "0.3.7"
tracing = "0.1.40"
which = "6.0.0"
whoami = "1.5.1"
xdg = "2.5.2"

schemars = "0.8.16"
5 changes: 3 additions & 2 deletions devenv-run-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "devenv-run-tests"
version = "0.1.0"
edition = "2018"
edition.workspace = true

[dependencies]
clap = { version = "3", features = ["derive"] }
clap.workspace = true
tempdir.workspace = true

devenv= { path = "../devenv" }
48 changes: 25 additions & 23 deletions devenv-run-tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::Parser;
use devenv::log::Level;
use devenv::log::Logger;
use devenv::{Devenv, DevenvOptions};
use std::fs;
use std::path::PathBuf;

Expand Down Expand Up @@ -37,7 +38,6 @@ fn run_tests_in_directory(args: &Args) -> Result<Vec<TestResult>, Box<dyn std::e
logger.info("Running Tests");

let cwd = std::env::current_dir()?;
let cwd = cwd.display();

let mut test_results = vec![];

Expand All @@ -47,14 +47,15 @@ fn run_tests_in_directory(args: &Args) -> Result<Vec<TestResult>, Box<dyn std::e

for path in paths {
let path = path?.path();
let path = path.as_path();
if path.is_dir() {
let dir_name_path = path.file_name().unwrap();
let dir_name = dir_name_path.to_str().unwrap();

if !args.only.is_empty() {
let mut found = false;
for only in &args.only {
if path.as_path().ends_with(only) {
if path.ends_with(only) {
found = true;
break;
}
Expand All @@ -64,7 +65,7 @@ fn run_tests_in_directory(args: &Args) -> Result<Vec<TestResult>, Box<dyn std::e
}
} else {
for exclude in &args.exclude {
if path.as_path().ends_with(exclude) {
if path.ends_with(exclude) {
println!("Skipping {}", dir_name);
continue;
}
Expand All @@ -78,31 +79,32 @@ fn run_tests_in_directory(args: &Args) -> Result<Vec<TestResult>, Box<dyn std::e
println!(" Running .setup.sh");
let _ = std::process::Command::new("bash")
.arg(".setup.sh")
.current_dir(&path)
.current_dir(path)
.status()?;
}
let overrides = args.override_input.iter().enumerate().flat_map(|(i, arg)| {
if i % 2 == 0 {
vec!["--override-input", arg.as_str()]
} else {
vec![arg.as_str()]
}
});
// TODO: use as a library
let status = std::process::Command::new("devenv")
.args([
"--override-input",
"devenv",
&format!("path:{cwd}?dir=src/modules"),
])
.args(overrides)
.arg("test")
.current_dir(&path)
.status()?;

let mut config = devenv::config::Config::load_from(path)?;
for input in args.override_input.chunks_exact(2) {
config.add_input(&input[0].clone(), &input[1].clone(), &[]);
}

let tmpdir = tempdir::TempDir::new_in(path, ".devenv")
.expect("Failed to create temporary directory");

let options = DevenvOptions {
config,
devenv_root: Some(cwd.join(path)),
devenv_dotfile: Some(tmpdir.path().to_path_buf()),
..Default::default()
};

let mut devenv = Devenv::new(options);
devenv.create_directories();

let status = devenv.test();
let result = TestResult {
name: dir_name.to_string(),
passed: status.success(),
passed: status.is_ok(),
};
test_results.push(result);
}
Expand Down
Loading
Loading