Skip to content

Commit

Permalink
test: serialised extension dumping
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Jul 29, 2024
1 parent 081a0d0 commit 4a37118
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hugr-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum CliArgs {
/// Validate and visualize a HUGR file.
Validate(validate::CliArgs),
/// Write standard extensions out in serialized form.
GenExtension(extensions::ExtArgs),
GenExtensions(extensions::ExtArgs),
/// External commands
#[command(external_subcommand)]
External(Vec<OsString>),
Expand Down
2 changes: 1 addition & 1 deletion hugr-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use clap_verbosity_flag::Level;
fn main() {
match CliArgs::parse() {
CliArgs::Validate(args) => run_validate(args),
CliArgs::GenExtension(args) => args.run_dump(),
CliArgs::GenExtensions(args) => args.run_dump(),
CliArgs::External(_) => {
// TODO: Implement support for external commands.
// Running `hugr COMMAND` would look for `hugr-COMMAND` in the path
Expand Down
41 changes: 41 additions & 0 deletions hugr-cli/tests/gen_extensions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Tests for the CLI extension writing.
//!
//! Miri is globally disabled for these tests because they mostly involve
//! calling the CLI binary, which Miri doesn't support.
#![cfg(all(test, not(miri)))]

use assert_cmd::Command;
use rstest::{fixture, rstest};

#[fixture]
fn cmd() -> Command {
let mut cmd = Command::cargo_bin("hugr").unwrap();
cmd.arg("gen-extensions");
cmd
}

#[rstest]
fn test_extension_dump(mut cmd: Command) {
let temp_dir = assert_fs::TempDir::new()
.expect("temp dir creation failure.")
.into_persistent_if(std::env::var_os("HUGR_CLI_TEST_PERSIST_FILES").is_some());
cmd.arg("-o");
cmd.arg(temp_dir.path());
cmd.assert().success();

let expected_paths = [
"logic.json",
"prelude.json",
"ptr.json",
"arithmetic/int/types.json",
"arithmetic/float/types.json",
"arithmetic/int.json",
"arithmetic/float.json",
"arithmetic/conversions.json",
];
// check all paths exist
for path in expected_paths.iter() {
let full_path = temp_dir.join(path);
assert!(full_path.exists());
}
}

0 comments on commit 4a37118

Please sign in to comment.