Skip to content
Snippets Groups Projects
Commit d01dee1c authored by tanguy.cavagna's avatar tanguy.cavagna :desktop:
Browse files

Added unit tests

parent 5c57527f
No related branches found
No related tags found
No related merge requests found
...@@ -7,9 +7,9 @@ LIBS:=-lm -lncurses ...@@ -7,9 +7,9 @@ LIBS:=-lm -lncurses
BIN = bin BIN = bin
# Get source and object # Get source and object
SRCS = $(filter-out $(wildcard */*_tests.c */*test.c */*tests.c */*_test.c), $(wildcard *.c */*.c)) SRCS = $(filter-out $(wildcard test.c */*/*-test.c unity/unity.c), $(wildcard *.c */*.c))
OBJS = $(addprefix $(BIN)/, $(SRCS:.c=.o)) OBJS = $(addprefix $(BIN)/, $(SRCS:.c=.o))
SRCS_TEST = $(filter-out $(wildcard main.c */main.c gfx/*), $(wildcard *.c */*.c)) SRCS_TEST = $(filter-out $(wildcard main.c), $(wildcard *.c */*/*.c */*.c))
OBJS_TEST = $(addprefix $(BIN)/, $(SRCS_TEST:.c=.o)) OBJS_TEST = $(addprefix $(BIN)/, $(SRCS_TEST:.c=.o))
# Create the target # Create the target
...@@ -26,8 +26,13 @@ $(BIN)/%.o: %.c ...@@ -26,8 +26,13 @@ $(BIN)/%.o: %.c
help: help:
@echo "src: $(SRCS)" @echo "src: $(SRCS)"
@echo "obj: $(OBJS)" @echo "obj: $(OBJS)"
@echo "obj_test: $(OBJ_TEST)" @echo "src_test: $(SRCS_TEST)"
@echo "obj_test: $(OBJS_TEST)"
test: $(OBJS_TEST)
$(CC) $(CFLAGS) -o $(BIN)/$@ $^ $(LIBS) $(LDFLAGS)
./$(BIN)/$@
clean: clean:
rm -rf $(BIN) rm -rf $(BIN)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <string.h> #include <string.h>
int main(void) { int main(void) {
srand(clock());
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
init_term(); init_term();
int menu_choice; int menu_choice;
......
test.c 0 → 100644
#include "unity/unity.h"
#include "word-bank/test/bank-test.h"
void setUp(void) {
// set stuff up here
}
void tearDown(void) {
// clean stuff up here
}
// not needed when using generate_test_runner.rb
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_random_word_should_be_jeter);
return UNITY_END();
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -115,7 +115,6 @@ int count_words() { ...@@ -115,7 +115,6 @@ int count_words() {
char *get_random_word() { char *get_random_word() {
if (bank == NULL) { if (bank == NULL) {
srand(clock());
init_bank(); init_bank();
load_bank(); load_bank();
} }
......
#include "bank-test.h"
void test_random_word_should_be_jeter(void) {
srand(2022);
char *word = get_random_word();
TEST_ASSERT_EQUAL_STRING("JETER", word);
}
#ifndef BANK_TEST_H
#define BANK_TEST_H
#include "../../unity/unity.h"
#include "../bank.h"
#include <stdio.h>
#include <time.h>
void test_random_word_should_be_jeter(void);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment