[clang-tidy] NFC Consolidate test absl::Time implementation
authorJonas Toth <jonas.toth@gmail.com>
Tue, 11 Dec 2018 12:42:17 +0000 (12:42 +0000)
committerJonas Toth <jonas.toth@gmail.com>
Tue, 11 Dec 2018 12:42:17 +0000 (12:42 +0000)
Summary: Several tests re-implement these same prototypes (differently), so we can put them in a common location.

Patch by hwright.

Reviewers: JonasToth

Reviewed By: JonasToth

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D55540

llvm-svn: 348840

clang-tools-extra/test/clang-tidy/Inputs/absl/time/time.h [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/abseil-duration-comparison.cpp
clang-tools-extra/test/clang-tidy/abseil-duration-factory-float.cpp
clang-tools-extra/test/clang-tidy/abseil-duration-factory-scale.cpp
clang-tools-extra/test/clang-tidy/abseil-upgrade-duration-conversions.cpp

diff --git a/clang-tools-extra/test/clang-tidy/Inputs/absl/time/time.h b/clang-tools-extra/test/clang-tidy/Inputs/absl/time/time.h
new file mode 100644 (file)
index 0000000..9d136a5
--- /dev/null
@@ -0,0 +1,72 @@
+// Mimic the implementation of absl::Duration
+namespace absl {
+
+using int64_t = long long int;
+
+class Duration {
+public:
+  Duration &operator*=(int64_t r);
+  Duration &operator*=(float r);
+  Duration &operator*=(double r);
+  template <typename T> Duration &operator*=(T r);
+
+  Duration &operator/=(int64_t r);
+  Duration &operator/=(float r);
+  Duration &operator/=(double r);
+  template <typename T> Duration &operator/=(T r);
+};
+
+template <typename T> Duration operator*(Duration lhs, T rhs);
+template <typename T> Duration operator*(T lhs, Duration rhs);
+template <typename T> Duration operator/(Duration lhs, T rhs);
+
+class Time{};
+
+constexpr Duration Nanoseconds(long long);
+constexpr Duration Microseconds(long long);
+constexpr Duration Milliseconds(long long);
+constexpr Duration Seconds(long long);
+constexpr Duration Minutes(long long);
+constexpr Duration Hours(long long);
+
+template <typename T> struct EnableIfFloatImpl {};
+template <> struct EnableIfFloatImpl<float> { typedef int Type; };
+template <> struct EnableIfFloatImpl<double> { typedef int Type; };
+template <> struct EnableIfFloatImpl<long double> { typedef int Type; };
+template <typename T> using EnableIfFloat = typename EnableIfFloatImpl<T>::Type;
+
+template <typename T, EnableIfFloat<T> = 0> Duration Nanoseconds(T n);
+template <typename T, EnableIfFloat<T> = 0> Duration Microseconds(T n);
+template <typename T, EnableIfFloat<T> = 0> Duration Milliseconds(T n);
+template <typename T, EnableIfFloat<T> = 0> Duration Seconds(T n);
+template <typename T, EnableIfFloat<T> = 0> Duration Minutes(T n);
+template <typename T, EnableIfFloat<T> = 0> Duration Hours(T n);
+
+double ToDoubleHours(Duration d);
+double ToDoubleMinutes(Duration d);
+double ToDoubleSeconds(Duration d);
+double ToDoubleMilliseconds(Duration d);
+double ToDoubleMicroseconds(Duration d);
+double ToDoubleNanoseconds(Duration d);
+int64_t ToInt64Hours(Duration d);
+int64_t ToInt64Minutes(Duration d);
+int64_t ToInt64Seconds(Duration d);
+int64_t ToInt64Milliseconds(Duration d);
+int64_t ToInt64Microseconds(Duration d);
+int64_t ToInt64Nanoseconds(Duration d);
+
+// Relational Operators
+constexpr bool operator<(Duration lhs, Duration rhs);
+constexpr bool operator>(Duration lhs, Duration rhs);
+constexpr bool operator>=(Duration lhs, Duration rhs);
+constexpr bool operator<=(Duration lhs, Duration rhs);
+constexpr bool operator==(Duration lhs, Duration rhs);
+constexpr bool operator!=(Duration lhs, Duration rhs);
+
+// Additive Operators
+inline Time operator+(Time lhs, Duration rhs);
+inline Time operator+(Duration lhs, Time rhs);
+inline Time operator-(Time lhs, Duration rhs);
+inline Duration operator-(Time lhs, Time rhs);
+
+}  // namespace absl
index a24e6f8..7a70db6 100644 (file)
@@ -1,62 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-duration-comparison %t
+// RUN: %check_clang_tidy %s abseil-duration-comparison %t -- -- -I%S/Inputs
 
-// Mimic the implementation of absl::Duration
-namespace absl {
-
-class Duration {};
-class Time{};
-
-Duration Nanoseconds(long long);
-Duration Microseconds(long long);
-Duration Milliseconds(long long);
-Duration Seconds(long long);
-Duration Minutes(long long);
-Duration Hours(long long);
-
-#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \
-  Duration NAME(float n);                         \
-  Duration NAME(double n);                        \
-  template <typename T>                           \
-  Duration NAME(T n);
-
-GENERATE_DURATION_FACTORY_OVERLOADS(Nanoseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Microseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Milliseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Seconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Minutes);
-GENERATE_DURATION_FACTORY_OVERLOADS(Hours);
-#undef GENERATE_DURATION_FACTORY_OVERLOADS
-
-using int64_t = long long int;
-
-double ToDoubleHours(Duration d);
-double ToDoubleMinutes(Duration d);
-double ToDoubleSeconds(Duration d);
-double ToDoubleMilliseconds(Duration d);
-double ToDoubleMicroseconds(Duration d);
-double ToDoubleNanoseconds(Duration d);
-int64_t ToInt64Hours(Duration d);
-int64_t ToInt64Minutes(Duration d);
-int64_t ToInt64Seconds(Duration d);
-int64_t ToInt64Milliseconds(Duration d);
-int64_t ToInt64Microseconds(Duration d);
-int64_t ToInt64Nanoseconds(Duration d);
-
-// Relational Operators
-constexpr bool operator<(Duration lhs, Duration rhs);
-constexpr bool operator>(Duration lhs, Duration rhs);
-constexpr bool operator>=(Duration lhs, Duration rhs);
-constexpr bool operator<=(Duration lhs, Duration rhs);
-constexpr bool operator==(Duration lhs, Duration rhs);
-constexpr bool operator!=(Duration lhs, Duration rhs);
-
-// Additive Operators
-inline Time operator+(Time lhs, Duration rhs);
-inline Time operator+(Duration lhs, Time rhs);
-inline Time operator-(Time lhs, Duration rhs);
-inline Duration operator-(Time lhs, Time rhs);
-
-}  // namespace absl
+#include "absl/time/time.h"
 
 void f() {
   double x;
index 443eed3..2649d2b 100644 (file)
@@ -1,32 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-duration-factory-float %t
-
-// Mimic the implementation of absl::Duration
-namespace absl {
-
-class Duration {};
-
-Duration Nanoseconds(long long);
-Duration Microseconds(long long);
-Duration Milliseconds(long long);
-Duration Seconds(long long);
-Duration Minutes(long long);
-Duration Hours(long long);
-
-#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \
-  Duration NAME(float n);                         \
-  Duration NAME(double n);                        \
-  template <typename T>                           \
-  Duration NAME(T n);
-
-GENERATE_DURATION_FACTORY_OVERLOADS(Nanoseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Microseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Milliseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Seconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Minutes);
-GENERATE_DURATION_FACTORY_OVERLOADS(Hours);
-#undef GENERATE_DURATION_FACTORY_OVERLOADS
-
-}  // namespace absl
+// RUN: %check_clang_tidy %s abseil-duration-factory-float %t -- -- -I%S/Inputs
+
+#include "absl/time/time.h"
 
 void ConvertFloatTest() {
   absl::Duration d;
index 834d71a..dc94773 100644 (file)
@@ -1,32 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-duration-factory-scale %t
+// RUN: %check_clang_tidy %s abseil-duration-factory-scale %t -- -- -I%S/Inputs
 
-// Mimic the implementation of absl::Duration
-namespace absl {
-
-class Duration {};
-
-Duration Nanoseconds(long long);
-Duration Microseconds(long long);
-Duration Milliseconds(long long);
-Duration Seconds(long long);
-Duration Minutes(long long);
-Duration Hours(long long);
-
-#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \
-  Duration NAME(float n);                         \
-  Duration NAME(double n);                        \
-  template <typename T>                           \
-  Duration NAME(T n);
-
-GENERATE_DURATION_FACTORY_OVERLOADS(Nanoseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Microseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Milliseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Seconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Minutes);
-GENERATE_DURATION_FACTORY_OVERLOADS(Hours);
-#undef GENERATE_DURATION_FACTORY_OVERLOADS
-
-}  // namespace absl
+#include "absl/time/time.h"
 
 void ScaleTest() {
   absl::Duration d;
index 3ac113c..7d8ad43 100644 (file)
@@ -1,49 +1,8 @@
-// RUN: %check_clang_tidy %s abseil-upgrade-duration-conversions %t
+// RUN: %check_clang_tidy %s abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
 
 using int64_t = long long;
 
-// Partial implementation of relevant APIs from
-// https://github.com/abseil/abseil-cpp/blob/master/absl/time/time.h
-namespace absl {
-
-class Duration {
-public:
-  Duration &operator*=(int64_t r);
-  Duration &operator*=(float r);
-  Duration &operator*=(double r);
-  template <typename T> Duration &operator*=(T r);
-
-  Duration &operator/=(int64_t r);
-  Duration &operator/=(float r);
-  Duration &operator/=(double r);
-  template <typename T> Duration &operator/=(T r);
-};
-
-template <typename T> Duration operator*(Duration lhs, T rhs);
-template <typename T> Duration operator*(T lhs, Duration rhs);
-template <typename T> Duration operator/(Duration lhs, T rhs);
-
-constexpr Duration Nanoseconds(int64_t n);
-constexpr Duration Microseconds(int64_t n);
-constexpr Duration Milliseconds(int64_t n);
-constexpr Duration Seconds(int64_t n);
-constexpr Duration Minutes(int64_t n);
-constexpr Duration Hours(int64_t n);
-
-template <typename T> struct EnableIfFloatImpl {};
-template <> struct EnableIfFloatImpl<float> { typedef int Type; };
-template <> struct EnableIfFloatImpl<double> { typedef int Type; };
-template <> struct EnableIfFloatImpl<long double> { typedef int Type; };
-template <typename T> using EnableIfFloat = typename EnableIfFloatImpl<T>::Type;
-
-template <typename T, EnableIfFloat<T> = 0> Duration Nanoseconds(T n);
-template <typename T, EnableIfFloat<T> = 0> Duration Microseconds(T n);
-template <typename T, EnableIfFloat<T> = 0> Duration Milliseconds(T n);
-template <typename T, EnableIfFloat<T> = 0> Duration Seconds(T n);
-template <typename T, EnableIfFloat<T> = 0> Duration Minutes(T n);
-template <typename T, EnableIfFloat<T> = 0> Duration Hours(T n);
-
-} // namespace absl
+#include "absl/time/time.h"
 
 template <typename T> struct ConvertibleTo {
   operator T() const;