feat(parser): redirections
This commit is contained in:
parent
04ff7376eb
commit
8a5c589742
17 changed files with 78 additions and 108 deletions
|
|
@ -9,27 +9,19 @@ TestSuite(IO_Backend);
|
|||
|
||||
Test(IO_Backend, init_null)
|
||||
{
|
||||
struct iob_context ctx =
|
||||
{
|
||||
.mode = IOB_MODE_NULL,
|
||||
.args = NULL
|
||||
};
|
||||
struct iob_context ctx = { .mode = IOB_MODE_NULL, .args = NULL };
|
||||
int actual = iob_init(&ctx);
|
||||
int expected = IOB_ERROR_BAD_ARG;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
int expected = IOB_ERROR_BAD_ARG;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_stdin)
|
||||
{
|
||||
struct iob_context ctx =
|
||||
{
|
||||
.mode = IOB_MODE_STDIN,
|
||||
.args = NULL
|
||||
};
|
||||
struct iob_context ctx = { .mode = IOB_MODE_STDIN, .args = NULL };
|
||||
int actual = iob_init(&ctx);
|
||||
int expected = 0;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
int expected = 0;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
}
|
||||
|
||||
// WARNING: this one could fail because of iob_close in the previous test
|
||||
|
|
@ -37,82 +29,62 @@ iob_close();
|
|||
Test(IO_Backend, init_script)
|
||||
{
|
||||
char *script_name = "script.tmp";
|
||||
struct iob_context ctx = {
|
||||
.mode = IOB_MODE_SCRIPT,
|
||||
.args = script_name
|
||||
};
|
||||
struct iob_context ctx = { .mode = IOB_MODE_SCRIPT, .args = script_name };
|
||||
// Create file
|
||||
FILE *f = fopen(script_name, "w");
|
||||
fclose(f);
|
||||
|
||||
int actual = iob_init(&ctx);
|
||||
int expected = 0;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
remove(script_name);
|
||||
int expected = 0;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
remove(script_name);
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_script_not_a_file)
|
||||
{
|
||||
char *script_name = "not_a_file.tmp";
|
||||
struct iob_context ctx = {
|
||||
.mode = IOB_MODE_SCRIPT,
|
||||
.args = script_name
|
||||
};
|
||||
struct iob_context ctx = { .mode = IOB_MODE_SCRIPT, .args = script_name };
|
||||
int actual = iob_init(&ctx);
|
||||
int expected = IOB_ERROR_CANNOT_OPEN_FILE;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
int expected = IOB_ERROR_CANNOT_OPEN_FILE;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_script_null)
|
||||
{
|
||||
struct iob_context ctx =
|
||||
{
|
||||
.mode = IOB_MODE_SCRIPT,
|
||||
.args = NULL
|
||||
};
|
||||
struct iob_context ctx = { .mode = IOB_MODE_SCRIPT, .args = NULL };
|
||||
int actual = iob_init(&ctx);
|
||||
int expected = IOB_ERROR_CANNOT_OPEN_FILE;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
int expected = IOB_ERROR_CANNOT_OPEN_FILE;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_cmd)
|
||||
{
|
||||
char *cmd = "iamacommand --yesido";
|
||||
struct iob_context ctx = {
|
||||
.mode = IOB_MODE_CMD,
|
||||
.args = cmd
|
||||
};
|
||||
struct iob_context ctx = { .mode = IOB_MODE_CMD, .args = cmd };
|
||||
int actual = iob_init(&ctx);
|
||||
int expected = 0;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
int expected = 0;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_cmd_null)
|
||||
{
|
||||
struct iob_context ctx =
|
||||
{
|
||||
.mode = IOB_MODE_CMD,
|
||||
.args = NULL
|
||||
};
|
||||
struct iob_context ctx = { .mode = IOB_MODE_CMD, .args = NULL };
|
||||
int actual = iob_init(&ctx);
|
||||
int expected = IOB_ERROR_BAD_ARG;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
int expected = IOB_ERROR_BAD_ARG;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_already_init)
|
||||
{
|
||||
char *cmd = "iamacommand --yesido";
|
||||
struct iob_context ctx = {
|
||||
.mode = IOB_MODE_CMD,
|
||||
.args = cmd
|
||||
};
|
||||
struct iob_context ctx = { .mode = IOB_MODE_CMD, .args = cmd };
|
||||
iob_init(&ctx);
|
||||
int actual = iob_init(&ctx);
|
||||
int expected = IOB_ERROR_MODULE_ALREADY_INITIALIZED;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
}
|
||||
|
||||
Test(IO_Backend, close_not_init)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue