Skip to content

Commit

Permalink
tests: more test cases for CLI.
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Jan 24, 2025
1 parent 37f1061 commit b4e8ad9
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ wild = "2.2.1"

[dev-dependencies]
assert_cmd = "2.0.16"
assert_fs = "1.1.2"
predicates = { workspace = true }
70 changes: 70 additions & 0 deletions cli/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use assert_cmd::Command;
use assert_fs::prelude::*;
use assert_fs::TempDir;
use predicates::prelude::*;

#[test]
Expand Down Expand Up @@ -273,6 +275,29 @@ fn cli_scan_compiled_rules() {
.failure()
.code(1)
.stderr("error: can\'t use namespace with \'--compiled-rules\'\n");

let temp_dir = TempDir::new().unwrap();
let input_file = temp_dir.child("rule.yar");

input_file.write_str("rule test { condition: true }").unwrap();

Command::cargo_bin("yr")
.unwrap()
.arg("compile")
.arg("-o")
.arg(input_file.with_extension("yarc"))
.arg(input_file.path())
.assert()
.success();

Command::cargo_bin("yr")
.unwrap()
.arg("scan")
.arg("--compiled-rules")
.arg(input_file.with_extension("yarc"))
.arg("src/tests/testdata/dummy.file")
.assert()
.success();
}

#[test]
Expand Down Expand Up @@ -313,3 +338,48 @@ fn cli_issue_280() {
.assert()
.success();
}

#[cfg(feature = "debug-cmd")]
#[test]
fn cli_debug_ast() {
Command::cargo_bin("yr")
.unwrap()
.arg("debug")
.arg("ast")
.arg("src/tests/testdata/foo.yar")
.assert()
.success();
}

#[cfg(feature = "debug-cmd")]
#[test]
fn cli_debug_cst() {
Command::cargo_bin("yr")
.unwrap()
.arg("debug")
.arg("cst")
.arg("src/tests/testdata/foo.yar")
.assert()
.success();
}

#[cfg(feature = "debug-cmd")]
#[test]
fn cli_debug_wasm() {
let temp_dir = TempDir::new().unwrap();
let input_file = temp_dir.child("rule.yar");

input_file.write_str("rule test { condition: true }").unwrap();

Command::cargo_bin("yr")
.unwrap()
.arg("debug")
.arg("wasm")
.arg(input_file.path())
.assert()
.success();

if !input_file.with_extension("wasm").exists() {
panic!("`yr debug wasm` didn't create .wasm file")
}
}

0 comments on commit b4e8ad9

Please sign in to comment.