Skip to content

Commit

Permalink
Update Catch2 v2 to v3.
Browse files Browse the repository at this point in the history
  • Loading branch information
oo13 committed Jan 18, 2024
1 parent e2d9835 commit 81256c7
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 41 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,21 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: apt-get install catch2
run: sudo apt-get -y install catch2
- name: Checkout Catch2 v3
uses: actions/checkout@v4
with:
repository: catchorg/Catch2
ref: v3.4.0
path: Catch2

- name: Install Catch2 v3
run: |
mkdir Catch2/build
cd Catch2/build
cmake .. -DBUILD_TESTING=OFF
cmake --build . --target install
- name: test
run: |
Expand All @@ -37,16 +48,16 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Checkout Catch2 v2
uses: actions/checkout@v3
- name: Checkout Catch2 v3
uses: actions/checkout@v4
with:
repository: catchorg/Catch2
ref: v2.13.10
ref: v3.4.0
path: Catch2

- name: Install Catch2
- name: Install Catch2 v3
run: |
mkdir Catch2/build
cd Catch2/build
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Use doxygen. I tested the generation in doxygen 1.9.4.
# Unit Test
This library includes some unit test codes. If you want to run it, the following programs are needed:
- Catch2 (Tested in version 2.13.10)
- cmake (Tested in Version 3.24.3) or meson (Tested in Version 1.0.1)
- Catch2 v3 (Tested in version 3.4.0)
- cmake (Tested in Version 3.28.1) or meson (Tested in Version 1.2.3)
cmake:
```
Expand All @@ -88,3 +88,5 @@ meson:
% meson test ; # or ninja test
% meson test --benchmark ; # or ninja benchmark
```
Note that Catch2 v3 requires C++14, but the library can be compiled by C++11.
10 changes: 7 additions & 3 deletions copyright
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Comment: Inspired by spirit_po (https://github.com/cbeck88/spirit-po), but nothi
Comment: The plural expression table in PluralParse.h is derived from lib/plurals.js in "https://github.com/alexanderwallin/node-gettext". It's published by a sort of MIT License but we have no need to show the copyright notice and the permission notice because the second sentence is removed.

Files: test/*.cpp
Copyright: © 2022 OOTA, Masato
Copyright: © 2022, 2024 OOTA, Masato
© 2013 Translate.
License: CC-BY-SA-3.0
Comment: A data table is derived from https://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html?id=l10n/pluralforms
Expand All @@ -19,12 +19,16 @@ Files: sample/load.cpp
Copyright: © 2019 OOTA, Masato
License: CC0-1.0

Files: spiritless_po.doxygen test/CMakeLists.txt test/main.cpp sample/dump.cpp
Files: spiritless_po.doxygen sample/dump.cpp
Copyright: © 2022 OOTA, Masato
License: CC0-1.0

Files: test/meson.build
Copyright: © 2023 OOTA, Masato
Copyright: © 2023, 2024 OOTA, Masato
License: CC0-1.0

Files: test/CMakeLists.txt
Copyright: © 2022, 2024 OOTA, Masato
License: CC0-1.0


Expand Down
8 changes: 4 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Build settings for Unit Test of spiritless_po.
# Copyright © 2022 OOTA, Masato
# Copyright © 2022, 2024 OOTA, Masato
# This is published under CC0 1.0.
# For more information, see CC0 1.0 Universal (CC0 1.0) at <https://creativecommons.org/publicdomain/zero/1.0/legalcode>.
cmake_minimum_required(VERSION 3.5)

project(test_spiritless_po CXX)

find_package(Catch2 REQUIRED)
add_executable(test_spiritless_po main.cpp Catalog.cpp MetadataParser.cpp PluralParser.cpp PoParser.cpp)
target_link_libraries(test_spiritless_po Catch2::Catch2)
add_executable(test_spiritless_po Catalog.cpp MetadataParser.cpp PluralParser.cpp PoParser.cpp)
target_link_libraries(test_spiritless_po Catch2::Catch2WithMain)
target_include_directories(test_spiritless_po PRIVATE ../include)
target_compile_features(test_spiritless_po PRIVATE cxx_std_11)
target_compile_definitions(test_spiritless_po PRIVATE CATCH_CONFIG_ENABLE_BENCHMARKING)
target_compile_definitions(test_spiritless_po PRIVATE ENABLE_BENCHMARK)
if (MSVC)
set(CMAKE_CXX_FLAGS "/permissive- /EHsc /W4 /O2")
else()
Expand Down
4 changes: 2 additions & 2 deletions test/Catalog.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
Copyright © 2022 OOTA, Masato
Copyright © 2022, 2024 OOTA, Masato
License: CC-BY-SA-3.0
See https://creativecommons.org/licenses/by-sa/3.0/legalcode for license details.
*/
#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <iostream>
#include <sstream>
#include <string>
Expand Down
4 changes: 2 additions & 2 deletions test/MetadataParser.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
Copyright © 2022 OOTA, Masato
Copyright © 2022, 2024 OOTA, Masato
License: CC-BY-SA-3.0
See https://creativecommons.org/licenses/by-sa/3.0/legalcode for license details.
*/
#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <string>

#include "spiritless_po/MetadataParser.h"
Expand Down
13 changes: 11 additions & 2 deletions test/PluralParser.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/*
Copyright © 2022 OOTA, Masato
Copyright © 2022, 2024 OOTA, Masato
© 2013 Translate.
License: CC-BY-SA-3.0
See https://creativecommons.org/licenses/by-sa/3.0/legalcode for license details.
*/
#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/benchmark/catch_benchmark.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/generators/catch_generators_range.hpp>
#include <random>
#include <string>
#include <vector>
Expand Down Expand Up @@ -213,6 +217,7 @@ namespace {
};


#ifdef ENABLE_BENCHMARK
// This function returns a random integer vector.
vector<unsigned long int> gen_int_vector(const size_t s)
{
Expand All @@ -224,6 +229,7 @@ namespace {
}
return v;
}
#endif // ENABLE_BENCHMARK
}

