fix and finish the diagnostics helper
there was still a subtle bug in this helper. testing your own test fixture is sometimes a good idea ;-)
This commit is contained in:
parent
4145452397
commit
059dbd8c75
3 changed files with 50 additions and 16 deletions
|
|
@ -112,7 +112,14 @@ namespace test{
|
|||
: "VAL";
|
||||
}
|
||||
|
||||
/** helper for investigating a variadic argument pack */
|
||||
/** helper for investigating a variadic argument pack
|
||||
* @warning always spell out the template arguments explicitly
|
||||
* when invoking this diagnostics, e.g. \c showVariadicTypes<ARGS...>(args...)
|
||||
* otherwise the template argument matching for functions might mess up the
|
||||
* kind of reference you'll see in the diagnostics.
|
||||
* @see test-helper-variadic-test.cpp
|
||||
*/
|
||||
template<typename... EMPTY>
|
||||
inline string
|
||||
showVariadicTypes ()
|
||||
{
|
||||
|
|
@ -120,7 +127,7 @@ namespace test{
|
|||
}
|
||||
|
||||
template<typename X, typename... XS>
|
||||
string
|
||||
inline string
|
||||
showVariadicTypes (X const& x, XS const&... xs)
|
||||
{
|
||||
return " :---#"
|
||||
|
|
@ -129,12 +136,13 @@ namespace test{
|
|||
+ " " + showRefKind<X>()
|
||||
+ " Address* " + boost::lexical_cast<string>(&x)
|
||||
+ "\n"
|
||||
+ showVariadicTypes (xs...);
|
||||
+ showVariadicTypes<XS...> (xs...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** create a random but not insane Time value */
|
||||
inline lib::time::Time
|
||||
randTime ()
|
||||
|
|
|
|||
|
|
@ -822,6 +822,33 @@ out: sizeof.+lib.+test.+test.+Wrmrmpft.+Murpf.+ = 1
|
|||
END
|
||||
|
||||
|
||||
TEST "Variadic template diagnostics" TestHelperVariadic_test <<END
|
||||
out-lit: --no-arg--
|
||||
out-lit: :.
|
||||
out-lit: --value--
|
||||
out: .+#1.+ Type: d VAL Address. 0x.+
|
||||
out-lit: :.
|
||||
out-lit: --reference--
|
||||
out: .+#1.+ Type: d REF Address. 0x.+
|
||||
out-lit: :.
|
||||
out-lit: --move--
|
||||
out: .+#1.+ Type: d MOV Address. 0x.+
|
||||
out-lit: :.
|
||||
out-lit: --two values--
|
||||
out: .+#2.+ Type: A4_c REF Address. 0x.+
|
||||
out: .+#1.+ Type: l MOV Address. 0x.+
|
||||
out-lit: :.
|
||||
out-lit: --matched--
|
||||
out: .+#3.+ Type: d REF Address. 0x.+
|
||||
out: .+#2.+ Type: d REF Address. 0x.+
|
||||
out: .+#1.+ Type: d MOV Address. 0x.+
|
||||
out-lit: :.
|
||||
out-lit: --baseclass--
|
||||
out: .+#1.+ Type: .+lib.test.test.+Interface. REF Address. 0x.+
|
||||
out-lit: :.
|
||||
END
|
||||
|
||||
|
||||
TEST "TestOption_test" TestOption_test <<END
|
||||
out: Testing invocation with cmdline: ...
|
||||
out: --> Testgroup=ALL
|
||||
|
|
|
|||
|
|
@ -23,21 +23,15 @@
|
|||
|
||||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
|
||||
//#include <boost/lexical_cast.hpp>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
//#include <map>
|
||||
|
||||
//using boost::lexical_cast;
|
||||
//using util::contains;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
//using std::endl;
|
||||
|
||||
|
||||
namespace lib {
|
||||
|
|
@ -65,7 +59,7 @@ namespace test{
|
|||
string s_;
|
||||
|
||||
public:
|
||||
Impl(string ss ="IMP") : s_(ss) { }
|
||||
Impl(string ss ="ZOMG") : s_(ss) { }
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -106,28 +100,33 @@ namespace test{
|
|||
{
|
||||
double d = makeRvalue();
|
||||
double& dr = d;
|
||||
|
||||
|
||||
Impl obj;
|
||||
Interface const& ref = obj;
|
||||
|
||||
|
||||
cout << "--no-arg--\n" << showVariadicTypes() <<"\n";
|
||||
cout << "--value--\n" << showVariadicTypes<double>(d) <<"\n";
|
||||
cout << "--reference--\n" << showVariadicTypes<double&>(d) <<"\n";
|
||||
cout << "--move--\n" << showVariadicTypes<double&&>(d) <<"\n";
|
||||
|
||||
forwardFunction("two values", "foo", 42L);
|
||||
forwardFunction("matched", d,dr,std::move(dr));
|
||||
forwardFunction("two values", "foo", 42L); // passed as REF, MOV
|
||||
forwardFunction("matched", d,dr,std::move(dr)); // passed as REF, REF, MOV
|
||||
|
||||
forwardFunction<Interface const&>("baseclass", ref);
|
||||
}
|
||||
|
||||
|
||||
/** this dummy simulates a typical variadic call
|
||||
* which takes all arguments as '&&' for the purpose of "perfect forwarding"
|
||||
*/
|
||||
template<typename... ARGS>
|
||||
void
|
||||
forwardFunction (string id, ARGS const&... args)
|
||||
forwardFunction (string id, ARGS&&... args)
|
||||
{
|
||||
// in reality here you'd invoke some factory(<std::forward<ARGS>(args)...)
|
||||
//
|
||||
cout << "--"<<id<<"--\n"
|
||||
<< showVariadicTypes<ARGS...>(args...)
|
||||
<< showVariadicTypes<ARGS&&...>(args...)
|
||||
<< "\n"
|
||||
;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue