Skip to content

Commit

Permalink
Revert back to Catch2 v2
Browse files Browse the repository at this point in the history
Catch v3 doesn't support MSVC 2015
  • Loading branch information
rikyoz committed Jan 16, 2024
1 parent ba2e6f4 commit a5e5b87
Show file tree
Hide file tree
Showing 27 changed files with 66 additions and 98 deletions.
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ endif()

# Catch2
CPMAddPackage( NAME Catch2
VERSION 3.5.1
VERSION 2.13.10
OPTIONS "CATCH_CONFIG_CONSOLE_WIDTH 512" "CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS ON"
GITHUB_REPOSITORY "catchorg/Catch2" )
list( APPEND CMAKE_MODULE_PATH "${Catch2_SOURCE_DIR}/extras" )
list( APPEND CMAKE_MODULE_PATH "${Catch2_SOURCE_DIR}/contrib" )

include( CTest )
include( Catch )
Expand Down
2 changes: 1 addition & 1 deletion tests/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define CATCH_CONFIG_RUNNER

#include <catch2/catch_session.hpp> // IMPORTANT: it must be included before any other includes.
#include <catch2/catch.hpp> // IMPORTANT: it must be included before any other includes.

#include <iostream>

Expand Down
6 changes: 2 additions & 4 deletions tests/src/test_bit7zlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_predicate.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
#include <catch2/catch.hpp>

#include "utils/shared_lib.hpp"

