Bug fixes, shelving to fix another bug local_cpptest
authorKrista Bennett <krista@pep-project.org>
Tue, 01 May 2018 14:40:18 +0200
branchlocal_cpptest
changeset 263960be0da624a6
parent 2638 d52e41da942e
child 2640 1bf5b0421bd8
Bug fixes, shelving to fix another bug
test/Makefile
test/src/EngineTestSuite.cc
test/src/TestDriver.cc
     1.1 --- a/test/Makefile	Mon Apr 30 15:33:54 2018 +0200
     1.2 +++ b/test/Makefile	Tue May 01 14:40:18 2018 +0200
     1.3 @@ -7,16 +7,15 @@
     1.4  include ../default.conf
     1.5  
     1.6  HERE:=$(CURDIR)
     1.7 -TEST_HOME=$(HERE)pEp_test_home
     1.8 +TEST_HOME=$(HERE)/pEp_test_home
     1.9  
    1.10  TARGET=TestDriver
    1.11  
    1.12 -SRC_DIRS := ./src ./src/util ./src/engine_tests
    1.13 -SRCS := src/EngineTestSuite.cc src/EngineTestIndividualSuite.cc src/EngineTestSessionSuite.cc $(wildcard src/*/*.cc) src/SuiteMaker.cc src/TestDriver.cc
    1.14 +SRCS := $(wildcard src/*.cc) $(wildcard src/*/*.cc)
    1.15  OBJS := $(addsuffix .o,$(basename $(SRCS)))
    1.16  DEPS := $(OBJS:.o=.d)
    1.17  
    1.18 -INC_DIRS := ./include /usr/local/include #$(shell find $(SRC_DIRS) -type d) 
    1.19 +INC_DIRS := ./include /usr/local/include  
    1.20  INC_FLAGS := $(addprefix -I,$(INC_DIRS))
    1.21  
    1.22  LDFLAGS += -L/usr/local/lib
    1.23 @@ -80,108 +79,28 @@
    1.24  	endif
    1.25  endif
    1.26  
    1.27 -
    1.28  CPPFLAGS += $(INC_FLAGS) -MMD -MP
    1.29  
    1.30 +all: $(TARGET) test_home_
    1.31 +	
    1.32  $(TARGET): $(OBJS)
    1.33 -	$(CXX) $(CPPFLAGS) $(LDFLAGS) $(OBJS) -o $@ $(LOADLIBES) $(LDLIBS)
    1.34 +	$(CXX) $(CPPFLAGS) $(LDFLAGS) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@
    1.35  
    1.36 +.PHONY: test_home_
    1.37 +test_home_: 
    1.38 +	mkdir -p $(TEST_HOME)
    1.39 +
    1.40 +TEST_CMD_=$(TARGET)
    1.41 +
    1.42 +.PHONY: test
    1.43 +test: all
    1.44 +	./$(TARGET) $(TEST_CMD_)
    1.45 +	
    1.46  .PHONY: clean
    1.47  clean:
    1.48  	$(RM) $(TARGET) $(OBJS) $(DEPS)
    1.49  
    1.50 +
    1.51 +
    1.52  -include $(DEPS)
    1.53 -
    1.54 -
    1.55 -# 
    1.56 -# TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS) #HOME=$(TEST_HOME) GNUPGHOME=$(TEST_GNUPGHOME)
    1.57 -# 
    1.58 -# 
    1.59 -# CFLAGS:=$(filter-out -DNDEBUG,$(CFLAGS))
    1.60 -# ifneq ($(MAKECMDGOALS),clean)
    1.61 -# 	ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
    1.62 -# 		$(error The macro NDEBUG must not be defined for test compilation.)
    1.63 -# 	endif
    1.64 -# endif
    1.65 -# 
    1.66 -# CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
    1.67 -# ifneq ($(MAKECMDGOALS),clean)
    1.68 -# 	ifneq (,$(findstring -DNDEBUG,$(CXXFLAGS)))
    1.69 -# 		$(error The macro NDEBUG must not be defined for test compilation.)
    1.70 -# 	endif
    1.71 -# endif
    1.72 -# 
    1.73 -# # .PHONY: all
    1.74 -# # all: main
    1.75 -# 
    1.76 -# # don't delete .o files!
    1.77 -# .PRECIOUS: %.o
    1.78 -# 
    1.79 -# 
    1.80 -# SRC_DIRS ?= ./src
    1.81 -# 
    1.82 -# SRCS := $(wildcard src/*.cc) $(wildcard src/*/*.cc)
    1.83 -# OBJS := $(addsuffix .o,$(basename $(SRCS)))
    1.84 -# DEPS := $(OBJS:.o=.d)
    1.85 -# 
    1.86 -# CPPFLAGS += -I./include -MMD -MP
    1.87 -# 
    1.88 -# #	$(CC) $(LDFLAGS) $(OBJS) -o $@ $(LOADLIBES) $(LDLIBS)
    1.89 -# $(TARGET): $(OBJS)
    1.90 -# 	$(CXX) $(CXXFLAGS) $^ $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@
    1.91 -# 
    1.92 -# 
    1.93 -# .PHONY: test_home_
    1.94 -# test_home_: 
    1.95 -# 	mkdir -p $(TEST_HOME)
    1.96 -# 
    1.97 -# # .PHONY: clean
    1.98 -# # clean:
    1.99 -# # 	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) msg4.asc msg_encrypt_for_self.asc
   1.100 -# 
   1.101 -# 
   1.102 -# .PHONY: clean
   1.103 -# clean:
   1.104 -# 	$(RM) $(TARGET) $(OBJS) $(DEPS)
   1.105 -# 
   1.106 -# -include $(DEPS)
   1.107 -# 
   1.108 -# # .PHONY: main
   1.109 -# # main: TestDriver
   1.110 -# # 	
   1.111 -# # TestDriver : src/TestDriver
   1.112 -# # 	$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) $(LDLIBS) $(TESTOBJ) $(SUITEOBJ) -o TestDriver
   1.113 -# # 
   1.114 -# # .PHONY: testfiles
   1.115 -# # testfiles : $(TESTOBJ)
   1.116 -# # 	$(CXX) -c $(CXXFLAGS) $^ $(LDFLAGS) $(LDLIBS)
   1.117 -# # 
   1.118 -# # .PHONY: suitefiles	
   1.119 -# # suitefiles : $(SUITEOBJ)
   1.120 -# # 	$(CXX) -c $(CXXFLAGS) $^ $(LDFLAGS) $(LDLIBS)
   1.121 -# #  
   1.122 -# # # %_test : %_test.o test_util.o
   1.123 -# # # 	$(CXX) $^ $(LDFLAGS) $(LDLIBS) -o $@
   1.124 -# # # 
   1.125 -# # # %_run : % test_home_
   1.126 -# # # 	$(TEST_CMD_PFX) ./$<
   1.127 -# # # 
   1.128 -# # # %_lldb : % test_home_
   1.129 -# # # 	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
   1.130 -# # # 
   1.131 -# # # %_valgrind : % test_home_
   1.132 -# # # 	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
   1.133 -# # # 
   1.134 -# # # %_gdb : % test_home_
   1.135 -# # # 	$(TEST_CMD_PFX) gdb ./$<
   1.136 -# # 
   1.137 -# # # .PHONY: unit_tests
   1.138 -# # # unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
   1.139 -# # 
   1.140 -# # # .PHONY: compile
   1.141 -# # # compile: $(UNIT_TESTS) $(TARGET)
   1.142 -# # 
   1.143 -# # # Installs the engine, not the test binaries
   1.144 -# # .PHONY: install
   1.145 -# # install:
   1.146 -# # 	$(MAKE) -C .. install
   1.147 + 
     2.1 --- a/test/src/EngineTestSuite.cc	Mon Apr 30 15:33:54 2018 +0200
     2.2 +++ b/test/src/EngineTestSuite.cc	Tue May 01 14:40:18 2018 +0200
     2.3 @@ -11,43 +11,45 @@
     2.4      test_home = test_home_dir;
     2.5      
     2.6      // TODO: This is *nix specific, which the current testing env is anyway,
     2.7 -    // but it needn't remain so forever and always.
     2.8 -    prev_gpg_home = getenv("GNUPGHOME");
     2.9 +    // but it needn't remain so forever and always
    2.10 +    char* tmp = getenv("GNUPGHOME");
    2.11 +    if (tmp)
    2.12 +        prev_gpg_home = getenv("GNUPGHOME");
    2.13  }
    2.14  
    2.15  void EngineTestSuite::set_full_env() {
    2.16  
    2.17      if (test_home.empty())
    2.18 -        throw "SETUP: BAD INITIALISATION. No test home.";
    2.19 +        throw std::runtime_error("SETUP: BAD INITIALISATION. No test home.");
    2.20      
    2.21      int success = system("gpgconf --kill all");
    2.22      if (success != 0)
    2.23 -        throw "SETUP: Error when executing 'gpgconf --kill all'.";
    2.24 +        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");
    2.25      
    2.26      string home = getenv("HOME");
    2.27      if (test_home.compare(home) == 0 || test_home.compare(home + "/") == 0 ||
    2.28          test_home.compare(home + "/.gnupg") == 0 || test_home.compare(home + ".gnupg") == 0 ||
    2.29          test_home.compare(prev_gpg_home) == 0 || test_home.compare(prev_gpg_home + "/.gnupg") == 0 ||
    2.30          test_home.compare(prev_gpg_home + ".gnupg") == 0)
    2.31 -        throw "SETUP: new GNUPGHOME threatens to mess up user GNUPGHOME (and delete all their keys). NO DICE.";
    2.32 +        throw std::runtime_error("SETUP: new GNUPGHOME threatens to mess up user GNUPGHOME (and delete all their keys). NO DICE.");
    2.33      
    2.34      cout << "Ok - checked if new test home will be safe. We'll try and make the directory, deleting it if it has already exists." << endl;
    2.35      
    2.36      struct stat buf;
    2.37      if (stat(test_home.c_str(), &buf) == 0) {
    2.38          cout << test_home << " exists. We'll recursively delete. We hope we're not horking your whole system..." << endl;
    2.39 -        success = nftw(test_home.c_str(), util_delete_filepath, 100, FTW_DEPTH);
    2.40 +        success = nftw((test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
    2.41          if (success != 0)
    2.42 -            throw "SETUP: can't delete the whole directory.";
    2.43 +            throw std::runtime_error("SETUP: can't delete the whole directory.");
    2.44      }
    2.45      
    2.46      success = setenv("GNUPGHOME", (test_home + "/.gnupg").c_str(), 1);
    2.47      if (success != 0)
    2.48 -        throw "SETUP: Error when setting GNUPGHOME.";
    2.49 +        throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
    2.50  
    2.51      success = setenv("HOME", test_home.c_str(), 1);
    2.52      if (success != 0)
    2.53 -        throw "SETUP: Cannot set test_home for init.";
    2.54 +        throw std::runtime_error("SETUP: Cannot set test_home for init.");
    2.55      
    2.56      cout << "calling init()\n";
    2.57      PEP_STATUS status = init(&session);
    2.58 @@ -57,17 +59,17 @@
    2.59  
    2.60      success = setenv("HOME", home.c_str(), 1);
    2.61      if (success != 0)
    2.62 -        throw "SETUP: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!";    
    2.63 +        throw std::runtime_error("SETUP: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!");    
    2.64  }
    2.65  
    2.66  void EngineTestSuite::restore_full_env() {
    2.67      int success = system("gpgconf --kill all");
    2.68      if (success != 0)
    2.69 -        throw "RESTORE: Error when executing 'gpgconf --kill all'.";
    2.70 +        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
    2.71  
    2.72      success = setenv("GNUPGHOME", prev_gpg_home.c_str(), 1);
    2.73      if (success != 0)
    2.74 -        throw "RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!";
    2.75 +        throw std::runtime_error("RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!");
    2.76  }
    2.77  
    2.78  int EngineTestSuite::util_delete_filepath(const char *filepath, 
     3.1 --- a/test/src/TestDriver.cc	Mon Apr 30 15:33:54 2018 +0200
     3.2 +++ b/test/src/TestDriver.cc	Tue May 01 14:40:18 2018 +0200
     3.3 @@ -1,3 +1,4 @@
     3.4 +#include <stdlib.h>
     3.5  #include <cpptest.h>
     3.6  #include <cpptest-suite.h>
     3.7  #include <cpptest-textoutput.h>
     3.8 @@ -11,10 +12,10 @@
     3.9  
    3.10  using namespace std;
    3.11  
    3.12 -string common_test_home = "~/pEp_tests";
    3.13 +string common_test_home = "./pEp_test_home";
    3.14  
    3.15  void usage() {
    3.16 -    throw "Bad usage. Fix me, you loser developer.";
    3.17 +    throw std::runtime_error("Bad usage. Fix me, you loser developer.");
    3.18  }
    3.19  
    3.20  int main(int argc, char** argv) {
    3.21 @@ -24,35 +25,18 @@
    3.22  
    3.23      int start_index = 1;
    3.24      
    3.25 -
    3.26 -    if (argc > 1) {
    3.27 -        string tmpstr = argv[1];
    3.28 -        if (tmpstr.compare(0,10,"--testdir=")) {
    3.29 -            try {
    3.30 -                tmpstr = tmpstr.substr(10);
    3.31 -            } 
    3.32 -            catch (std::out_of_range o) {
    3.33 -                usage();
    3.34 -            }
    3.35 -            common_test_home = tmpstr;
    3.36 -            start_index++;
    3.37 -        }
    3.38 -    }
    3.39 -
    3.40      struct stat dirchk;
    3.41      if (stat(common_test_home.c_str(), &dirchk) == 0) {
    3.42          if (!S_ISDIR(dirchk.st_mode))
    3.43 -            throw ("The test directory, " + common_test_home + "exists, but is not a directory.").c_str(); 
    3.44 +            throw std::runtime_error(("The test directory, " + common_test_home + "exists, but is not a directory.").c_str()); 
    3.45      }
    3.46 -    else if (common_test_home.compare("~/pEp_tests")) {
    3.47 +    else {
    3.48          int errchk = mkdir(common_test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
    3.49 +        cout << errchk << endl;
    3.50          if (errchk != 0)
    3.51 -            throw "Error creating a test directory.";
    3.52 +            throw std::runtime_error("Error creating a test directory.");
    3.53      }
    3.54 -    else
    3.55 -        throw "Test directory does not exist. Test directories from the command line must be created first. Because we're lazy.";
    3.56 -        
    3.57 -            
    3.58 +                    
    3.59      EngineTestSuite* test_runner = new EngineTestSuite("MainTestDriver", common_test_home);
    3.60          
    3.61      for (int i = start_index; i < argc; i++) {
    3.62 @@ -60,7 +44,7 @@
    3.63          auto_ptr<Test::Suite> test_suite;
    3.64          suitemaker_build(argv[i], common_test_home.c_str(), test_suite);
    3.65          if (test_suite.get() == NULL)
    3.66 -            throw "Could not create a test suite instance."; // FIXME, better error, cleanup, obviously
    3.67 +            throw std::runtime_error("Could not create a test suite instance."); // FIXME, better error, cleanup, obviously
    3.68          test_runner->add(test_suite);
    3.69      }
    3.70