Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2017-06-20 18:03:37 +0100
committerPhil Nash2017-06-20 18:03:47 +0100
commitda5964af782fc6dc1d7c8f19507e967f3a286ca9 (patch)
tree8af8a11eb1735dbd8a4080d449cc6a75318c5e1b /include
parentee0defb93900f1b8fdf65dfcbd2db1b1f33137bd (diff)
downloadcatch3-da5964af782fc6dc1d7c8f19507e967f3a286ca9.tar.gz
Updated version of Clara (should fix Windows compile issues)
- embedded using new embed script
Diffstat (limited to 'include')
-rw-r--r--include/external/clara.hpp102
-rw-r--r--include/internal/catch_clara.h8
2 files changed, 68 insertions, 42 deletions
diff --git a/include/external/clara.hpp b/include/external/clara.hpp
index f4ad627f..b2eced66 100644
--- a/include/external/clara.hpp
+++ b/include/external/clara.hpp
@@ -4,23 +4,40 @@
#ifndef CATCH_CLARA_HPP_INCLUDED
#define CATCH_CLARA_HPP_INCLUDED
+
+#ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH
+#define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80
+#endif
+
+
+// ----------- #included from clara_textflow.hpp -----------
+
+// TextFlowCpp
+//
+// A single-header library for wrapping and laying out basic text, by Phil Nash
+//
+// This work is licensed under the BSD 2-Clause license.
+// See the accompanying LICENSE file, or the one at https://opensource.org/licenses/BSD-2-Clause
+//
+// This project is hosted at https://github.com/philsquared/textflowcpp
+
+#ifndef CATCH_CLARA_TEXTFLOW_HPP_INCLUDED
+#define CATCH_CLARA_TEXTFLOW_HPP_INCLUDED
+
+
#include <cassert>
#include <ostream>
#include <sstream>
#include <vector>
-#include <memory>
-#include <set>
-#include <algorithm>
-#ifndef CLARA_CONFIG_CONSOLE_WIDTH
-#define CLARA_CONFIG_CONSOLE_WIDTH 80
+#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
+#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
+
#endif
-namespace Catch {
-namespace clara {
-// Included from TextFlow.hpp
-namespace TextFlow {
+namespace Catch { namespace clara { namespace TextFlow
+{
inline auto isWhitespace( char c ) -> bool {
static std::string chars = " \t\n\r";
@@ -39,7 +56,7 @@ namespace TextFlow {
class Column {
std::vector<std::string> m_strings;
- size_t m_width = CLARA_CONFIG_CONSOLE_WIDTH;
+ size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH;
size_t m_indent = 0;
size_t m_initialIndent = std::string::npos;
@@ -51,12 +68,12 @@ namespace TextFlow {
size_t m_stringIndex = 0;
size_t m_pos = 0;
- size_t m_len;
+ size_t m_len = 0;
bool m_suffix = false;
iterator( Column const& column, size_t stringIndex )
- : m_column( column ),
- m_stringIndex( stringIndex )
+ : m_column( column ),
+ m_stringIndex( stringIndex )
{}
auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; }
@@ -143,9 +160,9 @@ namespace TextFlow {
auto operator ==( iterator const& other ) const -> bool {
return
- m_pos == other.m_pos &&
- m_stringIndex == other.m_stringIndex &&
- &m_column == &other.m_column;
+ m_pos == other.m_pos &&
+ m_stringIndex == other.m_stringIndex &&
+ &m_column == &other.m_column;
}
auto operator !=( iterator const& other ) const -> bool {
return !operator==( other );
@@ -171,7 +188,7 @@ namespace TextFlow {
auto width() const -> size_t { return m_width; }
auto begin() const -> iterator { return iterator( *this ); }
- auto end() const -> iterator { return iterator( *this, m_strings.size() ); }
+ auto end() const -> iterator { return { *this, m_strings.size() }; }
inline friend std::ostream& operator << ( std::ostream& os, Column const& col ) {
bool first = true;
@@ -197,7 +214,7 @@ namespace TextFlow {
class Spacer : public Column {
public:
- Spacer( size_t spaceWidth ) : Column( "" ) {
+ explicit Spacer( size_t spaceWidth ) : Column( "" ) {
width( spaceWidth );
}
};
@@ -216,8 +233,8 @@ namespace TextFlow {
size_t m_activeIterators;
iterator( Columns const& columns, EndTag )
- : m_columns( columns.m_columns ),
- m_activeIterators( 0 )
+ : m_columns( columns.m_columns ),
+ m_activeIterators( 0 )
{
m_iterators.reserve( m_columns.size() );
@@ -226,9 +243,9 @@ namespace TextFlow {
}
public:
- iterator( Columns const& columns )
- : m_columns( columns.m_columns ),
- m_activeIterators( m_columns.size() )
+ explicit iterator( Columns const& columns )
+ : m_columns( columns.m_columns ),
+ m_activeIterators( m_columns.size() )
{
m_iterators.reserve( m_columns.size() );
@@ -277,7 +294,7 @@ namespace TextFlow {
using const_iterator = iterator;
auto begin() const -> iterator { return iterator( *this ); }
- auto end() const -> iterator { return iterator( *this, iterator::EndTag() ); }
+ auto end() const -> iterator { return { *this, iterator::EndTag() }; }
auto operator += ( Column const& col ) -> Columns& {
m_columns.push_back( col );
@@ -315,9 +332,19 @@ namespace TextFlow {
cols += other;
return cols;
}
+}}} // namespace Catch::clara::TextFlow
+
+#endif // CATCH_CLARA_TEXTFLOW_HPP_INCLUDED
+
+// ----------- end of #include from clara_textflow.hpp -----------
+// ........... back in clara.hpp
-} // namespace TextFlow
+#include <memory>
+#include <set>
+#include <algorithm>
+
+namespace Catch { namespace clara {
namespace detail {
// Traits for extracting arg and return type of lambdas (for single argument lambdas)
@@ -475,8 +502,7 @@ namespace detail {
new(&m_value) T(other.m_value);
}
- ResultValueBase(Type type, T const &value)
- : ResultBase(Ok) {
+ ResultValueBase(Type, T const &value) : ResultBase(Ok) {
new(&m_value) T(value);
}
@@ -600,10 +626,9 @@ namespace detail {
target = source;
return ParserResult::ok(ParseResultType::Matched);
}
-
inline auto convertInto(std::string const &source, bool &target) -> ParserResult {
std::string srcLC = source;
- std::transform(srcLC.begin(), srcLC.end(), srcLC.begin(), ::tolower);
+ std::transform(srcLC.begin(), srcLC.end(), srcLC.begin(), [](char c) { return static_cast<char>( ::tolower(c) ); } );
if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on")
target = true;
else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off")
@@ -869,7 +894,7 @@ namespace detail {
public:
using ParserRefImpl::ParserRefImpl;
- auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override {
+ auto parse(std::string const &, TokenStream const &tokens) const -> InternalParseResult override {
auto validationResult = validate();
if (!validationResult)
return InternalParseResult(validationResult);
@@ -941,10 +966,10 @@ namespace detail {
using ParserBase::parse;
- auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override {
- auto result = validate();
- if (!result)
- return InternalParseResult(result);
+ auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override {
+ auto validationResult = validate();
+ if (!validationResult)
+ return InternalParseResult(validationResult);
auto remainingTokens = tokens;
if (remainingTokens && remainingTokens->type == TokenType::Option) {
@@ -1069,6 +1094,7 @@ namespace detail {
}
auto rows = getHelpColumns();
+ size_t consoleWidth = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH;
size_t optWidth = 0;
for (auto const &cols : rows)
optWidth = std::max(optWidth, cols.left.size() + 2);
@@ -1077,7 +1103,7 @@ namespace detail {
auto row =
TextFlow::Column(cols.left).width(optWidth).indent(2) +
TextFlow::Spacer(4) +
- TextFlow::Column(cols.right).width(73 - optWidth);
+ TextFlow::Column(cols.right).width(consoleWidth - 7 - optWidth);
os << row << std::endl;
}
}
@@ -1131,7 +1157,7 @@ namespace detail {
auto result = InternalParseResult::ok(ParseState(ParseResultType::NoMatch, tokens));
while (result.value().remainingTokens()) {
- int remainingTokenCount = result.value().remainingTokens().count();
+ auto remainingTokenCount = result.value().remainingTokens().count();
for (auto parser : allParsers) {
result = parser->parse( exeName, result.value().remainingTokens() );
if (!result || result.value().type() != ParseResultType::NoMatch) {
@@ -1183,7 +1209,7 @@ using detail::ParseResultType;
using detail::ParserResult;
-} // namespace clara
-} // namespace Catch
+}} // namespace Catch::clara
+
#endif // CATCH_CLARA_HPP_INCLUDED
diff --git a/include/internal/catch_clara.h b/include/internal/catch_clara.h
index 9c66a55d..1aeb4658 100644
--- a/include/internal/catch_clara.h
+++ b/include/internal/catch_clara.h
@@ -11,10 +11,10 @@
// Use Catch's value for console width (store Clara's off to the side, if present)
#ifdef CLARA_CONFIG_CONSOLE_WIDTH
-#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
-#undef CLARA_CONFIG_CONSOLE_WIDTH
+#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
+#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
#endif
-#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
+#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
#include "../external/clara.hpp"
@@ -22,7 +22,7 @@
// Restore Clara's value for console width, if present
#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
-#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
+#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
#endif