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

fix: test api user arguments #1563

Merged
merged 1 commit into from
Aug 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
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
);
}
Loading