Basic test framework in place
This commit is contained in:
parent
62040d023e
commit
06a65cab7a
9
Makefile
9
Makefile
@ -1,6 +1,13 @@
|
||||
CC=tcc
|
||||
all: tests
|
||||
run: shortcodes
|
||||
./shortcodes
|
||||
shortcodes.c: shortcodes.rl
|
||||
ragel -G2 shortcodes.rl -o shortcodes.c
|
||||
shortcodes: shortcodes.c
|
||||
tcc shortcodes.c -lbg -g -o shortcodes
|
||||
$(CC) shortcodes.c -lbg -g -o shortcodes
|
||||
tests: shortcodes.c shortcodes.h tests.c
|
||||
$(CC) tests.c shortcodes.c -lbg -lcgreen -g -o tests
|
||||
./tests
|
||||
clean:
|
||||
rm -f shortcodes shortcodes.c
|
||||
|
@ -1 +1,4 @@
|
||||
char *parse(char *);
|
||||
#ifndef SHORTCODES_H
|
||||
#define SHORTCODES_H
|
||||
int parse(char *);
|
||||
#endif
|
||||
|
@ -159,13 +159,9 @@ int parse(char *input) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
parse(
|
||||
"bbb{{% sarasa sar1 sar2 \"sar3\" %}}ccc
|
||||
{{< c1 arg2 >}}foobar{{% /c1%}}aaa{{% sarasa name=\"pepe\" %}}");
|
||||
// if (output == 0) {
|
||||
// printf("parse error\n");
|
||||
// return 1;
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
// int main(int argc, char **argv) {
|
||||
// parse(
|
||||
// "bbb{{% sarasa sar1 sar2 \"sar3\" %}}ccc"
|
||||
// "{{< c1 arg2 >}}foobar{{% /c1%}}aaa{{% sarasa name=\"pepe\" %}}");
|
||||
// return 0;
|
||||
// };
|
||||
|
13
tests.c
13
tests.c
@ -1,22 +1,19 @@
|
||||
#!/usr/bin/tcc -run -lcgreen shortcodes.c bstrlib/bstrlib.c
|
||||
#include <cgreen/cgreen.h>
|
||||
#include "shortcodes.h"
|
||||
#include "bstrlib/bstrlib.h"
|
||||
|
||||
Describe(parse);
|
||||
BeforeEach(parse) {}
|
||||
AfterEach(parse) {}
|
||||
|
||||
Ensure(parse, is_identity) {
|
||||
char *input = "hello";
|
||||
bstring output = parse(input);
|
||||
printf("%s / %s", output->data, input);
|
||||
assert_that(output->data, is_equal_to_string("hello!"));
|
||||
Ensure(parse, empty_string) {
|
||||
char *input = "";
|
||||
int output = parse(input);
|
||||
assert_that(output, is_equal_to(0));
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
TestSuite *suite = create_test_suite();
|
||||
add_test_with_context(suite, parse, is_identity);
|
||||
add_test_with_context(suite, parse, empty_string);
|
||||
return run_test_suite(suite, create_text_reporter());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user