63 lines
2.2 KiB
C
63 lines
2.2 KiB
C
#include "test_shell_commander.h"
|
|
#include "wapp.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
WpTestFuncResult test_commander_cmd_success(void) {
|
|
WpStr8List cmd = wpDblList(WpStr8);
|
|
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit("echo"));
|
|
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit("hello world"));
|
|
|
|
WpCmdResult result = wpShellCommanderExecute(SHELL_OUTPUT_DISCARD, NULL, &cmd);
|
|
b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
|
|
result.error == SHELL_ERR_NO_ERROR;
|
|
|
|
return wpTesterResult(succeeded);
|
|
}
|
|
|
|
WpTestFuncResult test_commander_cmd_failure(void) {
|
|
WpStr8List cmd = wpDblList(WpStr8);
|
|
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit("grep"));
|
|
|
|
WpCmdResult result = wpShellCommanderExecute(SHELL_OUTPUT_DISCARD, NULL, &cmd);
|
|
b8 failed = result.exited && result.exit_code != EXIT_SUCCESS &&
|
|
result.error == SHELL_ERR_NO_ERROR;
|
|
|
|
return wpTesterResult(failed);
|
|
}
|
|
|
|
WpTestFuncResult test_commander_cmd_out_buf_success(void) {
|
|
WpStr8 buf = wpStr8Buf(64);
|
|
WpStr8 expected = wpStr8Buf(64);
|
|
char msg[] = "hello world";
|
|
wpStr8CopyCstrCapped(&expected, msg);
|
|
|
|
WpStr8List cmd = wpDblList(WpStr8);
|
|
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit("echo"));
|
|
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit(msg));
|
|
|
|
WpCmdResult result = wpShellCommanderExecute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
|
b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
|
|
result.error == SHELL_ERR_NO_ERROR && wpStr8EqualToCount(&buf, &expected, strlen(msg));
|
|
|
|
return wpTesterResult(succeeded);
|
|
}
|
|
|
|
WpTestFuncResult test_commander_cmd_out_buf_failure(void) {
|
|
WpStr8 buf = wpStr8Buf(4);
|
|
WpStr8 expected = wpStr8Buf(64);
|
|
char msg[] = "hello world";
|
|
wpStr8CopyCstrCapped(&expected, msg);
|
|
|
|
WpStr8List cmd = wpDblList(WpStr8);
|
|
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit("echo"));
|
|
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit(msg));
|
|
|
|
WpCmdResult result = wpShellCommanderExecute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
|
b8 failed = !result.exited && result.exit_code != EXIT_SUCCESS &&
|
|
result.error == SHELL_ERR_OUT_BUF_FULL && !wpStr8Equal(&buf, &expected);
|
|
|
|
return wpTesterResult(failed);
|
|
}
|