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

feat: add keyword argument name in error message #779

Merged
merged 4 commits into from
Oct 17, 2023
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
1 change: 1 addition & 0 deletions kclvm/cmd/src/test_data/failed/keyword_argument_error.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = "{ID}".format(2) # keyword argument not found -> keyword argument 'ID' not found
22 changes: 20 additions & 2 deletions kclvm/cmd/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ fn test_run_command() {
test_conflict_mod_file();
test_instances_with_yaml();
test_plugin_not_found();
test_error_message_fuzz_matched();
test_error_message_fuzz_unmatched();
test_keyword_argument_error_message();
}

fn test_run_command_with_import() {
Expand Down Expand Up @@ -560,7 +563,6 @@ fn test_plugin_not_found() {
}
}

#[test]
fn test_error_message_fuzz_matched() {
let test_case_path = PathBuf::from("./src/test_data/fuzz_match/main.k");
let matches = app().arg_required_else_help(true).get_matches_from(&[
Expand All @@ -579,7 +581,6 @@ fn test_error_message_fuzz_matched() {
}
}

#[test]
fn test_error_message_fuzz_unmatched() {
let test_case_path = PathBuf::from("./src/test_data/fuzz_match/main_unmatched.k");
let matches = app().arg_required_else_help(true).get_matches_from(&[
Expand All @@ -596,3 +597,20 @@ fn test_error_message_fuzz_unmatched() {
}
}
}

fn test_keyword_argument_error_message() {
let test_case_path = PathBuf::from("./src/test_data/failed/keyword_argument_error.k");
let matches = app().arg_required_else_help(true).get_matches_from(&[
ROOT_CMD,
"run",
&test_case_path.canonicalize().unwrap().display().to_string(),
]);
let settings = must_build_settings(matches.subcommand_matches("run").unwrap());
let sess = Arc::new(ParseSession::default());
match exec_program(sess.clone(), &settings.try_into().unwrap()) {
Ok(_) => panic!("unreachable code."),
Err(msg) => {
assert!(msg.contains("keyword argument 'ID' not found"));
}
}
}
2 changes: 1 addition & 1 deletion kclvm/runtime/src/value/val_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ impl FormatString {
}
FieldType::Keyword(keyword) => kwargs
.dict_get_value(keyword.as_str())
.expect("keyword argument not found")
.expect(&format!("keyword argument '{}' not found", keyword))
.clone(),
};
for name_part in parts {
Expand Down
Loading