Skip to content

Commit

Permalink
feature: de-duplicated the cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide committed Nov 10, 2024
1 parent 97f3d1a commit be8d8d2
Showing 3 changed files with 74 additions and 1 deletion.
37 changes: 36 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -43,9 +43,11 @@ serde-inline-default = "0.2.2"
hostname = "0.4.0"
walkdir = "2.5.0"
toml_edit = "0.22.22"
which = '7.0.0'

[dev-dependencies]
assert_cmd = "2.0.16"
markdown = "1.0.0-alpha.21"

# The profile that 'cargo dist' will build with
[profile.dist]
36 changes: 36 additions & 0 deletions tests/cli_tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
use assert_cmd::{assert::OutputAssertExt, cargo::CommandCargoExt};
use markdown::{mdast::Node, ParseOptions};
use std::process::Command;

#[test]
fn unmanaged() {
let readme =
markdown::to_mdast(include_str!("../README.md"), &ParseOptions::default()).unwrap();

let mut nodes = Vec::new();
nodes.append(&mut readme.children().unwrap().clone());

let mut leaves = Vec::new();

while let Some(node) = nodes.pop() {
if let Some(children) = node.children() {
nodes.append(&mut children.clone());
} else {
leaves.push(node.clone());
}
}

let toml_blocks = leaves
.iter()
.filter_map(|x| {
if let Node::Code(code) = x {
Some(code)
} else {
None
}
})
.filter(|code| code.lang == Some("toml".to_string()))
.collect::<Vec<_>>();

let config = &toml_blocks[0].value;
let group = &toml_blocks[1].value;

std::fs::write("config.toml", config).unwrap();
std::fs::create_dir("groups").unwrap();
std::fs::write("groups/group.toml", group).unwrap();

let mut cmd = Command::cargo_bin("metapac").unwrap();
cmd.args(["--hostname", "pc", "--config-dir", ".", "unmanaged"]);
cmd.assert().success();

0 comments on commit be8d8d2

Please sign in to comment.