Skip to content

Commit

Permalink
Override << operator for better test error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ackerleytng committed Jul 7, 2020
1 parent 286dfea commit aa36997
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions jwt_verify_lib/status.h
Expand Up @@ -209,6 +209,14 @@ enum class Status {
JwksBioAllocError,
};

/**
* Overload << to output a Status to std::ostream
* @param os the std::ostream to write to
* @param status is the enum status.
* @return the std::ostream os
*/
std::ostream& operator<<(std::ostream& os, const Status& status);

/**
* Convert enum status to string.
* @param status is the enum status.
Expand Down
8 changes: 8 additions & 0 deletions src/status.cc
Expand Up @@ -15,6 +15,7 @@
#include "jwt_verify_lib/status.h"

#include <map>
#include <iostream>

namespace google {
namespace jwt_verify {
Expand Down Expand Up @@ -173,5 +174,12 @@ std::string getStatusString(Status status) {
return "";
}

std::ostream& operator<<(std::ostream& os, const Status& status) {
return os <<
"Status(" <<
static_cast<int>(status) << ", " <<
getStatusString(status) << ")";
}

} // namespace jwt_verify
} // namespace google

0 comments on commit aa36997

Please sign in to comment.