Skip to content

Commit

Permalink
Add gtest pretty printer for Timestamp (facebookincubator#9932)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookincubator#9932

Adding pretty printer function to make gtest equality comparison fail
with a legible error message. Before:

```
Expected equality of these values:
  Timestamp(0, 0)
    Which is: 16-byte object <00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00>
  dateTrunc("hour", Timestamp(1667725199 ,0))
    Which is: (16-byte object <80-69 67-63 00-00 00-00 00-00 00-00 00-00 00-00>)
```

After

```
Expected equality of these values:
  Timestamp(0, 0)
    Which is: sec: 0, ns: 0
  dateTrunc("hour", Timestamp(1667725199 ,0))
    Which is: (sec: 1667721600, ns: 0)
```

Reviewed By: mbasmanova

Differential Revision: D57805196

fbshipit-source-id: aef3b690155adacf9fa5bdae6003b163911a8e6c
  • Loading branch information
pedroerp authored and Joe-Abraham committed Jun 7, 2024
1 parent 9e01333 commit c4ae3fd
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions velox/type/Timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ struct Timestamp {
return obj;
}

// Pretty printer for gtest.
friend void PrintTo(const Timestamp& timestamp, std::ostream* os) {
*os << "sec: " << timestamp.seconds_ << ", ns: " << timestamp.nanos_;
}

private:
int64_t seconds_;
uint64_t nanos_;
Expand Down

0 comments on commit c4ae3fd

Please sign in to comment.