Skip to content

Commit

Permalink
fix: test api user arguments (#1563)
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored Aug 13, 2024
1 parent 3916bfb commit 848b26b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions kclvm/tools/src/testing/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ impl TestRun for TestSuite {
let artifact = None;
artifact
};
// Save the user argument options.
let user_args = args.args;
// Test every case in the suite.
for (name, _) in &self.cases {
args.args = vec![ast::Argument {
name: TEST_CASE_RUN_OPTION.into(),
value: format!("{:?}", name),
}];
args.args.append(&mut user_args.clone());
let start = Instant::now();
// Check if is the fast eval mode.
let exec_result = if let Some(_artifact) = &artifact {
Expand Down
4 changes: 4 additions & 0 deletions kclvm/tools/src/testing/test_data/module/pkg/func_test.k
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ test_func_0 = lambda {
test_func_1 = lambda {
assert func("a") == "d"
}

test_func_2 = lambda {
assert func("a") == option("a"), "got {}".format(option("a"))
}
23 changes: 20 additions & 3 deletions kclvm/tools/src/testing/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use kclvm_ast::ast::Argument;
use kclvm_runner::ExecProgramArgs;

use crate::testing::TestRun;

use super::{load_test_suites, TestOptions};
use std::path::Path;

#[test]
fn test_load_test_suites_and_run() {
let opts = TestOptions::default();
let opts = TestOptions {
exec_args: ExecProgramArgs {
args: vec![Argument {
name: "a".to_string(),
value: "\"a\"".to_string(),
}],
..Default::default()
},
..Default::default()
};
let suites = load_test_suites(
Path::new(".")
.join("src")
Expand All @@ -19,14 +31,19 @@ fn test_load_test_suites_and_run() {
)
.unwrap();
assert_eq!(suites.len(), 1);
assert_eq!(suites[0].cases.len(), 2);
assert_eq!(suites[0].cases.len(), 3);
let test_result = suites[0].run(&opts).unwrap();
assert_eq!(test_result.info.len(), 2);
assert_eq!(test_result.info.len(), 3);
assert!(test_result.info[0].error.is_none());
assert!(test_result.info[1]
.error
.as_ref()
.unwrap()
.to_string()
.contains("Error"),);
assert!(
test_result.info[2].error.is_none(),
"{:?}",
test_result.info[2].error
);
}

0 comments on commit 848b26b

Please sign in to comment.