mirror of https://github.com/procxx/kepka.git
				
				
				
			Enable tests
This commit is contained in:
		
							parent
							
								
									a1e200c273
								
							
						
					
					
						commit
						badbf7a900
					
				| 
						 | 
				
			
			@ -3,6 +3,7 @@ project(telegram-desktop)
 | 
			
		|||
 | 
			
		||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cotire/CMake;${PROJECT_SOURCE_DIR}/modules/")
 | 
			
		||||
include(cotire)
 | 
			
		||||
include(CTest)
 | 
			
		||||
 | 
			
		||||
if (CMAKE_VERSION VERSION_GREATER 3.9)
 | 
			
		||||
    cmake_policy(SET CMP0071 NEW)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -700,3 +700,13 @@ cotire(Telegram)
 | 
			
		|||
# See https://github.com/sakra/cotire/blob/master/MANUAL.md#objective-c
 | 
			
		||||
# ObjC and ObjC++ files cannot be cotired, so they have to include appropriate Qt and Tg
 | 
			
		||||
# headers themselves, this applies to macOS platform sources.
 | 
			
		||||
 | 
			
		||||
##================================================
 | 
			
		||||
## Tests
 | 
			
		||||
##================================================
 | 
			
		||||
 | 
			
		||||
if (BUILD_TESTING)
 | 
			
		||||
    include_directories(ThirdParty/Catch/single_include)
 | 
			
		||||
 | 
			
		||||
    add_subdirectory(SourceFiles/base/tests)
 | 
			
		||||
endif()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
add_executable(tests_flags flags_tests.cpp)
 | 
			
		||||
target_link_libraries(tests_flags Qt5::Core)
 | 
			
		||||
add_test(flagsTest ${CMAKE_BINARY_DIR}/bin/tests_flags)
 | 
			
		||||
 | 
			
		||||
add_executable(tests_flat_map flat_map_tests.cpp)
 | 
			
		||||
target_link_libraries(tests_flat_map Qt5::Core)
 | 
			
		||||
add_test(flatMapTest ${CMAKE_BINARY_DIR}/bin/tests_flat_map)
 | 
			
		||||
 | 
			
		||||
add_executable(tests_flat_set flat_set_tests.cpp)
 | 
			
		||||
target_link_libraries(tests_flat_set Qt5::Core)
 | 
			
		||||
add_test(flatSetTest ${CMAKE_BINARY_DIR}/bin/tests_flat_set)
 | 
			
		||||
| 
						 | 
				
			
			@ -18,6 +18,7 @@ to link the code of portions of this program with the OpenSSL library.
 | 
			
		|||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
 | 
			
		||||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 | 
			
		||||
*/
 | 
			
		||||
#define CATCH_CONFIG_MAIN
 | 
			
		||||
#include "catch.hpp"
 | 
			
		||||
 | 
			
		||||
#include "base/flags.h"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,6 +18,7 @@ to link the code of portions of this program with the OpenSSL library.
 | 
			
		|||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
 | 
			
		||||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 | 
			
		||||
*/
 | 
			
		||||
#define CATCH_CONFIG_MAIN
 | 
			
		||||
#include "catch.hpp"
 | 
			
		||||
 | 
			
		||||
#include "base/flat_map.h"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,6 +18,7 @@ to link the code of portions of this program with the OpenSSL library.
 | 
			
		|||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
 | 
			
		||||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 | 
			
		||||
*/
 | 
			
		||||
#define CATCH_CONFIG_MAIN
 | 
			
		||||
#include "catch.hpp"
 | 
			
		||||
 | 
			
		||||
#include "base/flat_set.h"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,97 +0,0 @@
 | 
			
		|||
/*
 | 
			
		||||
This file is part of Telegram Desktop,
 | 
			
		||||
the official desktop version of Telegram messaging app, see https://telegram.org
 | 
			
		||||
 | 
			
		||||
Telegram Desktop is free software: you can redistribute it and/or modify
 | 
			
		||||
it under the terms of the GNU General Public License as published by
 | 
			
		||||
the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
(at your option) any later version.
 | 
			
		||||
 | 
			
		||||
It is distributed in the hope that it will be useful,
 | 
			
		||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
In addition, as a special exception, the copyright holders give permission
 | 
			
		||||
to link the code of portions of this program with the OpenSSL library.
 | 
			
		||||
 | 
			
		||||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
 | 
			
		||||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 | 
			
		||||
*/
 | 
			
		||||
