diff --git a/.github/workflows/vade.yml b/.github/workflows/vade.yml index 4dbe781..944ac60 100644 --- a/.github/workflows/vade.yml +++ b/.github/workflows/vade.yml @@ -14,6 +14,6 @@ jobs: steps: - uses: actions/checkout@v3 - name: Install dependencies - run: sudo apt install --quiet -y make gcc python3 bash valgrind nasm + run: sudo apt update && sudo apt install --quiet -y make gcc python3 bash valgrind nasm - name: Build and test run: bin/vade clean test diff --git a/Makefile b/Makefile index e99475e..ee24791 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,9 @@ ifeq ($(CC),$(CLANG)) VALGRIND:= endif -ifeq (, $(shell which $(VALGRIND) 2>/dev/null)) +ifneq (,$(VALGRIND)) +# Check if valgrind is operational (eg: not missing debuginfo etc..) +ifneq (0, $(shell ($(VALGRIND) /bin/true 2>/dev/null ; echo $$?))) #$(error "NOT HAVE VALGRIND ($(VALGRIND))") RUN:= RUNTEST:=RUN @@ -71,6 +73,8 @@ else VGRUN:=$(VALGRIND) $(VGOPTS) RUNTEST:=VGRUN endif +endif + RUNPYTEST:=RUNPY ifeq (, $(shell which $(GCOV) 2>/dev/null)) diff --git a/vade/src/open_close/open_close.c b/vade/src/open_close/open_close.c new file mode 100644 index 0000000..ba0e860 --- /dev/null +++ b/vade/src/open_close/open_close.c @@ -0,0 +1,40 @@ +#include "open_close.h" +#include +#include + +printer_t *printer() { + printer_t *p = calloc(1, sizeof(printer_t)); + p->text = calloc(1, 1); +} +void printer_free(printer_t *p) { + if (p) { + free(p->text); + free(p); + } +} +void printer_print(printer_t *p, char *s) { + p->text = realloc(p->text, strlen(p->text) + strlen(s) + 1); + strcat(p->text, s); +} + +#include "test/test.h" +TEST_F(open_close, Printer_001_empty) { + printer_t *p = printer(); + EXPECT_STREQ("", p->text); + printer_free(p); +} + +TEST_F(open_close, Printer_002_one_print) { + printer_t *p = printer(); + printer_print(p, "hello"); + EXPECT_STREQ("hello", p->text); + printer_free(p); +} + +TEST_F(open_close, Printer_003_two_prints) { + printer_t *p = printer(); + printer_print(p, "hello"); + printer_print(p, " world!\n"); + EXPECT_STREQ("hello world!\n", p->text); + printer_free(p); +} diff --git a/vade/src/open_close/open_close.h b/vade/src/open_close/open_close.h new file mode 100644 index 0000000..46cfdeb --- /dev/null +++ b/vade/src/open_close/open_close.h @@ -0,0 +1,5 @@ +typedef struct { + char *text; +} printer_t; +extern printer_t *printer(); +extern void printer_print(printer_t *p, char *s);