Expand Down Expand Up @@ -46,7 +44,7 @@ TEST_CASE( "Bit7zLibrary: Constructing from a non-existing shared library", "[bi

TEST_CASE( "Bit7zLibrary: Normal construction", "[bit7zlibrary]" ) {
const auto libPath = sevenzip_lib_path();
INFO( "Library path: " << fs::path{ libPath }.string() );
INFO( "Library path: " << fs::path{ libPath }.string() )

REQUIRE_NOTHROW( Bit7zLibrary{ libPath } );
}
Expand Down
4 changes: 1 addition & 3 deletions tests/src/test_bitabstractarchivecreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/catch.hpp>

#include "utils/shared_lib.hpp"

Expand Down
2 changes: 1 addition & 1 deletion tests/src/test_bitarchiveeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch.hpp>

#include "utils/shared_lib.hpp"

Expand Down
4 changes: 1 addition & 3 deletions tests/src/test_bitarchiveiteminfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/catch.hpp>

#include "utils/archive.hpp"
#include "utils/filesystem.hpp"
Expand Down
18 changes: 8 additions & 10 deletions tests/src/test_bitarchivereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/catch.hpp>

#include "utils/archive.hpp"
#include "utils/filesystem.hpp"
Expand Down Expand Up @@ -58,8 +56,8 @@ void require_archive_item( const BitInFormat& format,
const BitArchiveItem& item,
const ExpectedItem& expectedItem,
const SourceLocation& location ) {
INFO( "Failed while checking archive item " << Catch::StringMaker< tstring >::convert( item.name() ) );
INFO( " from " << location.file_name() << ":" << location.line() );
INFO( "Failed while checking archive item " << Catch::StringMaker< tstring >::convert( item.name() ) )
INFO( " from " << location.file_name() << ":" << location.line() )
REQUIRE( item.isDir() == ( expectedItem.fileInfo.type == fs::file_type::directory ) );

if ( !item.isDir() ) {
Expand Down Expand Up @@ -94,8 +92,8 @@ void require_archive_item( const BitInFormat& format,
inline void require_archive_content( const BitArchiveReader& info,
const TestInputArchive& input,
const SourceLocation& location ) {
INFO( "Failed while checking content of " << Catch::StringMaker< tstring >::convert( info.archivePath() ) );
INFO( " from " << location.file_name() << ":" << location.line() );
INFO( "Failed while checking content of " << Catch::StringMaker< tstring >::convert( info.archivePath() ) )
INFO( " from " << location.file_name() << ":" << location.line() )
REQUIRE_FALSE( info.archiveProperties().empty() );

const auto& archive_content = input.content();
Expand Down Expand Up @@ -364,7 +362,7 @@ TEST_CASE( "BitArchiveReader: Reading metadata of multi-volume archives", "[bita
DYNAMIC_SECTION( "Archive format: " << testArchive.extension() ) {
const fs::path arcFileName = "clouds.jpg." + testArchive.extension() + ".001";

INFO( "Archive file: " << arcFileName );
INFO( "Archive file: " << arcFileName )

SECTION( "Opening as a split archive" ) {
const BitArchiveReader info( test::sevenzip_lib(), arcFileName.string< tchar >(), BitFormat::Split );
Expand Down Expand Up @@ -522,8 +520,8 @@ void require_item_type( const BitArchiveReader& info,
fs::file_type fileType,
std::uint32_t winAttributes,
SourceLocation location ) {
INFO( "Failed checking required item " << Catch::StringMaker< tstring >::convert( itemName ) );
INFO( " from " << location.file_name() << ":" << location.line() );
INFO( "Failed checking required item " << Catch::StringMaker< tstring >::convert( itemName ) )
INFO( " from " << location.file_name() << ":" << location.line() )
auto iterator = info.find( itemName );
REQUIRE( iterator != info.cend() );
REQUIRE( iterator->name() == itemName );
Expand Down
3 changes: 1 addition & 2 deletions tests/src/test_biterror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/catch.hpp>

#include <bit7z/biterror.hpp>

Expand Down
3 changes: 1 addition & 2 deletions tests/src/test_bitexception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/catch.hpp>

#include <bit7z/bitexception.hpp>
#include <bit7z/bitwindows.hpp>
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test_bitfilecompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch.hpp>

#include "utils/shared_lib.hpp"

Expand Down
2 changes: 1 addition & 1 deletion tests/src/test_bitfileextractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch.hpp>

#include "utils/shared_lib.hpp"

Expand Down
68 changes: 29 additions & 39 deletions tests/src/test_bitinputarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/matchers/catch_matchers_predicate.hpp>
#include <catch2/matchers/catch_matchers_quantifiers.hpp>
#include <catch2/matchers/catch_matchers_vector.hpp>
#include <catch2/catch.hpp>

#include "utils/archive.hpp"
#include "utils/crc.hpp"
Expand Down Expand Up @@ -55,8 +50,8 @@ inline auto archive_item( const BitArchiveReader& archive,
}

void require_filesystem_item( const ExpectedItem& expectedItem, const SourceLocation& location ) {
INFO( "From " << location.file_name() << ":" << location.line() );
INFO( "Failed while checking expected item: " << expectedItem.inArchivePath.u8string() );
INFO( "From " << location.file_name() << ":" << location.line() )
INFO( "Failed while checking expected item: " << expectedItem.inArchivePath.u8string() )

// Note: there's no need to check the file with fs::exists
// since the file's type check already includes the check for the file existence.
Expand All @@ -80,7 +75,7 @@ void require_filesystem_item( const ExpectedItem& expectedItem, const SourceLoca

void require_extracts_to_filesystem( const BitArchiveReader& info, const ExpectedItems& expectedItems ) {
TempTestDirectory testDir{ "test_bitinputarchive" };
INFO( "Test directory: " << testDir );
INFO( "Test directory: " << testDir )

REQUIRE_NOTHROW( info.extractTo( testDir ) );
if ( expectedItems.empty() ) {
Expand All @@ -94,7 +89,7 @@ void require_extracts_to_filesystem( const BitArchiveReader& info, const Expecte

void require_extracts_items_to_filesystem( const BitArchiveReader& info, const ExpectedItems& expectedItems ) {
TempTestDirectory testDir{ "test_bitinputarchive" };
INFO( "Test directory: " << testDir );
INFO( "Test directory: " << testDir )

for ( const auto& expectedItem : expectedItems ) {
const auto archiveItem = archive_item( info, expectedItem );
Expand Down Expand Up @@ -150,7 +145,7 @@ void require_extracts_to_buffers_map( const BitArchiveReader& info, const Expect
REQUIRE_NOTHROW( info.extractTo( bufferMap ) );
REQUIRE( bufferMap.size() == info.filesCount() );
for ( const auto& expectedItem : expectedItems ) {
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" );
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" )
const auto& extractedItem = bufferMap.find( path_to_tstring( expectedItem.inArchivePath ) );
if ( expectedItem.fileInfo.type != fs::file_type::directory ) {
REQUIRE( extractedItem != bufferMap.end() );
Expand All @@ -164,7 +159,7 @@ void require_extracts_to_buffers_map( const BitArchiveReader& info, const Expect
void require_extracts_to_buffers( const BitArchiveReader& info, const ExpectedItems& expectedItems ) {
buffer_t outputBuffer;
for ( const auto& expectedItem : expectedItems ) {
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" );
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" )
const auto archiveItem = archive_item( info, expectedItem );
REQUIRE( archiveItem != info.cend() );
if ( archiveItem->isDir() ) {
Expand Down Expand Up @@ -194,7 +189,7 @@ void require_extracts_to_fixed_buffers( const BitArchiveReader& info, const Expe
buffer_t invalidBuffer( invalidBufferSize, static_cast< byte_t >( '\0' ) );
buffer_t outputBuffer;
for ( const auto& expectedItem : expectedItems ) {
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" );
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" )
const auto archiveItem = archive_item( info, expectedItem );
REQUIRE( archiveItem != info.cend() );

Expand Down Expand Up @@ -257,7 +252,7 @@ void require_extracts_to_fixed_buffers( const BitArchiveReader& info, const Expe

void require_extracts_to_streams( const BitArchiveReader& info, const ExpectedItems& expectedItems ) {
for ( const auto& expectedItem : expectedItems ) {
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" );
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" )

const auto archiveItem = archive_item( info, expectedItem );
REQUIRE( archiveItem != info.cend() );
Expand Down Expand Up @@ -294,8 +289,8 @@ void require_archive_extracts( const BitArchiveReader& info,
}
#endif

INFO( "From " << location.file_name() << ":" << location.line() );
INFO( "Failed while extracting the archive" );
INFO( "From " << location.file_name() << ":" << location.line() )
INFO( "Failed while extracting the archive" )

SECTION( "Extracting to a temporary filesystem folder" ) {
require_extracts_to_filesystem( info, expectedItems );
Expand Down Expand Up @@ -333,12 +328,12 @@ void require_archive_extract_fails( const BitArchiveReader& info, const SourceLo
}
#endif

INFO( "From " << location.file_name() << ":" << location.line() );
INFO( "Failed while extracting the archive" );
INFO( "From " << location.file_name() << ":" << location.line() )
INFO( "Failed while extracting the archive" )

SECTION( "Extracting to a temporary filesystem folder should fail" ) {
TempTestDirectory testDir{ "test_bitinputarchive" };
INFO( "Test directory: " << testDir );
INFO( "Test directory: " << testDir )
REQUIRE_THROWS( info.extractTo( testDir ) );
// TODO: Make some guarantees on what remains after a failed extraction
for ( const auto& item : fs::directory_iterator( testDir.path() ) ) {
Expand All @@ -363,8 +358,8 @@ void require_archive_extract_fails( const BitArchiveReader& info, const SourceLo
require_archive_extract_fails( info, BIT7Z_CURRENT_LOCATION )

void require_archive_tests( const BitArchiveReader& info, const SourceLocation& location ) {
INFO( "From " << location.file_name() << ":" << location.line() );
INFO( "Failed while testing the archive" );
INFO( "From " << location.file_name() << ":" << location.line() )
INFO( "Failed while testing the archive" )
#ifdef BIT7Z_BUILD_FOR_P7ZIP
const auto& detectedFormat = (info).detectedFormat();
if ( detectedFormat == BitFormat::Rar || detectedFormat == BitFormat::Rar5 ) {
Expand Down Expand Up @@ -575,7 +570,7 @@ TEST_CASE( "BitInputArchive: Testing and extracting multi-volume archives", "[bi
const auto wholeArcFileName = std::string{ "clouds.jpg." } + testFormat.extension;
const fs::path splitArcFileName = wholeArcFileName + ".001";

INFO( "Archive file: " << splitArcFileName );
INFO( "Archive file: " << splitArcFileName )

SECTION( "Opening as a split archive" ) {
const BitArchiveReader info( test::sevenzip_lib(),
Expand Down Expand Up @@ -960,7 +955,7 @@ TEMPLATE_TEST_CASE( "BitInputArchive: Extracting an archive using various Overwr
BitArchiveReader info( test::sevenzip_lib(), inputArchive, testFormat.format );

TempTestDirectory testOutDir{ "test_bitinputarchive" };
INFO( "Output directory: " << testOutDir );
INFO( "Output directory: " << testOutDir )

const auto expectedFile = overwritten_file_path< TestType >( testFormat.format );
REQUIRE_FALSE( fs::exists( expectedFile ) );
Expand Down Expand Up @@ -1067,7 +1062,7 @@ TEMPLATE_TEST_CASE( "BitInputArchive: Extracting an archive to the filesystem sh
#endif

TempTestDirectory testOutDir{ "test_bitinputarchive" };
INFO( "Output directory: " << testOutDir );
INFO( "Output directory: " << testOutDir )

REQUIRE_NOTHROW( info.extractTo( testOutDir ) );

Expand Down Expand Up @@ -1133,7 +1128,7 @@ TEMPLATE_TEST_CASE( "BitInputArchive: Extracting an archive not having time meta
REQUIRE( expectedModifiedTime.dwHighDateTime != 0 );

TempTestDirectory testOutDir{ "test_bitinputarchive" };
INFO( "Output directory: " << testOutDir );
INFO( "Output directory: " << testOutDir )

REQUIRE_NOTHROW( info.extractTo( testOutDir ) );

Expand All @@ -1160,7 +1155,7 @@ TEMPLATE_TEST_CASE( "BitInputArchive: Extracting a file with a comment should pr
BitArchiveReader info( test::sevenzip_lib(), inputArchive, BitFormat::SevenZip );

TempTestDirectory testOutDir{ "test_bitinputarchive" };
INFO( "Output directory: " << testOutDir );
INFO( "Output directory: " << testOutDir )

REQUIRE_NOTHROW( info.extractTo( testOutDir ) );

Expand Down Expand Up @@ -1233,7 +1228,7 @@ TEMPLATE_TEST_CASE( "BitInputArchive: Using extraction callbacks", "[bitinputarc

SECTION( "When extracting to the filesystem" ) {
TempTestDirectory testOutDir{ "test_bitinputarchive" };
INFO( "Output directory: " << testOutDir );
INFO( "Output directory: " << testOutDir )
require_extracts_to_filesystem( info, expectedItems );
}

Expand All @@ -1260,19 +1255,14 @@ TEMPLATE_TEST_CASE( "BitInputArchive: Using extraction callbacks", "[bitinputarc
// For some reason, the Tar format makes the progress decrease in some cases,
// and it is not always less than the total size ¯\_(ツ)_/¯.
if ( testArchive.format != BitFormat::Tar ) {
// Checking that the values reported by the progress callback are increasing.
// Checking that the values reported by the progress callback are increasing,
// and less than or equal to the total size.
uint64_t lastProgress = 0;
REQUIRE_THAT( progressValues,
AllMatch( Predicate< uint64_t >( [ &lastProgress ]( uint64_t progress ) -> bool {
const bool result = progress >= lastProgress;
lastProgress = progress;
return result;
} ) ) );

// Checking that all the values reported by the progress callback ar less than or equal to the total size.
REQUIRE_THAT( progressValues, AllMatch( Predicate< uint64_t >( [ &totalSize ]( uint64_t progress ) -> bool {
return progress <= totalSize;
} ) ) );
for ( uint64_t progress : progressValues ) {
REQUIRE( progress >= lastProgress );
REQUIRE( progress <= totalSize );
lastProgress = progress;
}

// TODO: Fix 7-Zip not calling the progress callback on last extracted block in these formats
if ( testArchive.format != BitFormat::Iso && testArchive.format != BitFormat::Rar5 ) {
Expand Down
4 changes: 1 addition & 3 deletions tests/src/test_bititemsvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/matchers/catch_matchers_vector.hpp>
#include <catch2/catch.hpp>

#include "utils/filesystem.hpp"

Expand Down
2 changes: 1 addition & 1 deletion tests/src/test_bitmemcompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch.hpp>

#include "utils/shared_lib.hpp"

Expand Down
2 changes: 1 addition & 1 deletion tests/src/test_bitmemextractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch.hpp>

#include "utils/shared_lib.hpp"

Expand Down
Loading

0 comments on commit a5e5b87

Please sign in to comment.