Commit dd014585 authored by Michaël Roynard's avatar Michaël Roynard
Browse files

Implement tool

parent c4a5ca1e
Pipeline #1940 passed with stage
in 45 seconds
#include <gtest/gtest.h>
namespace {
template<auto &F, auto ... Args, auto = F(Args...)>
constexpr bool is_constexpr(int) {
return true;
}
template<auto &F, auto ... Args>
constexpr bool is_constexpr(...) {
return false;
}
}
#define ASSERT_COMPILETIME_EXPR(...) \
do { \
constexpr bool ret = is_constexpr<__VA_ARGS__>(0); \
ASSERT_TRUE(ret); \
} while(false);
#define ASSERT_RUNTIME_EXPR(...) \
do { \
constexpr bool ret = is_constexpr<__VA_ARGS__>(0); \
ASSERT_FALSE(ret); \
} while(false);
#include <gtest-constexpr-ext/gtest-constexpr-ext.hpp>
#include <gtest/gtest.h>
TEST(Always_True, True)
constexpr int f(int a) {
if (a == 0) {
throw "Runtime!";
} else {
return a;
}
}
TEST(Gtest_Constexpr_Ext, Compiletime)
{
ASSERT_COMPILETIME_EXPR(f, 1);
}
TEST(Gtest_Constexpr_Ext, Runtime)
{
ASSERT_TRUE(true);
ASSERT_RUNTIME_EXPR(f, 0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment