Basic harness for unit tests

Adds catch.hpp - a test harness for writing and running unit tests.
Updated the make file so that running `make test` runs all the tests. I
removed all the tests that either didn't compile, failing on running or
didn't terminate without some input.

Added an example catch test to demonstrate it working.
This commit is contained in:
thk123 2017-04-25 14:08:49 +01:00
parent eac93e3178
commit 3391d459c0
4 changed files with 11483 additions and 49 deletions

View File

@ -1,24 +1,17 @@
SRC = cpp_parser.cpp \ .PHONY: all cprover.dir test
cpp_scanner.cpp \
elf_reader.cpp \ SRC = catch_entry_point.cpp \
float_utils.cpp \ catch_example.cpp \
ieee_float.cpp \
json.cpp \
miniBDD.cpp \
osx_fat_reader.cpp \
sharing_map.cpp \
sharing_node.cpp \
smt2_parser.cpp \
string_utils.cpp \
unicode.cpp \
wp.cpp \
# Empty last line # Empty last line
INCLUDES= -I ../src/ INCLUDES= -I ../src/ -I.
include ../src/config.inc include ../src/config.inc
include ../src/common include ../src/common
cprover.dir:
$(MAKE) $(MAKEARGS) -C ../src
LIBS = ../src/ansi-c/ansi-c$(LIBEXT) \ LIBS = ../src/ansi-c/ansi-c$(LIBEXT) \
../src/cpp/cpp$(LIBEXT) \ ../src/cpp/cpp$(LIBEXT) \
../src/json/json$(LIBEXT) \ ../src/json/json$(LIBEXT) \
@ -31,52 +24,33 @@ LIBS = ../src/ansi-c/ansi-c$(LIBEXT) \
../src/assembler/assembler$(LIBEXT) \ ../src/assembler/assembler$(LIBEXT) \
../src/analyses/analyses$(LIBEXT) \ ../src/analyses/analyses$(LIBEXT) \
../src/solvers/solvers$(LIBEXT) \ ../src/solvers/solvers$(LIBEXT) \
# Empty last line
CLEANFILES = $(SRC:.cpp=$(EXEEXT)) TESTS = catch_entry_point$(EXEEXT) \
miniBDD$(EXEEXT) \
string_utils$(EXEEXT) \
sharing_node$(EXEEXT) \
# Empty last line
CLEANFILES = $(TESTS)
all: cprover.dir
$(MAKE) $(MAKEARGS) $(TESTS)
test: all
$(foreach test,$(TESTS), (echo Running: $(test); ./$(test)) &&) true
all: $(SRC:.cpp=$(EXEEXT))
############################################################################### ###############################################################################
cpp_parser$(EXEEXT): cpp_parser$(OBJEXT) catch_entry_point$(EXEEXT): $(OBJ)
$(LINKBIN)
cpp_scanner$(EXEEXT): cpp_scanner$(OBJEXT)
$(LINKBIN)
elf_reader$(EXEEXT): elf_reader$(OBJEXT)
$(LINKBIN)
float_utils$(EXEEXT): float_utils$(OBJEXT)
$(LINKBIN)
ieee_float$(EXEEXT): ieee_float$(OBJEXT)
$(LINKBIN)
json$(EXEEXT): json$(OBJEXT)
$(LINKBIN) $(LINKBIN)
miniBDD$(EXEEXT): miniBDD$(OBJEXT) miniBDD$(EXEEXT): miniBDD$(OBJEXT)
$(LINKBIN) $(LINKBIN)
osx_fat_reader$(EXEEXT): osx_fat_reader$(OBJEXT)
$(LINKBIN)
smt2_parser$(EXEEXT): smt2_parser$(OBJEXT)
$(LINKBIN)
wp$(EXEEXT): wp$(OBJEXT)
$(LINKBIN)
string_utils$(EXEEXT): string_utils$(OBJEXT) string_utils$(EXEEXT): string_utils$(OBJEXT)
$(LINKBIN) $(LINKBIN)
sharing_map$(EXEEXT): sharing_map$(OBJEXT)
$(LINKBIN)
sharing_node$(EXEEXT): sharing_node$(OBJEXT) sharing_node$(EXEEXT): sharing_node$(OBJEXT)
$(LINKBIN) $(LINKBIN)
unicode$(EXEEXT): unicode$(OBJEXT)
$(LINKBIN)

11420
unit/catch.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
/*******************************************************************\
Module: Catch Tests
Author: DiffBlue Limited. All rights reserved.
\*******************************************************************/
#ifndef CATCH_ENTRY_POINT_H
#define CATCH_ENTRY_POINT_H
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#endif // CATCH_ENTRY_POINT_H

25
unit/catch_example.cpp Normal file
View File

@ -0,0 +1,25 @@
/*******************************************************************\
Module: Example Catch Tests
Author: DiffBlue Limited. All rights reserved.
\*******************************************************************/
#include <catch.hpp>
unsigned int Factorial(unsigned int number)
{
return number>1?Factorial(number-1)*number:1;
}
// This is an example unit test to demonstrate the build system and the
// catch unit test framework. The source code is taken from the documentation
// of catch.
TEST_CASE("Factorials are computed", "[core][factorial]")
{
REQUIRE(Factorial(1)==1);
REQUIRE(Factorial(2)==2);
REQUIRE(Factorial(3)==6);
REQUIRE(Factorial(10)==3628800);
}