1- // RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-comparison %t -- -- -I%S/Inputs
1+ // RUN: %check_clang_tidy %s abseil-duration-comparison %t -- -- -I%S/Inputs
22
33#include " absl/time/time.h"
44
@@ -11,104 +11,104 @@ void f() {
1111 // Check against the RHS
1212 b = x > absl::ToDoubleSeconds (d1);
1313 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
14- // CHECK-FIXES: absl::Seconds(x) > d1;
14+ // CHECK-FIXES: b = absl::Seconds(x) > d1;
1515 b = x >= absl::ToDoubleSeconds (d1);
1616 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
17- // CHECK-FIXES: absl::Seconds(x) >= d1;
17+ // CHECK-FIXES: b = absl::Seconds(x) >= d1;
1818 b = x == absl::ToDoubleSeconds (d1);
1919 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
20- // CHECK-FIXES: absl::Seconds(x) == d1;
20+ // CHECK-FIXES: b = absl::Seconds(x) == d1;
2121 b = x <= absl::ToDoubleSeconds (d1);
2222 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
23- // CHECK-FIXES: absl::Seconds(x) <= d1;
23+ // CHECK-FIXES: b = absl::Seconds(x) <= d1;
2424 b = x < absl::ToDoubleSeconds (d1);
2525 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
26- // CHECK-FIXES: absl::Seconds(x) < d1;
26+ // CHECK-FIXES: b = absl::Seconds(x) < d1;
2727 b = x == absl::ToDoubleSeconds (t1 - t2);
2828 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
29- // CHECK-FIXES: absl::Seconds(x) == t1 - t2;
29+ // CHECK-FIXES: b = absl::Seconds(x) == t1 - t2;
3030 b = absl::ToDoubleSeconds (d1) > absl::ToDoubleSeconds (d2);
3131 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
32- // CHECK-FIXES: d1 > d2;
32+ // CHECK-FIXES: b = d1 > d2;
3333
3434 // Check against the LHS
3535 b = absl::ToDoubleSeconds (d1) < x;
3636 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
37- // CHECK-FIXES: d1 < absl::Seconds(x);
37+ // CHECK-FIXES: b = d1 < absl::Seconds(x);
3838 b = absl::ToDoubleSeconds (d1) <= x;
3939 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
40- // CHECK-FIXES: d1 <= absl::Seconds(x);
40+ // CHECK-FIXES: b = d1 <= absl::Seconds(x);
4141 b = absl::ToDoubleSeconds (d1) == x;
4242 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
43- // CHECK-FIXES: d1 == absl::Seconds(x);
43+ // CHECK-FIXES: b = d1 == absl::Seconds(x);
4444 b = absl::ToDoubleSeconds (d1) >= x;
4545 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
46- // CHECK-FIXES: d1 >= absl::Seconds(x);
46+ // CHECK-FIXES: b = d1 >= absl::Seconds(x);
4747 b = absl::ToDoubleSeconds (d1) > x;
4848 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
49- // CHECK-FIXES: d1 > absl::Seconds(x);
49+ // CHECK-FIXES: b = d1 > absl::Seconds(x);
5050
5151 // Comparison against zero
5252 b = absl::ToDoubleSeconds (d1) < 0.0 ;
5353 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
54- // CHECK-FIXES: d1 < absl::ZeroDuration();
54+ // CHECK-FIXES: b = d1 < absl::ZeroDuration();
5555 b = absl::ToDoubleSeconds (d1) < 0 ;
5656 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
57- // CHECK-FIXES: d1 < absl::ZeroDuration();
57+ // CHECK-FIXES: b = d1 < absl::ZeroDuration();
5858
5959 // Scales other than Seconds
6060 b = x > absl::ToDoubleMicroseconds (d1);
6161 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
62- // CHECK-FIXES: absl::Microseconds(x) > d1;
62+ // CHECK-FIXES: b = absl::Microseconds(x) > d1;
6363 b = x >= absl::ToDoubleMilliseconds (d1);
6464 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
65- // CHECK-FIXES: absl::Milliseconds(x) >= d1;
65+ // CHECK-FIXES: b = absl::Milliseconds(x) >= d1;
6666 b = x == absl::ToDoubleNanoseconds (d1);
6767 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
68- // CHECK-FIXES: absl::Nanoseconds(x) == d1;
68+ // CHECK-FIXES: b = absl::Nanoseconds(x) == d1;
6969 b = x <= absl::ToDoubleMinutes (d1);
7070 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
71- // CHECK-FIXES: absl::Minutes(x) <= d1;
71+ // CHECK-FIXES: b = absl::Minutes(x) <= d1;
7272 b = x < absl::ToDoubleHours (d1);
7373 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
74- // CHECK-FIXES: absl::Hours(x) < d1;
74+ // CHECK-FIXES: b = absl::Hours(x) < d1;
7575
7676 // Integer comparisons
7777 b = x > absl::ToInt64Microseconds (d1);
7878 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
79- // CHECK-FIXES: absl::Microseconds(x) > d1;
79+ // CHECK-FIXES: b = absl::Microseconds(x) > d1;
8080 b = x >= absl::ToInt64Milliseconds (d1);
8181 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
82- // CHECK-FIXES: absl::Milliseconds(x) >= d1;
82+ // CHECK-FIXES: b = absl::Milliseconds(x) >= d1;
8383 b = x == absl::ToInt64Nanoseconds (d1);
8484 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
85- // CHECK-FIXES: absl::Nanoseconds(x) == d1;
85+ // CHECK-FIXES: b = absl::Nanoseconds(x) == d1;
8686 b = x == absl::ToInt64Seconds (d1);
8787 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
88- // CHECK-FIXES: absl::Seconds(x) == d1;
88+ // CHECK-FIXES: b = absl::Seconds(x) == d1;
8989 b = x <= absl::ToInt64Minutes (d1);
9090 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
91- // CHECK-FIXES: absl::Minutes(x) <= d1;
91+ // CHECK-FIXES: b = absl::Minutes(x) <= d1;
9292 b = x < absl::ToInt64Hours (d1);
9393 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
94- // CHECK-FIXES: absl::Hours(x) < d1;
94+ // CHECK-FIXES: b = absl::Hours(x) < d1;
9595
9696 // Other abseil-duration checks folded into this one
9797 b = static_cast <double >(5 ) > absl::ToDoubleSeconds (d1);
9898 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
99- // CHECK-FIXES: absl::Seconds(5) > d1;
99+ // CHECK-FIXES: b = absl::Seconds(5) > d1;
100100 b = double (5 ) > absl::ToDoubleSeconds (d1);
101101 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
102- // CHECK-FIXES: absl::Seconds(5) > d1;
102+ // CHECK-FIXES: b = absl::Seconds(5) > d1;
103103 b = float (5 ) > absl::ToDoubleSeconds (d1);
104104 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
105- // CHECK-FIXES: absl::Seconds(5) > d1;
105+ // CHECK-FIXES: b = absl::Seconds(5) > d1;
106106 b = ((double )5 ) > absl::ToDoubleSeconds (d1);
107107 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
108- // CHECK-FIXES: absl::Seconds(5) > d1;
108+ // CHECK-FIXES: b = absl::Seconds(5) > d1;
109109 b = 5.0 > absl::ToDoubleSeconds (d1);
110110 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
111- // CHECK-FIXES: absl::Seconds(5) > d1;
111+ // CHECK-FIXES: b = absl::Seconds(5) > d1;
112112
113113 // A long expression
114114 bool some_condition;
@@ -125,20 +125,20 @@ void f() {
125125 int y;
126126 b = (y + 5 ) * 10 > absl::ToDoubleMilliseconds (d1);
127127 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison]
128- // CHECK-FIXES: absl::Milliseconds((y + 5) * 10) > d1;
128+ // CHECK-FIXES: b = absl::Milliseconds((y + 5) * 10) > d1;
129129
130130 // We should still transform the expression inside this macro invocation
131131#define VALUE_IF (v, e ) v ? (e) : 0
132132 int a = VALUE_IF (1 , 5 > absl::ToDoubleSeconds (d1));
133133 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: perform comparison in the duration domain [abseil-duration-comparison]
134- // CHECK-FIXES: VALUE_IF(1, absl::Seconds(5) > d1);
134+ // CHECK-FIXES: int a = VALUE_IF(1, absl::Seconds(5) > d1);
135135#undef VALUE_IF
136136
137137#define VALUE_IF_2 (e ) (e)
138138#define VALUE_IF (v, e ) v ? VALUE_IF_2(e) : VALUE_IF_2(0 )
139139 int a2 = VALUE_IF (1 , 5 > absl::ToDoubleSeconds (d1));
140140 // CHECK-MESSAGES: [[@LINE-1]]:24: warning: perform comparison in the duration domain [abseil-duration-comparison]
141- // CHECK-FIXES: VALUE_IF(1, absl::Seconds(5) > d1);
141+ // CHECK-FIXES: int a2 = VALUE_IF(1, absl::Seconds(5) > d1);
142142#undef VALUE_IF
143143#undef VALUE_IF_2
144144
0 commit comments