gflags: add test (#28181)

This commit is contained in:
Vinyl Darkscratch 2018-05-23 05:36:19 -07:00 committed by FX Coudert
parent e5cd976d5b
commit 7edd73b437

View file

@ -29,4 +29,34 @@ class Gflags < Formula
system "make", "install"
end
end
test do
(testpath/"test.cpp").write <<~EOS
#include <iostream>
#include "gflags/gflags.h"
DEFINE_bool(verbose, false, "Display program name before message");
DEFINE_string(message, "Hello world!", "Message to print");
static bool IsNonEmptyMessage(const char *flagname, const std::string &value)
{
return value[0] != '\0';
}
DEFINE_validator(message, &IsNonEmptyMessage);
int main(int argc, char *argv[])
{
gflags::SetUsageMessage("some usage message");
gflags::SetVersionString("1.0.0");
gflags::ParseCommandLineFlags(&argc, &argv, true);
if (FLAGS_verbose) std::cout << gflags::ProgramInvocationShortName() << ": ";
std::cout << FLAGS_message;
gflags::ShutDownCommandLineFlags();
return 0;
}
EOS
system ENV.cxx, "-L#{lib}", "-lgflags", "test.cpp", "-o", "test"
assert_match "Hello world!", shell_output("./test")
assert_match "Foo bar!", shell_output("./test --message='Foo bar!'")
end
end