Skip to content

Commit

Permalink
Feature/unit tests (#64)
Browse files Browse the repository at this point in the history
- fixed unit tests on Windows. We will adapt them for other platforms as well.
  nntp and postprocessor tests do not pass. We will debug them later.
- separated the tests from the application itself
- using CMake to configure files for building tests. We will completely switch to CMake later.
- deleted obsolete Autotools generated files
- updated README
  • Loading branch information
dnzbk authored Nov 23, 2023
1 parent 85645ad commit 73e8c00
Show file tree
Hide file tree
Showing 57 changed files with 1,673 additions and 28,925 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/windows-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: windows tests

on:
push:
branches:
- feature/*
- develop
- main
workflow_call:
workflow_dispatch:

jobs:
test:
runs-on: [self-hosted, windows]

steps:

- name: Prepare environment
run: |
"C:\Program Files\CMake\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Checkout
uses: actions/checkout@v3

- name: Build
run: |
cmake --version
mkdir build
cd build
cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows-static
cmake --build . --config Release -j 2
- name: Test
run: |
cd build
ctest -C Release
- name: Upload test artifacts
uses: actions/upload-artifact@v3
if: failure()
with:
name: nzbget-windows-test-log
path: build/Testing/Temporary/LastTest.log
retention-days: 5
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@
# GNU Autotools
.deps/
config.h
config.h.in
config.h.in~
configure
configure~
config.log
config.status
Makefile
Makefile.in
aclocal.m4
posix/config.guess
posix/config.sub
posix/depcomp
posix/install-sh
posix/missing
stamp-h1
autom4te.cache/
.dirstamp
Expand Down Expand Up @@ -67,6 +77,7 @@ ipch/

# NZBGet specific
nzbget
build
code_revision.cpp
*.temp
*.pyc
Expand Down
62 changes: 62 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
cmake_minimum_required(VERSION 3.22)

project(
nzbget
VERSION "22.0"
DESCRIPTION "NZBGet is a binary downloader, which downloads files from Usenet"
LANGUAGES C CXX
)

option(ENABLE_TESTS "Enable tests" ON)

set(VERSION "22")
set(PACKAGE "nzbget")
add_compile_definitions(HAVE_CONFIG_H=1)

configure_file(
${CMAKE_SOURCE_DIR}/cmake_config.h.in
${CMAKE_BINARY_DIR}/config.h
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_EXTENSIONS OFF)
set(BUILD_SHARED_LIBS OFF)
set(OPENSSL_USE_STATIC_LIBS ON)
set(ZLIB_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")

find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Weverything")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /W4")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} winmm.lib /NODEFAULTLIB:msvcrt.lib;libcmt.lib;msvcrtd.lib")
endif()

include_directories(lib/regex)
include_directories(${CMAKE_BINARY_DIR})
add_subdirectory(lib)

if (NOT WIN32)
find_package(LibXml2 REQUIRED)
include_directories(${LIBXML2_INCLUDE_DIR})
execute_process(COMMAND chmod +x ${CMAKE_SOURCE_DIR}/code_revision.sh)
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/code_revision.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
execute_process(COMMAND mv ${CMAKE_SOURCE_DIR}/code_revision.cpp ${CMAKE_BINARY_DIR})
endif()

if(ENABLE_TESTS)
include(CTest)
add_subdirectory(tests)
endif()
31 changes: 0 additions & 31 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -250,37 +250,6 @@ AM_CPPFLAGS = \
-I$(srcdir)/lib/par2 \
-I$(srcdir)/lib/yencode

if WITH_TESTS
nzbget_SOURCES += \
lib/catch/catch.h \
tests/suite/TestMain.cpp \
tests/suite/TestMain.h \
tests/suite/TestUtil.cpp \
tests/suite/TestUtil.h \
tests/main/CommandLineParserTest.cpp \
tests/main/OptionsTest.cpp \
tests/feed/FeedFilterTest.cpp \
tests/postprocess/DupeMatcherTest.cpp \
tests/postprocess/RarRenamerTest.cpp \
tests/postprocess/RarReaderTest.cpp \
tests/postprocess/DirectUnpackTest.cpp \
tests/queue/NzbFileTest.cpp \
tests/nntp/ServerPoolTest.cpp \
tests/util/FileSystemTest.cpp \
tests/util/NStringTest.cpp \
tests/util/UtilTest.cpp

if WITH_PAR2
nzbget_SOURCES += \
tests/postprocess/ParCheckerTest.cpp \
tests/postprocess/ParRenamerTest.cpp
endif

AM_CPPFLAGS += \
-I$(srcdir)/lib/catch \
-I$(srcdir)/tests/suite
endif

EXTRA_DIST = \
$(windows_FILES) \
$(osx_FILES) \
Expand Down
Loading

0 comments on commit 73e8c00

Please sign in to comment.