#define CATCH_CONFIG_RUNNER
 | 
			
		||||
#include "catch.hpp"
 | 
			
		||||
#include "reporters/catch_reporter_compact.hpp"
 | 
			
		||||
#include <QFile>
 | 
			
		||||
 | 
			
		||||
namespace Catch {
 | 
			
		||||
 | 
			
		||||
	struct MinimalReporter : CompactReporter {
 | 
			
		||||
		MinimalReporter( ReporterConfig const& _config )
 | 
			
		||||
        : CompactReporter( _config )
 | 
			
		||||
        {}
 | 
			
		||||
 | 
			
		||||
        virtual void testRunEnded( TestRunStats const& _testRunStats ) {
 | 
			
		||||
            printTotals( _testRunStats.totals );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    private:
 | 
			
		||||
        // Colour, message variants:
 | 
			
		||||
        // - white: No tests ran.
 | 
			
		||||
        // -   red: Failed [both/all] N test cases, failed [both/all] M assertions.
 | 
			
		||||
        // - white: Passed [both/all] N test cases (no assertions).
 | 
			
		||||
        // -   red: Failed N tests cases, failed M assertions.
 | 
			
		||||
        // - green: Passed [both/all] N tests cases with M assertions.
 | 
			
		||||
 | 
			
		||||
        std::string bothOrAll( std::size_t count ) const {
 | 
			
		||||
            return count == 1 ? std::string() : count == 2 ? "both " : "all " ;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void printTotals( const Totals& totals ) const {
 | 
			
		||||
            if( totals.testCases.total() == 0 ) {
 | 
			
		||||
            }
 | 
			
		||||
            else if( totals.testCases.failed == totals.testCases.total() ) {
 | 
			
		||||
                Colour colour( Colour::ResultError );
 | 
			
		||||
                const std::string qualify_assertions_failed =
 | 
			
		||||
                    totals.assertions.failed == totals.assertions.total() ?
 | 
			
		||||
                        bothOrAll( totals.assertions.failed ) : std::string();
 | 
			
		||||
                stream <<
 | 
			
		||||
                    "Failed " << bothOrAll( totals.testCases.failed )
 | 
			
		||||
                              << pluralise( totals.testCases.failed, "test case"  ) << ", "
 | 
			
		||||
                    "failed " << qualify_assertions_failed <<
 | 
			
		||||
                                 pluralise( totals.assertions.failed, "assertion" ) << '.';
 | 
			
		||||
            }
 | 
			
		||||
            else if( totals.assertions.total() == 0 ) {
 | 
			
		||||
                stream <<
 | 
			
		||||
                    "Passed " << bothOrAll( totals.testCases.total() )
 | 
			
		||||
                              << pluralise( totals.testCases.total(), "test case" )
 | 
			
		||||
                              << " (no assertions).";
 | 
			
		||||
            }
 | 
			
		||||
            else if( totals.assertions.failed ) {
 | 
			
		||||
                Colour colour( Colour::ResultError );
 | 
			
		||||
                stream <<
 | 
			
		||||
                    "Failed " << pluralise( totals.testCases.failed, "test case"  ) << ", "
 | 
			
		||||
                    "failed " << pluralise( totals.assertions.failed, "assertion" ) << '.';
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    INTERNAL_CATCH_REGISTER_REPORTER( "minimal", MinimalReporter )
 | 
			
		||||
 | 
			
		||||
} // end namespace Catch
 | 
			
		||||
 | 
			
		||||
int main(int argc, const char *argv[]) {
 | 
			
		||||
	const char *catch_argv[] = { argv[0], "-r", "minimal" };
 | 
			
		||||
	constexpr auto catch_argc = sizeof(catch_argv) / sizeof(catch_argv[0]);
 | 
			
		||||
	auto result = Catch::Session().run(catch_argc, catch_argv);
 | 
			
		||||
	if (result == 0) {
 | 
			
		||||
		for (auto i = 0; i != argc; ++i) {
 | 
			
		||||
			if (argv[i] == QString("--touch") && i + 1 != argc) {
 | 
			
		||||
				QFile(QFile::decodeName(argv[++i])).open(QIODevice::WriteOnly);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return (result < 0xff ? result : 0xff);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue