From 5264cf006696fab714c3975f8d721ae1f82c9307 Mon Sep 17 00:00:00 2001 From: Zoltan Fridrich Date: Fri, 16 Jul 2021 10:46:24 +0200 Subject: [PATCH] Add tests Related: rhbz#1980993 --- catch1.spec | 5 +++-- tests/.fmf/version | 1 + tests/devel-usability/factorial.cpp | 14 ++++++++++++++ tests/devel-usability/runtest.sh | 22 ++++++++++++++++++++++ tests/provision.fmf | 4 ++++ tests/tests.yml | 13 +++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 tests/.fmf/version create mode 100644 tests/devel-usability/factorial.cpp create mode 100755 tests/devel-usability/runtest.sh create mode 100644 tests/provision.fmf create mode 100644 tests/tests.yml diff --git a/catch1.spec b/catch1.spec index 306659f..3f90782 100644 --- a/catch1.spec +++ b/catch1.spec @@ -2,7 +2,7 @@ Name: catch1 Version: 1.12.2 -Release: 9%{?dist} +Release: 10%{?dist} Summary: A modern, C++-native, header-only, framework for unit-tests, TDD and BDD License: Boost @@ -57,7 +57,8 @@ cp -pr include %{buildroot}%{_includedir}/catch %changelog -* Thu Jul 15 2021 Zoltan Fridrich - 1.12.2-9 +* Thu Jul 15 2021 Zoltan Fridrich - 1.12.2-10 +- Add tests - Fix compilation error due to dynamic stack sizes Resolves: rhbz#1980993 diff --git a/tests/.fmf/version b/tests/.fmf/version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/tests/devel-usability/factorial.cpp b/tests/devel-usability/factorial.cpp new file mode 100644 index 0000000..a5d1082 --- /dev/null +++ b/tests/devel-usability/factorial.cpp @@ -0,0 +1,14 @@ +#define CATCH_CONFIG_MAIN +#include + +unsigned int Factorial(unsigned int number) { + return number <= 1 ? number : Factorial(number - 1) * number; +} + +TEST_CASE("Factorials are computed", "[factorial]") { + REQUIRE(Factorial(1) == 1); + REQUIRE(Factorial(2) == 2); + REQUIRE(Factorial(3) == 6); + REQUIRE(Factorial(10) == 3628800); +} + diff --git a/tests/devel-usability/runtest.sh b/tests/devel-usability/runtest.sh new file mode 100755 index 0000000..abd8ca7 --- /dev/null +++ b/tests/devel-usability/runtest.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e +set -x + +TEST_SOURCE=factorial.cpp +TEST_TARGET="${TEST_SOURCE/\.cpp/}" + +CXXFLAGS="$(rpm --eval '%{build_cxxflags}')" +LDFLAGS="$(rpm --eval '%{build_ldflags}')" +LIBFLAGS="" + +# build target using distribution-specific flags +g++ -std=c++11 $CXXFLAGS $LDFLAGS $LIBFLAGS -o $TEST_TARGET $TEST_SOURCE + +# test that target exists +test -f ./$TEST_TARGET + +# test that target is executable +test -x ./$TEST_TARGET + +# test that target runs successfully +./$TEST_TARGET diff --git a/tests/provision.fmf b/tests/provision.fmf new file mode 100644 index 0000000..c4bef80 --- /dev/null +++ b/tests/provision.fmf @@ -0,0 +1,4 @@ +--- +standard-inventory-qcow2: + qemu: + m: 4G diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..57267f4 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,13 @@ +--- +- hosts: localhost + tags: + - classic + roles: + - role: standard-test-basic + tests: + - devel-usability + required_packages: + - gcc-c++ + - rpm + - redhat-rpm-config + - catch1-devel