Tests : use $HOME to sandbox test`s management DB and keyrings
authorEdouard Tisserant <edouard@pep-project.org>
Fri, 09 Jun 2017 15:11:11 +0200
changeset 1844415b5ea8bfd1
parent 1842 dcd86e0c4a58
child 1845 40bfde56746e
Tests : use $HOME to sandbox test`s management DB and keyrings
test/Makefile
     1.1 --- a/test/Makefile	Fri Jun 09 14:34:58 2017 +0200
     1.2 +++ b/test/Makefile	Fri Jun 09 15:11:11 2017 +0200
     1.3 @@ -2,10 +2,10 @@
     1.4  # This file is under GNU General Public License 3.0
     1.5  # see LICENSE.txt
     1.6  
     1.7 +HERE := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
     1.8 +
     1.9  include ../Makefile.conf
    1.10  
    1.11 -export GNUPGHOME=.
    1.12 -
    1.13  CC?=g++ -std=gnu++11 -pthread
    1.14  CXX?=g++ -std=gnu++11 -pthread
    1.15  LD?=$(CXX)
    1.16 @@ -34,32 +34,49 @@
    1.17  # don't delete .o files!
    1.18  .PRECIOUS: %.o
    1.19  
    1.20 +unexport GNUPGHOME;
    1.21 +TEST_HOME=$(HERE)/test_home
    1.22 +TEST_HOME_SKEL=$(TEST_HOME)_skel
    1.23 +TEST_GNUPGHOME_SKEL=$(TEST_HOME)_skel/.gnupg
    1.24 +
    1.25 +ifeq ($(shell uname), Darwin)
    1.26 +    LIBPATH = DYLD_LIBRARY_PATH
    1.27 +else
    1.28 +    LIBPATH = LD_LIBRARY_PATH
    1.29 +endif
    1.30 +
    1.31 +TEST_CMD_PFX = $(LIBPATH)=$(HOME)/lib:../src HOME=$(TEST_HOME)
    1.32 +
    1.33 +test_home_skel:
    1.34 +	mkdir -p test_home_skel
    1.35 +	-cat 0x*.asc *_sec.asc | gpg2 --import --homedir $(TEST_GNUPGHOME_SKEL)
    1.36 +	$(TEST_CMD_CLEAN)
    1.37 +
    1.38 +test_home_: test_home_skel
    1.39 +	rm -rf test_home
    1.40 +	cp -a test_home_skel test_home
    1.41 +
    1.42  clean:
    1.43  	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
    1.44 -	rm -Rf *.dSYM .imported pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
    1.45 +	rm -Rf *.dSYM test_home test_home_skel pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
    1.46  
    1.47 -.imported:
    1.48 -	-cat 0x*.asc *_sec.asc | gpg2 --import
    1.49 -	touch .imported
    1.50 -
    1.51 -test: pEpEngineTest .imported
    1.52 -	LD_LIBRARY_PATH=~/lib:../src ./pEpEngineTest
    1.53 +test: pEpEngineTest test_home_
    1.54 +	$(TEST_CMD_PFX) ./pEpEngineTest
    1.55  
    1.56  %_test : %_test.o test_util.o
    1.57  	 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
    1.58  
    1.59 -%_run : %
    1.60 -	LD_LIBRARY_PATH=~/lib:../src ./$<
    1.61 +%_run : % test_home_
    1.62 +	$(TEST_CMD_PFX) ./$<
    1.63  
    1.64 +%_lldb : % test_home_
    1.65 +	$(TEST_CMD_PFX) lldb ./$<
    1.66  
    1.67 -%_lldb : %
    1.68 -	LD_LIBRARY_PATH=~/lib:../src lldb ./$<
    1.69 +%_valgrind : % test_home_
    1.70 +	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
    1.71  
    1.72 -%_valgrind : %
    1.73 -	LD_LIBRARY_PATH=~/lib:../src valgrind --leak-check=yes ./$<
    1.74 -
    1.75 -%_gdb : %
    1.76 -	LD_LIBRARY_PATH=~/lib:../src gdb ./$<
    1.77 +%_gdb : % test_home_
    1.78 +	$(TEST_CMD_PFX) gdb ./$<
    1.79  
    1.80  unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
    1.81