summaryrefslogtreecommitdiff
path: root/test/command.c
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2023-01-26 13:07:07 +0100
committerAlbert Cervin <albert@acervin.com>2023-01-26 13:07:07 +0100
commite65158a0326108d1fc724ee683b7fa900ef2671a (patch)
tree9bad30b377a326e0d0e3101c4f96228ae7a41673 /test/command.c
parent9a2b138a03e27d0f04101fe6ae3977d79518c513 (diff)
downloaddged-e65158a0326108d1fc724ee683b7fa900ef2671a.tar.gz
dged-e65158a0326108d1fc724ee683b7fa900ef2671a.tar.xz
dged-e65158a0326108d1fc724ee683b7fa900ef2671a.zip
More tests and documentation
Also, split out platform-specific parts and add mocks for tests.
Diffstat (limited to 'test/command.c')
-rw-r--r--test/command.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/command.c b/test/command.c
index 738f5f9..be5fffc 100644
--- a/test/command.c
+++ b/test/command.c
@@ -72,8 +72,30 @@ void test_lookup_command() {
"Expected the found function to have the correct name");
}
+int32_t failing_command(struct command_ctx ctx, int argc, const char *argv[]) {
+ return 100;
+}
+
+void test_execute_command() {
+ struct commands cmds = single_fake_command("fake");
+ struct command *cmd = lookup_command(&cmds, "fake");
+
+ int32_t res = execute_command(cmd, &cmds, NULL, NULL, 0, NULL);
+ ASSERT(res == 0, "Expected to be able to execute command successfully");
+
+ register_command(&cmds, (struct command){
+ .fn = failing_command,
+ .name = "fejl",
+ .userdata = NULL,
+ });
+ struct command *fail_cmd = lookup_command(&cmds, "fejl");
+ int32_t res2 = execute_command(fail_cmd, &cmds, NULL, NULL, 0, NULL);
+ ASSERT(res2 != 0, "Expected failing command to fail");
+}
+
void run_command_tests() {
run_test(test_command_registry_create);
run_test(test_register_command);
run_test(test_lookup_command);
+ run_test(test_execute_command);
}