diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Makefile | 12 | ||||
| -rwxr-xr-x | main | bin | 12972 -> 13724 bytes | |||
| -rw-r--r-- | main.c | 8 | ||||
| -rw-r--r-- | main.o | bin | 1412 -> 1172 bytes | |||
| -rw-r--r-- | words.c | 3 | ||||
| -rw-r--r-- | words.h | 1 | ||||
| -rw-r--r-- | words_test.c | 21 |
8 files changed, 41 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0c9b81 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +main @@ -1,11 +1,17 @@ CC=gcc -main : main.o - $(CC) main.o -lcgreen -o main +main : main.o words_test.o words.o + $(CC) main.o words_test.o words.o -lcgreen -o main ./main main.o : main.c $(CC) -c main.c +words.o : words.c + $(CC) -c words.c + +words_test.o : words_test.c + $(CC) -c words_test.c + clean: - rm main main.o + rm main *.o Binary files differ@@ -1,10 +1,12 @@ #include <cgreen/cgreen.h> -Describe(Cgreen); -BeforeEach(Cgreen) {} -AfterEach(Cgreen) {} +TestSuite *words_tests(); int main(int argc, char **argv) { TestSuite *suite = create_test_suite(); + add_suite(suite, words_tests()); + if (argc > 1) { + return run_single_test(suite, argv[1], create_text_reporter()); + } return run_test_suite(suite, create_text_reporter()); } Binary files differ@@ -0,0 +1,3 @@ +int split_words(char *sentence) { + return 0; +} @@ -0,0 +1 @@ +int split_words(char *sentence); diff --git a/words_test.c b/words_test.c new file mode 100644 index 0000000..0979409 --- /dev/null +++ b/words_test.c @@ -0,0 +1,21 @@ +#include <cgreen/cgreen.h> + +#include "words.h" +#include <string.h> + +Describe(Words); +BeforeEach(Words) {} +AfterEach(Words) {} + +Ensure(Words, returns_word_count) { + char *sentence = strdup("Birds of a feather"); + int word_count = split_words(sentence); + assert_that(word_count, is_equal_to(4)); + free(sentence); +} + +TestSuite *words_tests() { + TestSuite *suite = create_test_suite(); + add_test_with_context(suite, Words, returns_word_count); + return suite; +} |
