Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c8dbd6

Browse files
Properly print Arduino String objects in tests
This ensures that checks like: REQUIRE(some_str == "ABC");Actually print the value of some_str instead of just `1` (which is theString object converted to StringIfHelperType).This is implemented by adding a specialization of the Catch StringMakertemplate, so this only takes effect when StringPrinter.h is included.This commit includes it in all the String testcases (even ones that donot strictly use it now) for good measure.
1 parent3caa039 commit0c8dbd6

19 files changed

+60
-0
lines changed

‎test/src/String/StringPrinter.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include<catch.hpp>
4+
#include<String.h>
5+
6+
namespaceCatch {
7+
/**
8+
* Template specialization that makes sure Catch can properly print
9+
* Arduino Strings when used in comparisons directly.
10+
*
11+
* Note that without this, String objects are printed as 0 and 1,
12+
* because they are implicitly convertible to StringIfHelperType,
13+
* which is a dummy pointer.
14+
*/
15+
template<>
16+
structStringMaker<arduino::String> {
17+
static std::stringconvert(const arduino::String& str) {
18+
if (str)
19+
return ::Catch::Detail::stringify(std::string(str.c_str(), str.length()));
20+
else
21+
return"{invalid String}";
22+
}
23+
};
24+
}// namespace Catch

‎test/src/String/test_String.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include<String.h>
1414

15+
#include"StringPrinter.h"
16+
1517
/**************************************************************************************
1618
* TEST CODE
1719
**************************************************************************************/

‎test/src/String/test_characterAccessFunc.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include<String.h>
1212

13+
#include"StringPrinter.h"
14+
1315
/**************************************************************************************
1416
* TEST CODE
1517
**************************************************************************************/

‎test/src/String/test_compareTo.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include<String.h>
1212

13+
#include"StringPrinter.h"
14+
1315
/**************************************************************************************
1416
* TEST CODE
1517
**************************************************************************************/

‎test/src/String/test_comparisonFunc.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include<String.h>
1212

13+
#include"StringPrinter.h"
14+
1315
/**************************************************************************************
1416
* TEST CODE
1517
**************************************************************************************/

‎test/src/String/test_concat.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include<String.h>
1212

13+
#include"StringPrinter.h"
14+
1315
/**************************************************************************************
1416
* TEST CODE
1517
**************************************************************************************/

‎test/src/String/test_indexOf.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include<String.h>
1212

13+
#include"StringPrinter.h"
14+
1315
/**************************************************************************************
1416
* TEST CODE
1517
**************************************************************************************/

‎test/src/String/test_lastIndexOf.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include<String.h>
1212

13+
#include"StringPrinter.h"
14+
1315
/**************************************************************************************
1416
* TEST CODE
1517
**************************************************************************************/

‎test/src/String/test_length.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include<String.h>
1212

13+
#include"StringPrinter.h"
14+
1315
/**************************************************************************************
1416
* TEST CODE
1517
**************************************************************************************/

‎test/src/String/test_operators.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include<String.h>
1212

13+
#include"StringPrinter.h"
14+
1315
/**************************************************************************************
1416
* TEST CODE
1517
**************************************************************************************/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp