Skip to content

Commit

Permalink
[Fix] The way of getting testcases (#36)
Browse files Browse the repository at this point in the history
* fix the way of getting testcases

* update readme

* use parameterized macro

* fix

* fix

* fix
  • Loading branch information
logic-finder authored Jun 20, 2024
1 parent 96f6ab9 commit 3b1006c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 58 deletions.
24 changes: 15 additions & 9 deletions test/.test/btn.test
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
tests[0] = (testcase) { .name = "usual",
.argv = "10",
.input = "I hate programming in C so much.",
.output = "Ihateprogr\namminginCs\nomuch.\n" };
tests[1] = (testcase) { .name = "multiline",
.argv = "10",
.input = "I hate programming in C so much.\nI'm getting headache.",
.output = "Ihateprogr\namminginCs\nomuch.I'mg\nettinghead\nache.\n" };
tlen = 2;
TEST
(
"usual",
"10",
"I hate programming in C so much.",
"Ihateprogr\namminginCs\nomuch.\n"
)

TEST
(
"multiline",
"10",
"I hate programming in C so much.\nI'm getting headache.",
"Ihateprogr\namminginCs\nomuch.I'mg\nettinghead\nache.\n"
)
60 changes: 31 additions & 29 deletions test/.test/hd.test
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
tests[0] = (testcase)
{
.name = "no-heading",
.argv = "",
.input = "test",
.output = "# test\n"
};
tests[1] = (testcase)
{
.name = "heading",
.argv = "",
.input = "# test",
.output = "# test\n"
};
tests[2] = (testcase)
{
.name = "no_heading_multiline",
.argv = "",
.input = "test\ntest2\n",
.output = "# test\n# test2\n\n"
};
tests[3] = (testcase)
{
.name = "heading_multiline",
.argv = "",
.input = "# test\n# test2\n",
.output = "# test\n# test2\n\n"
};
tlen = 4;
TEST
(
"no-heading",
"",
"test",
"# test\n"
)

TEST
(
"heading",
"",
"# test",
"# test\n"
)

TEST
(
"no_heading_multiline",
"",
"test\ntest2\n",
"# test\n# test2\n\n"
)

TEST
(
"heading_multiline",
"",
"# test\n# test2\n",
"# test\n# test2\n\n"
)
39 changes: 23 additions & 16 deletions test/.test/nsy.test
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
tests[0] = (testcase) {
.name = "e-mark",
.argv = "e",
.input = "asdf",
.output = "!a!s!d!f!\n"};
tests[1] = (testcase) {
.name = "q-mark",
.argv = "q",
.input = "asdf",
.output = "?a?s?d?f?\n" };
tests[2] = (testcase) {
.name = "multiline",
.argv = "e",
.input = "asdf\nqwer",
.output = "!a!s!d!f!q!w!e!r!\n" };
tlen = 3;
TEST
(
"e-mark",
"e",
"asdf",
"!a!s!d!f!\n"
)

TEST
(
"q-mark",
"q",
"asdf",
"?a?s?d?f?\n"
)

TEST
(
"multiline",
"e",
"asdf\nqwer",
"!a!s!d!f!q!w!e!r!\n"
)
7 changes: 3 additions & 4 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ These programs require two things in order to run: (1) an executable of a progra
A testcase file has test cases to be used during a test. It must have the following shape, since this file is to be included in a `test.c` source code file, which will be compiled soon.

```
test[0] = (testcase) { .name = "", .argv = "", .input = "", .output = "" };
test[1] = (testcase) { .name = "", .argv = "", .input = "", .output = "" };
TEST("test-name-1", "argv", "input", "expected-output")
TEST("test-name-2", "argv", "input", "expected-output")
...
test[n] = (testcase) { .name = "", .argv = "", .input = "", .output = "" };
tlen = n + 1;
TEST("test-name-n", "argv", "input", "expected-output")
```

- name = the name of a test case.
Expand Down
11 changes: 11 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
#define TESTCASE_LEN 32
#define OUTPUT_LEN 1024
#define SYSTEM_FAILED -1
#
#define TEST(_name, _argv, _input, _output) \
if (tlen == TESTCASE_LEN) \
raise_err("test: reached TESTCASE_LEN."); \
tests[tlen++] = (testcase) { \
.name = _name, \
.argv = _argv, \
.input = _input, \
.output = _output \
};

typedef struct testcase_ {
char *name;
Expand Down Expand Up @@ -64,6 +74,7 @@ testcase *acquire_testcases(int *testcases_len_ptr) {
tests = malloc(TESTCASE_LEN * sizeof(testcase));
if (tests == NULL)
raise_err("test: failed to malloc.");
tlen = 0;

/*
* Include test cases. This line will be replaced
Expand Down

0 comments on commit 3b1006c

Please sign in to comment.