summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt2
-rw-r--r--test/Makefile16
-rw-r--r--test/integration/framework37
-rw-r--r--test/integration/makefile10
-rwxr-xr-xtest/integration/run-tests6
-rwxr-xr-xtest/integration/test-apt-helper-cat-file2
-rw-r--r--test/interactive-helper/CMakeLists.txt10
-rw-r--r--test/interactive-helper/makefile53
-rw-r--r--test/libapt/CMakeLists.txt22
-rw-r--r--test/libapt/fileutl_test.cc2
-rw-r--r--test/libapt/hashsums_test.cc14
-rw-r--r--test/libapt/makefile84
12 files changed, 78 insertions, 180 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 000000000..2f47b5c32
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(libapt)
+add_subdirectory(interactive-helper)
diff --git a/test/Makefile b/test/Makefile
deleted file mode 100644
index 35a0a51e3..000000000
--- a/test/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-# -*- make -*-
-
-# This is the top level test makefile for APT, it recurses to each lower
-# level make file and runs it with the proper target
-ifndef NOISY
-.SILENT:
-endif
-
-.PHONY: startup headers library clean veryclean all binary program doc test update-po
-startup all clean veryclean binary program dirs test update-po manpages docbook:
- $(MAKE) -C libapt $@
- $(MAKE) -C interactive-helper $@
-
-# Some very common aliases
-.PHONY: maintainer-clean dist-clean distclean pristine sanity
-maintainer-clean dist-clean distclean pristine sanity: veryclean
diff --git a/test/integration/framework b/test/integration/framework
index 7a6b044aa..0f442dff4 100644
--- a/test/integration/framework
+++ b/test/integration/framework
@@ -180,7 +180,7 @@ aptconfig() { runapt apt-config "$@"; }
aptcache() { runapt apt-cache "$@"; }
aptcdrom() { runapt apt-cdrom "$@"; }
aptget() { runapt apt-get "$@"; }
-aptftparchive() { runapt apt-ftparchive "$@"; }
+aptftparchive() { runapt "${APTFTPARCHIVEBINDIR}/apt-ftparchive" "$@"; }
aptkey() { runapt apt-key "$@"; }
aptmark() { runapt apt-mark "$@"; }
aptsortpkgs() { runapt apt-sortpkgs "$@"; }
@@ -257,6 +257,24 @@ escape_shell() {
echo "$@" | sed -e "s#'#'\"'\"'#g"
}
+find_project_binary_dir() {
+ local TESTDIRECTORY="$(readlink -f "$(dirname $0)")"
+ if [ -z "$PROJECT_BINARY_DIR" ]; then
+ PROJECT_BINARY_DIR=
+ for dir in ${TESTDIRECTORY}/../../ ${TESTDIRECTORY}/../../*; do
+ test -e "$dir/CMakeCache.txt" || continue
+ if [ -z "$PROJECT_BINARY_DIR" ] ||
+ [ "$dir/CMakeCache.txt" -nt "$PROJECT_BINARY_DIR/CMakeCache.txt" ]; then
+ PROJECT_BINARY_DIR="$dir"
+ fi
+ done
+ if [ -z "$PROJECT_BINARY_DIR" ]; then
+ echo "Cannot find build directory, you might want to set PROJECT_BINARY_DIR" >&2
+ exit 1
+ fi
+ export PROJECT_BINARY_DIR
+ fi
+}
setupenvironment() {
# privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
@@ -281,16 +299,19 @@ setupenvironment() {
fi
TESTDIRECTORY="$(readlink -f "$(dirname $0)")"
+ # Find the newest build directory (sets PROJECT_BINARY_DIR)
+ find_project_binary_dir
# allow overriding the default BUILDDIR location
SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
- BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
- LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
- METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
+ BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${PROJECT_BINARY_DIR}/cmdline"}"
+ LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}/../apt-pkg"}"
+ METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/../methods"}"
APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
- APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
- APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
- APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
- APTINTERNALPLANNER="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/apt-internal-planner"}"
+ APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}/../test/interactive-helper"}"
+ APTFTPARCHIVEBINDIR="${APT_INTEGRATION_TESTS_FTPARCHIVE_BIN_DIR:-"${BUILDDIRECTORY}/../ftparchive"}"
+ APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/solvers/apt"}"
+ APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/solvers/dump"}"
+ APTINTERNALPLANNER="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/planners/apt"}"
test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
# -----
diff --git a/test/integration/makefile b/test/integration/makefile
deleted file mode 100644
index fb12fe9a8..000000000
--- a/test/integration/makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-# -*- make -*-
-BASE=../..
-SUBDIR=test/integration
-
-# Bring in the default rules
-include ../../buildlib/defaults.mak
-
-.PHONY: test
-test:
- ./run-tests
diff --git a/test/integration/run-tests b/test/integration/run-tests
index 78f24fbaf..e90b4b755 100755
--- a/test/integration/run-tests
+++ b/test/integration/run-tests
@@ -1,4 +1,10 @@
#!/bin/sh
+
+TESTDIR="$(readlink -f "$(dirname "$0")")"
+. "$TESTDIR/framework"
+
+find_project_binary_dir
+
set -e
TESTTORUN=''
diff --git a/test/integration/test-apt-helper-cat-file b/test/integration/test-apt-helper-cat-file
index 3f509189e..a53a6b4a3 100755
--- a/test/integration/test-apt-helper-cat-file
+++ b/test/integration/test-apt-helper-cat-file
@@ -5,7 +5,7 @@ TESTDIR="$(readlink -f "$(dirname "$0")")"
. "$TESTDIR/framework"
setupenvironment
-TESTTOOL="${BUILDDIRECTORY}/test_fileutl"
+TESTTOOL="${BUILDDIRECTORY}/../test/interactive-helper/test_fileutl"
msgtest 'Check if we have build the test tool' "$TESTTOOL"
if [ -x "$TESTTOOL" ]; then
msgpass
diff --git a/test/interactive-helper/CMakeLists.txt b/test/interactive-helper/CMakeLists.txt
new file mode 100644
index 000000000..fc08d6a8f
--- /dev/null
+++ b/test/interactive-helper/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_executable(mthdcat mthdcat.cc)
+target_link_libraries(mthdcat apt-pkg)
+add_executable(testdeb testdeb.cc)
+target_link_libraries(testdeb apt-pkg apt-inst)
+add_executable(extract-control extract-control.cc)
+target_link_libraries(extract-control apt-pkg apt-inst)
+add_executable(aptwebserver aptwebserver.cc)
+target_link_libraries(aptwebserver apt-pkg ${CMAKE_THREAD_LIBS_INIT})
+add_executable(test_fileutl test_fileutl.cc)
+target_link_libraries(test_fileutl apt-pkg)
diff --git a/test/interactive-helper/makefile b/test/interactive-helper/makefile
deleted file mode 100644
index 096767c41..000000000
--- a/test/interactive-helper/makefile
+++ /dev/null
@@ -1,53 +0,0 @@
-# -*- make -*-
-BASE=../..
-SUBDIR=test/interactive-helper
-APT_DOMAIN=none
-
-# Bring in the default rules
-include ../../buildlib/defaults.mak
-
-# Program for testing methods
-PROGRAM=mthdcat
-SLIBS =
-SOURCE = mthdcat.cc
-include $(PROGRAM_H)
-
-# Program for testing the tar/deb extractor
-PROGRAM=testdeb
-SLIBS = -lapt-pkg -lapt-inst
-LIB_MAKES = apt-pkg/makefile apt-inst/makefile
-SOURCE = testdeb.cc
-include $(PROGRAM_H)
-
-# Program for testing tar extraction
-PROGRAM=extract-control
-SLIBS = -lapt-pkg -lapt-inst
-LIB_MAKES = apt-pkg/makefile apt-inst/makefile
-SOURCE = extract-control.cc
-include $(PROGRAM_H)
-
-# Program for testing udevcdrom
-PROGRAM=test_udevcdrom
-SLIBS = -lapt-pkg
-LIB_MAKES = apt-pkg/makefile
-SOURCE = test_udevcdrom.cc
-include $(PROGRAM_H)
-
-PROGRAM=test_fileutl
-SLIBS = -lapt-pkg
-LIB_MAKES = apt-pkg/makefile
-SOURCE = test_fileutl.cc
-include $(PROGRAM_H)
-
-# Program for checking rpm versions
-#PROGRAM=rpmver
-#SLIBS = -lapt-pkg -lrpm
-#SOURCE = rpmver.cc
-#include $(PROGRAM_H)
-
-# very simple webserver for APT testing
-PROGRAM=aptwebserver
-SLIBS = -lapt-pkg -lpthread
-LIB_MAKES = apt-pkg/makefile
-SOURCE = aptwebserver.cc
-include $(PROGRAM_H)
diff --git a/test/libapt/CMakeLists.txt b/test/libapt/CMakeLists.txt
new file mode 100644
index 000000000..7f9990526
--- /dev/null
+++ b/test/libapt/CMakeLists.txt
@@ -0,0 +1,22 @@
+include(ExternalProject)
+
+set(GTEST_ROOT "/usr/src/gtest" CACHE FILEPATH "Path to GTest CMake project")
+
+message(STATUS "Found GTest at ${GTEST_ROOT}")
+
+if (EXISTS ${GTEST_ROOT})
+
+ExternalProject_Add(gtest PREFIX ./gtest
+ SOURCE_DIR ${GTEST_ROOT}
+ INSTALL_COMMAND true)
+
+link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build)
+FILE(GLOB files gtest_runner.cc *-helpers.cc *_test.cc)
+add_executable(libapt_test ${files})
+target_link_libraries(libapt_test -lgtest ${CMAKE_THREAD_LIBS_INIT} apt-private apt-inst)
+add_dependencies(libapt_test gtest)
+add_test(NAME AptTests
+ COMMAND libapt_test
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+endif()
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index 0a299b51a..67bd850a1 100644
--- a/test/libapt/fileutl_test.cc
+++ b/test/libapt/fileutl_test.cc
@@ -216,7 +216,7 @@ TEST(FileUtlTest, Glob)
{
std::vector<std::string> files;
// normal match
- files = Glob("*akefile");
+ files = Glob("*MakeLists.txt");
EXPECT_EQ(1, files.size());
// not there
diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc
index 705c0297d..fb9a25643 100644
--- a/test/libapt/hashsums_test.cc
+++ b/test/libapt/hashsums_test.cc
@@ -119,7 +119,7 @@ static void getSummationString(char const * const type, std::string &sum)
FileFd fd;
ASSERT_TRUE(fd.Open(tempfile, FileFd::WriteOnly | FileFd::Empty, compress));
ASSERT_TRUE(fd.IsOpen());
- FileFd input(__FILE__, FileFd::ReadOnly);
+ FileFd input("/etc/os-release", FileFd::ReadOnly);
ASSERT_TRUE(input.IsOpen());
ASSERT_NE(0, input.FileSize());
ASSERT_TRUE(CopyFile(input, fd));
@@ -161,7 +161,7 @@ TEST(HashSumsTest, FileBased)
SHA512SumValue sha512(summation);
EXPECT_EQ(sha512.Value(), summation);
- FileFd fd(__FILE__, FileFd::ReadOnly);
+ FileFd fd("/etc/os-release", FileFd::ReadOnly);
EXPECT_TRUE(fd.IsOpen());
std::string FileSize;
strprintf(FileSize, "%llu", fd.FileSize());
@@ -243,18 +243,18 @@ TEST(HashSumsTest, FileBased)
fd.Close();
HashString sha2file("SHA512", sha512.Value());
- EXPECT_TRUE(sha2file.VerifyFile(__FILE__));
+ EXPECT_TRUE(sha2file.VerifyFile("/etc/os-release"));
HashString sha2wrong("SHA512", "00000000000");
- EXPECT_FALSE(sha2wrong.VerifyFile(__FILE__));
+ EXPECT_FALSE(sha2wrong.VerifyFile("/etc/os-release"));
EXPECT_EQ(sha2file, sha2file);
EXPECT_TRUE(sha2file == sha2file);
EXPECT_NE(sha2file, sha2wrong);
EXPECT_TRUE(sha2file != sha2wrong);
HashString sha2big("SHA256", sha256.Value());
- EXPECT_TRUE(sha2big.VerifyFile(__FILE__));
+ EXPECT_TRUE(sha2big.VerifyFile("/etc/os-release"));
HashString sha2small("sha256:" + sha256.Value());
- EXPECT_TRUE(sha2small.VerifyFile(__FILE__));
+ EXPECT_TRUE(sha2small.VerifyFile("/etc/os-release"));
EXPECT_EQ(sha2big, sha2small);
EXPECT_TRUE(sha2big == sha2small);
EXPECT_FALSE(sha2big != sha2small);
@@ -283,7 +283,7 @@ TEST(HashSumsTest, FileBased)
EXPECT_EQ(2, hashes.size());
EXPECT_FALSE(hashes.push_back(sha2wrong));
EXPECT_EQ(2, hashes.size());
- EXPECT_TRUE(hashes.VerifyFile(__FILE__));
+ EXPECT_TRUE(hashes.VerifyFile("/etc/os-release"));
EXPECT_EQ(similar, hashes);
EXPECT_TRUE(similar == hashes);
diff --git a/test/libapt/makefile b/test/libapt/makefile
deleted file mode 100644
index 5ff9cf68a..000000000
--- a/test/libapt/makefile
+++ /dev/null
@@ -1,84 +0,0 @@
-# -*- make -*-
-BASE=../..
-SUBDIR=test/libapt
-BASENAME=_libapt_test
-APT_DOMAIN=none
-
-# Bring in the default rules
-include ../../buildlib/defaults.mak
-
-.PHONY: test
-ifeq (file-okay,$(shell $(CC) -I $(BASE)/build/include -M gtest_runner.cc >/dev/null 2>&1 && echo 'file-okay'))
-test: $(BIN)/gtest$(BASENAME)
- MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=$(LIB) $(BIN)/gtest$(BASENAME)
-
-$(BIN)/gtest$(BASENAME): $(LIB)/gtest.a
-
-PROGRAM = gtest${BASENAME}
-SLIBS = -lapt-pkg -lapt-private -lapt-inst -pthread $(LIB)/gtest.a
-LIB_MAKES = apt-pkg/makefile apt-private/makefile apt-inst/makefile
-SOURCE = gtest_runner.cc $(wildcard *-helpers.cc *_test.cc)
-include $(PROGRAM_H)
-
-
-MKDIRS += $(OBJ) $(LIB)
-LOCAL=gtest
-SOURCE=gtest-all
-gtest-OBJS := $(addprefix $(OBJ)/,$(addsuffix .o,$(SOURCE)))
-
-# The rest of the file is based on the example found in
-# /usr/share/doc/libgtest-dev/examples/make/Makefile
-GTEST_DIR = /usr/src/gtest
-
-# Flags passed to the preprocessor.
-# Set Google Test's header directory as a system directory, such that
-# the compiler doesn't generate warnings in Google Test headers.
-#CPPFLAGS += -isystem $(GTEST_DIR)/include
-
-# Flags passed to the C++ compiler.
-CXXFLAGS += -pthread
-# disable some flags for gtest again
-CXXFLAGS+= -Wno-missing-declarations
-CXXFLAGS+= -Wno-missing-field-initializers
-CXXFLAGS+= -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Wno-suggest-attribute=noreturn
-CXXFLAGS+= -Wno-undef
-
-# All Google Test headers. Usually you shouldn't change this definition.
-GTEST_HEADERS = /usr/include/gtest/*.h \
- /usr/include/gtest/internal/*.h
-
-# House-keeping build targets.
-.PHONY: clean/gtest veryclean/gtest
-clean: clean/gtest
-clean/gtest:
- rm -f $(gtest-OBJS)
-veryclean: veryclean/gtest
-veryclean/gtest: clean/gtest
- rm -f $(LIB)/gtest.a
-
-# Usually you shouldn't tweak such internal variables, indicated by a
-# trailing _.
-GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
-
-# Builds gtest.a
-# For simplicity and to avoid depending on Google Test's
-# implementation details, the dependencies specified below are
-# conservative and not optimized. This is fine as Google Test
-# compiles fast and for ordinary users its source rarely changes.
-$(gtest-OBJS): $(GTEST_SRCS_)
- echo Compiling $@
- $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c -o $@ $(GTEST_DIR)/src/$(notdir $(basename $@)).cc
-
-$(LIB)/gtest.a: $(OBJ)/gtest-all.o
- echo Building static library $@
- -rm -f $@
- $(AR) $(ARFLAGS) $@ $^
-
-else
-test:
- @echo "APT uses Googles C++ testing framework for its unit tests"
- @echo "On Debian systems this is available in the 'libgtest-dev' package."
- @echo "Please install it before attempting to run the unit tests."
- $(CC) -I $(BASE)/build/include -M gtest_runner.cc
- exit 100
-endif