mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-23 13:05:39 +02:00
WIP: bazel support and CLI parameter
This commit is contained in:
@@ -119,6 +119,8 @@ namespace Catch {
|
|||||||
m_data.reporterSpecifications.push_back( std::move( *parsed ) );
|
m_data.reporterSpecifications.push_back( std::move( *parsed ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reading bazel env vars can change some parts of the config data,
|
||||||
|
// so we have to process the bazel env before acting on the config.
|
||||||
if ( enableBazelEnvSupport() ) {
|
if ( enableBazelEnvSupport() ) {
|
||||||
readBazelEnvVars();
|
readBazelEnvVars();
|
||||||
}
|
}
|
||||||
@@ -183,6 +185,8 @@ namespace Catch {
|
|||||||
|
|
||||||
bool Config::showHelp() const { return m_data.showHelp; }
|
bool Config::showHelp() const { return m_data.showHelp; }
|
||||||
|
|
||||||
|
std::string const& Config::getExitGuardFilePath() const { return m_data.prematureExitGuardFilePath; }
|
||||||
|
|
||||||
// IConfig interface
|
// IConfig interface
|
||||||
bool Config::allowThrows() const { return !m_data.noThrow; }
|
bool Config::allowThrows() const { return !m_data.noThrow; }
|
||||||
StringRef Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
|
StringRef Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
|
||||||
@@ -244,6 +248,11 @@ namespace Catch {
|
|||||||
m_data.shardCount = bazelShardOptions->shardCount;
|
m_data.shardCount = bazelShardOptions->shardCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto bazelExitGuardFile = Detail::getEnv( "TEST_PREMATURE_EXIT_FILE" );
|
||||||
|
if (bazelExitGuardFile) {
|
||||||
|
m_data.prematureExitGuardFilePath = bazelExitGuardFile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@@ -87,6 +87,8 @@ namespace Catch {
|
|||||||
|
|
||||||
std::vector<std::string> testsOrTags;
|
std::vector<std::string> testsOrTags;
|
||||||
std::vector<std::string> sectionsToRun;
|
std::vector<std::string> sectionsToRun;
|
||||||
|
|
||||||
|
std::string prematureExitGuardFilePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -114,6 +116,8 @@ namespace Catch {
|
|||||||
|
|
||||||
bool showHelp() const;
|
bool showHelp() const;
|
||||||
|
|
||||||
|
std::string const& getExitGuardFilePath() const;
|
||||||
|
|
||||||
// IConfig interface
|
// IConfig interface
|
||||||
bool allowThrows() const override;
|
bool allowThrows() const override;
|
||||||
StringRef name() const override;
|
StringRef name() const override;
|
||||||
|
@@ -26,6 +26,8 @@
|
|||||||
#include <catch2/internal/catch_istream.hpp>
|
#include <catch2/internal/catch_istream.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <set>
|
#include <set>
|
||||||
@@ -140,6 +142,50 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates empty file at path. The path must be writable, we do not
|
||||||
|
// try to create directories in path because that's hard in C++14.
|
||||||
|
void setUpGuardFile( std::string const& guardFilePath ) {
|
||||||
|
if ( !guardFilePath.empty() ) {
|
||||||
|
#if defined( _MSC_VER )
|
||||||
|
std::FILE* file = nullptr;
|
||||||
|
if ( fopen_s( &file, guardFilePath.c_str(), "w" ) ) {
|
||||||
|
char msgBuffer[100];
|
||||||
|
const auto err = errno;
|
||||||
|
std::string errMsg;
|
||||||
|
if ( !strerror_s( msgBuffer, err ) ) {
|
||||||
|
errMsg = msgBuffer;
|
||||||
|
} else {
|
||||||
|
errMsg = "Could not translate errno to a string";
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
std::FILE* file = std::fopen( guardFilePath.c_str(), "w" );
|
||||||
|
if ( !file ) {
|
||||||
|
const auto err = errno;
|
||||||
|
const char* errMsg = std::strerror( err );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CATCH_RUNTIME_ERROR( "Could not open the exit guard file '"
|
||||||
|
<< guardFilePath << "' because '"
|
||||||
|
<< errMsg << "' (" << err << ')' );
|
||||||
|
}
|
||||||
|
const int ret = std::fclose( file );
|
||||||
|
CATCH_ENFORCE(
|
||||||
|
ret == 0,
|
||||||
|
"Error when closing the exit guard file: " << ret );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Removes file at path. Assuming we created it in setUpGuardFile.
|
||||||
|
void tearDownGuardFile( std::string const& guardFilePath ) {
|
||||||
|
if ( !guardFilePath.empty() ) {
|
||||||
|
const int ret = std::remove( guardFilePath.c_str() );
|
||||||
|
CATCH_ENFORCE(
|
||||||
|
ret == 0,
|
||||||
|
"Error when removing the exit guard file: " << ret );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // anon namespace
|
} // anon namespace
|
||||||
|
|
||||||
Session::Session() {
|
Session::Session() {
|
||||||
@@ -258,6 +304,7 @@ namespace Catch {
|
|||||||
static_cast<void>(std::getchar());
|
static_cast<void>(std::getchar());
|
||||||
}
|
}
|
||||||
int exitCode = runInternal();
|
int exitCode = runInternal();
|
||||||
|
|
||||||
if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
|
if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
|
||||||
Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << '\n' << std::flush;
|
Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << '\n' << std::flush;
|
||||||
static_cast<void>(std::getchar());
|
static_cast<void>(std::getchar());
|
||||||
@@ -298,6 +345,10 @@ namespace Catch {
|
|||||||
CATCH_TRY {
|
CATCH_TRY {
|
||||||
config(); // Force config to be constructed
|
config(); // Force config to be constructed
|
||||||
|
|
||||||
|
// We need to retrieve potential Bazel config with the full Config
|
||||||
|
// constructor, so we have to create the guard file after it is created.
|
||||||
|
setUpGuardFile( m_config->getExitGuardFilePath() );
|
||||||
|
|
||||||
seedRng( *m_config );
|
seedRng( *m_config );
|
||||||
|
|
||||||
if (m_configData.filenamesAsTags) {
|
if (m_configData.filenamesAsTags) {
|
||||||
@@ -327,9 +378,12 @@ namespace Catch {
|
|||||||
TestGroup tests { CATCH_MOVE(reporter), m_config.get() };
|
TestGroup tests { CATCH_MOVE(reporter), m_config.get() };
|
||||||
auto const totals = tests.execute();
|
auto const totals = tests.execute();
|
||||||
|
|
||||||
|
// If we got here, running the tests finished normally-enough.
|
||||||
|
// They might've failed, but that would've been reported elsewhere.
|
||||||
|
tearDownGuardFile( m_config->getExitGuardFilePath() );
|
||||||
|
|
||||||
if ( tests.hadUnmatchedTestSpecs()
|
if ( tests.hadUnmatchedTestSpecs()
|
||||||
&& m_config->warnAboutUnmatchedTestSpecs() ) {
|
&& m_config->warnAboutUnmatchedTestSpecs() ) {
|
||||||
// UnmatchedTestSpecExitCode
|
|
||||||
return UnmatchedTestSpecExitCode;
|
return UnmatchedTestSpecExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -305,6 +305,9 @@ namespace Catch {
|
|||||||
| Opt( config.allowZeroTests )
|
| Opt( config.allowZeroTests )
|
||||||
["--allow-running-no-tests"]
|
["--allow-running-no-tests"]
|
||||||
( "Treat 'No tests run' as a success" )
|
( "Treat 'No tests run' as a success" )
|
||||||
|
| Opt( config.prematureExitGuardFilePath, "path" )
|
||||||
|
["--premature-exit-guard-file"]
|
||||||
|
( "create a file before running tests and delete it during clean exit" )
|
||||||
| Arg( config.testsOrTags, "test name|pattern|tags" )
|
| Arg( config.testsOrTags, "test name|pattern|tags" )
|
||||||
( "which test or tests to use" );
|
( "which test or tests to use" );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user