fix(testsuite): iobackend tests are now useable
This commit is contained in:
parent
79a73a23a0
commit
e11eca72dc
2 changed files with 46 additions and 42 deletions
|
|
@ -38,7 +38,7 @@ testsuite_SOURCES = ../tests/unit/lexer/lexer_tests.c \
|
||||||
../tests/unit/utils/utils_tests.c \
|
../tests/unit/utils/utils_tests.c \
|
||||||
../tests/unit/expansion/expand.c \
|
../tests/unit/expansion/expand.c \
|
||||||
../tests/unit/expansion/parse_var.c \
|
../tests/unit/expansion/parse_var.c \
|
||||||
#../tests/unit/io_backend/io_backend.c \
|
../tests/unit/io_backend/io_backend.c \
|
||||||
../tests/unit/utils/args.c \
|
../tests/unit/utils/args.c \
|
||||||
../tests/unit/utils/hash_map.c \
|
../tests/unit/utils/hash_map.c \
|
||||||
../tests/unit/utils/insert_into.c
|
../tests/unit/utils/insert_into.c
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ Test(IO_Backend, init_null)
|
||||||
{
|
{
|
||||||
struct iob_context ctx =
|
struct iob_context ctx =
|
||||||
{
|
{
|
||||||
.iob_mode = IOB_MODE_NULL;
|
.mode = IOB_MODE_NULL,
|
||||||
.args = NULL;
|
.args = NULL
|
||||||
};
|
};
|
||||||
int actual = iob_init(ctx);
|
int actual = iob_init(&ctx);
|
||||||
int expected = IOB_ERROR_BAD_ARG;
|
int expected = IOB_ERROR_BAD_ARG;
|
||||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||||
}
|
}
|
||||||
|
|
@ -23,10 +23,10 @@ Test(IO_Backend, init_stdin)
|
||||||
{
|
{
|
||||||
struct iob_context ctx =
|
struct iob_context ctx =
|
||||||
{
|
{
|
||||||
.iob_mode = IOB_MODE_STDIN;
|
.mode = IOB_MODE_STDIN,
|
||||||
.args = NULL;
|
.args = NULL
|
||||||
};
|
};
|
||||||
int actual = iob_init(ctx);
|
int actual = iob_init(&ctx);
|
||||||
int expected = 0;
|
int expected = 0;
|
||||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||||
iob_close();
|
iob_close();
|
||||||
|
|
@ -36,15 +36,16 @@ iob_close();
|
||||||
// Same applies for other tests
|
// Same applies for other tests
|
||||||
Test(IO_Backend, init_script)
|
Test(IO_Backend, init_script)
|
||||||
{
|
{
|
||||||
char *script_name = "script.tmp" struct iob_context ctx = {
|
char *script_name = "script.tmp";
|
||||||
.iob_mode = IOB_MODE_SCRIPT;
|
struct iob_context ctx = {
|
||||||
.args = script_name;
|
.mode = IOB_MODE_SCRIPT,
|
||||||
};
|
.args = script_name
|
||||||
// Create file
|
};
|
||||||
FILE *f = fopen(script_name, "w");
|
// Create file
|
||||||
fclose(f);
|
FILE *f = fopen(script_name, "w");
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
int actual = iob_init(ctx);
|
int actual = iob_init(&ctx);
|
||||||
int expected = 0;
|
int expected = 0;
|
||||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||||
iob_close();
|
iob_close();
|
||||||
|
|
@ -53,11 +54,12 @@ remove(script_name);
|
||||||
|
|
||||||
Test(IO_Backend, init_script_not_a_file)
|
Test(IO_Backend, init_script_not_a_file)
|
||||||
{
|
{
|
||||||
char *script_name = "not_a_file.tmp" struct iob_context ctx = {
|
char *script_name = "not_a_file.tmp";
|
||||||
.iob_mode = IOB_MODE_SCRIPT;
|
struct iob_context ctx = {
|
||||||
.args = script_name;
|
.mode = IOB_MODE_SCRIPT,
|
||||||
};
|
.args = script_name
|
||||||
int actual = iob_init(ctx);
|
};
|
||||||
|
int actual = iob_init(&ctx);
|
||||||
int expected = IOB_ERROR_CANNOT_OPEN_FILE;
|
int expected = IOB_ERROR_CANNOT_OPEN_FILE;
|
||||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||||
}
|
}
|
||||||
|
|
@ -66,21 +68,22 @@ Test(IO_Backend, init_script_null)
|
||||||
{
|
{
|
||||||
struct iob_context ctx =
|
struct iob_context ctx =
|
||||||
{
|
{
|
||||||
.iob_mode = IOB_MODE_SCRIPT;
|
.mode = IOB_MODE_SCRIPT,
|
||||||
.args = NULL;
|
.args = NULL
|
||||||
};
|
};
|
||||||
int actual = iob_init(ctx);
|
int actual = iob_init(&ctx);
|
||||||
int expected = IOB_ERROR_CANNOT_OPEN_FILE;
|
int expected = IOB_ERROR_CANNOT_OPEN_FILE;
|
||||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
Test(IO_Backend, init_cmd)
|
Test(IO_Backend, init_cmd)
|
||||||
{
|
{
|
||||||
char *cmd = "iamacommand --yesido" struct iob_context ctx = {
|
char *cmd = "iamacommand --yesido";
|
||||||
.iob_mode = IOB_MODE_CMD;
|
struct iob_context ctx = {
|
||||||
.args = cmd;
|
.mode = IOB_MODE_CMD,
|
||||||
};
|
.args = cmd
|
||||||
int actual = iob_init(ctx);
|
};
|
||||||
|
int actual = iob_init(&ctx);
|
||||||
int expected = 0;
|
int expected = 0;
|
||||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||||
iob_close();
|
iob_close();
|
||||||
|
|
@ -90,23 +93,24 @@ Test(IO_Backend, init_cmd_null)
|
||||||
{
|
{
|
||||||
struct iob_context ctx =
|
struct iob_context ctx =
|
||||||
{
|
{
|
||||||
.iob_mode = IOB_MODE_CMD;
|
.mode = IOB_MODE_CMD,
|
||||||
.args = NULL;
|
.args = NULL
|
||||||
};
|
};
|
||||||
int actual = iob_init(ctx);
|
int actual = iob_init(&ctx);
|
||||||
int expected = IOB_ERROR_BAD_ARG;
|
int expected = IOB_ERROR_BAD_ARG;
|
||||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
Test(IO_Backend, init_already_init)
|
Test(IO_Backend, init_already_init)
|
||||||
{
|
{
|
||||||
char *cmd = "iamacommand --yesido" struct iob_context ctx = {
|
char *cmd = "iamacommand --yesido";
|
||||||
.iob_mode = IOB_MODE_CMD;
|
struct iob_context ctx = {
|
||||||
.args = cmd;
|
.mode = IOB_MODE_CMD,
|
||||||
};
|
.args = cmd
|
||||||
iob_init(ctx);
|
};
|
||||||
int actual = iob_init(ctx);
|
iob_init(&ctx);
|
||||||
int expected = IOB_ERROR_ALREADY_INITIALIZED;
|
int actual = iob_init(&ctx);
|
||||||
|
int expected = IOB_ERROR_MODULE_ALREADY_INITIALIZED;
|
||||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||||
iob_close();
|
iob_close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue