diff --git a/.gitignore b/.gitignore index 157050f..184c4f7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ !*.py !*.h !*.mk +!test_*.sh diff --git a/Makefile b/Makefile index 091111c..d060ed6 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,13 @@ all: $(EXERCISES) $(MAKE) -f ex19.mk +test: all + $(MAKE) -f ex19.mk test + + clean: rm -f $(EXERCISES) $(MAKE) -f ex19.mk clean -.PHONY: all clean +.PHONY: all test clean diff --git a/ex19.c b/ex19.c index 5acd311..1615261 100644 --- a/ex19.c +++ b/ex19.c @@ -46,7 +46,6 @@ Object MonsterProto = { void *Room_move(void *self, Direction direction) { assert(self != NULL); - assert(direction); Room *room = self; Room *next = NULL; @@ -70,6 +69,8 @@ void *Room_move(void *self, Direction direction) if(next) { next->_(describe)(next); + } else { + printf("mumble mumble.\n"); } return next; @@ -103,7 +104,6 @@ Object RoomProto = { void *Map_move(void *self, Direction direction) { assert(self != NULL); - assert(direction); Map *map = self; Room *location = map->location; @@ -113,6 +113,8 @@ void *Map_move(void *self, Direction direction) if(next) { map->location = next; + } else { + map->location = location; } return next; @@ -176,9 +178,6 @@ int process_input(Map *game) printf("\n> "); char ch = getchar(); - assert(ch != EOF); - getchar(); // eat ENTER - int damage = rand() % 4; switch(ch) { @@ -219,6 +218,7 @@ int process_input(Map *game) printf("What?: %d\n", ch); } + getchar(); // eat ENTER return 1; } diff --git a/ex19.mk b/ex19.mk index 96e5d90..ec75aa7 100644 --- a/ex19.mk +++ b/ex19.mk @@ -2,8 +2,16 @@ CFLAGS=-Wall -g all: ex19 + ex19: object.o + +test: + ./test_ex19.sh + + clean: - rm -f ex19 - rm -f object.o + rm -f ex19 object.o + + +.PHONY: all test clean diff --git a/object.c b/object.c index 268f169..63db33e 100644 --- a/object.c +++ b/object.c @@ -85,6 +85,7 @@ void *Object_new(size_t size, Object proto, char *description) return NULL; } else { // all done, we made an object of any type + assert(el != NULL); return el; } } diff --git a/test_ex19.sh b/test_ex19.sh new file mode 100755 index 0000000..6e2abb0 --- /dev/null +++ b/test_ex19.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +EXIT_CODE=0 + +run_test() +{ + echo -n " $1" + cat $2 | ./ex19 >/dev/null + if [[ $? -eq 0 ]] + then + echo " ... OK" + else + echo " ... FAIL" + EXIT_CODE=1 + fi + rm -f $2 +} + + +tmp_01=`mktemp` +cat > $tmp_01 < $tmp_02 <