TEMPLATE_TEST_CASE( "Default Constructor of PluralFunction", "[PluralFunction]", PluralParser, ENABLE_ASSERT::PluralParser, INTERPRETER::PluralParser ) {
Expand Down Expand Up @@ -355,6 +361,8 @@ TEMPLATE_TEST_CASE( "Equality in PluralFunction", "[PluralFunction]", PluralPar



// For some reason, "g++ -D_GLIBCXX_DEBUG" causes some errors in BENCHMARK()...
#ifdef ENABLE_BENCHMARK
TEST_CASE( "Plural Function Benchmark", "[!benchmark]" ) {
const auto numbers = gen_int_vector(10000);
vector<PluralParser::FunctionType> test_funcs;
Expand Down Expand Up @@ -518,3 +526,4 @@ TEST_CASE( "Plural Function Benchmark", "[!benchmark]" ) {
}
};
}
#endif // ENABLE_BENCHMARK
4 changes: 2 additions & 2 deletions test/PoParser.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
Copyright © 2022 OOTA, Masato
Copyright © 2022, 2024 OOTA, Masato
License: CC-BY-SA-3.0
See https://creativecommons.org/licenses/by-sa/3.0/legalcode for license details.
*/
#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <iostream>
#include <string>

Expand Down
9 changes: 0 additions & 9 deletions test/main.cpp

This file was deleted.

12 changes: 5 additions & 7 deletions test/meson.build
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
# Build settings for Unit Test of prec_ctrl.
# Copyright © 2023 OOTA, Masato
# Copyright © 2023, 2024 OOTA, Masato
# This is published under CC0 1.0.
# For more information, see CC0 1.0 Universal (CC0 1.0) at <https://creativecommons.org/publicdomain/zero/1.0/legalcode>.

project('test_spiritless_po', 'cpp',
default_options: [
'cpp_std=c++11',
'cpp_std=c++14', # Catch v3 requires C++14.
'buildtype=debugoptimized',
'warning_level=3',
'b_sanitize=undefined',
'cpp_debugstl=true',
],
license: 'Boost',
# license_files: ['../LICENSE'],
license_files: ['../LICENSE'],
)

srcs = [
'main.cpp',
'Catalog.cpp',
'MetadataParser.cpp',
'PluralParser.cpp',
'PoParser.cpp',
]
incdirs = ['../include']
deps = [dependency('catch2')]

add_project_arguments('-DCATCH_CONFIG_ENABLE_BENCHMARKING', language: 'cpp')
deps = [dependency('catch2-with-main')]

exe_test = executable(
'test_spiritless_po',
Expand All @@ -42,6 +39,7 @@ exe_bench = executable(
'b_sanitize=none',
'cpp_debugstl=false'
],
cpp_args : '-DENABLE_BENCHMARK',
)
test('Unit Test', exe_test, timeout: 60)
benchmark('Bench', exe_bench, args: ['[!benchmark]'])

0 comments on commit 81256c7

Please sign in to comment.