1ee5fa1f2SLuke Ireland #ifndef FORTRAN_EVALUATE_TESTING_H_ 2ee5fa1f2SLuke Ireland #define FORTRAN_EVALUATE_TESTING_H_ 3ee5fa1f2SLuke Ireland 4ee5fa1f2SLuke Ireland #include <cinttypes> 5ee5fa1f2SLuke Ireland #include <string> 6ee5fa1f2SLuke Ireland 7ee5fa1f2SLuke Ireland namespace testing { 8ee5fa1f2SLuke Ireland 9ee5fa1f2SLuke Ireland // Returns EXIT_SUCCESS or EXIT_FAILURE, so a test's main() should end 10ee5fa1f2SLuke Ireland // with "return testing::Complete()". 11ee5fa1f2SLuke Ireland int Complete(); 12ee5fa1f2SLuke Ireland 13ee5fa1f2SLuke Ireland // Pass/fail testing. These macros return a pointer to a printf-like 14ee5fa1f2SLuke Ireland // function that can be optionally called to print more detail, e.g. 15ee5fa1f2SLuke Ireland // COMPARE(x, ==, y)("z is 0x%llx", z); 16ee5fa1f2SLuke Ireland // will also print z after the usual failure message if x != y. 17ee5fa1f2SLuke Ireland #define TEST(predicate) \ 18ee5fa1f2SLuke Ireland testing::Test(__FILE__, __LINE__, #predicate, (predicate)) 19ee5fa1f2SLuke Ireland #define MATCH(want, got) testing::Match(__FILE__, __LINE__, (want), #got, (got)) 20ee5fa1f2SLuke Ireland #define COMPARE(x, rel, y) \ 21ee5fa1f2SLuke Ireland testing::Compare(__FILE__, __LINE__, #x, #rel, #y, (x), (y)) 22ee5fa1f2SLuke Ireland 23ee5fa1f2SLuke Ireland // Functions called by these macros; do not call directly. 24ee5fa1f2SLuke Ireland using FailureDetailPrinter = void (*)(const char *, ...); 25ee5fa1f2SLuke Ireland FailureDetailPrinter Test( 26ee5fa1f2SLuke Ireland const char *file, int line, const char *predicate, bool pass); 27ee5fa1f2SLuke Ireland FailureDetailPrinter Match(const char *file, int line, std::uint64_t want, 28ee5fa1f2SLuke Ireland const char *gots, std::uint64_t got); 29ee5fa1f2SLuke Ireland FailureDetailPrinter Match(const char *file, int line, const char *want, 30ee5fa1f2SLuke Ireland const char *gots, const std::string &got); 31ee5fa1f2SLuke Ireland FailureDetailPrinter Match(const char *file, int line, const std::string &want, 32ee5fa1f2SLuke Ireland const char *gots, const std::string &got); 33ee5fa1f2SLuke Ireland FailureDetailPrinter Compare(const char *file, int line, const char *xs, 34ee5fa1f2SLuke Ireland const char *rel, const char *ys, std::uint64_t x, std::uint64_t y); 35*1f879005STim Keith } // namespace testing 36ee5fa1f2SLuke Ireland #endif // FORTRAN_EVALUATE_TESTING_H_ 37