Add test which uses gflags_declare.h.
authorAndreas Schuh <andreas.schuh.84@gmail.com>
Sun, 30 Mar 2014 14:16:00 +0000 (15:16 +0100)
committerAndreas Schuh <andreas.schuh.84@gmail.com>
Sun, 30 Mar 2014 14:16:00 +0000 (15:16 +0100)
Update issue 79
Added a test which uses gflags_declare.h as any other project would use it to avoid such avoidable build configuration mistakes.

test/CMakeLists.txt
test/gflags_declare_flags.cc [new file with mode: 0644]
test/gflags_declare_test.cc [new file with mode: 0644]

index 49c97ea..ff07474 100644 (file)
@@ -155,6 +155,13 @@ add_gflags_test(always_fail 1 "ERROR: failed validation of new value 'true' for
 #add_gflags_test(deadlock_if_cant_lock 0 "PASS" ""  gflags_unittest  --deadlock_if_cant_lock)
 
 # ----------------------------------------------------------------------------
+# use gflags_declare.h
+add_executable (gflags_declare_test gflags_declare_test.cc gflags_declare_flags.cc)
+
+add_test(NAME gflags_declare COMMAND gflags_declare_test --message "Hello gflags!")
+set_tests_properties(gflags_declare PROPERTIES PASS_REGULAR_EXPRESSION "Hello gflags!")
+
+# ----------------------------------------------------------------------------
 # (negative) compilation tests
 if (BUILD_NC_TESTS)
   find_package (PythonInterp)
diff --git a/test/gflags_declare_flags.cc b/test/gflags_declare_flags.cc
new file mode 100644 (file)
index 0000000..dc53de5
--- /dev/null
@@ -0,0 +1,9 @@
+#include <iostream>
+#include <gflags/gflags_declare.h>
+
+DECLARE_string(message); // in gflags_delcare_test.cc
+
+void print_message()
+{
+  std::cout << FLAGS_message << std::endl;
+}
diff --git a/test/gflags_declare_test.cc b/test/gflags_declare_test.cc
new file mode 100644 (file)
index 0000000..707bcc0
--- /dev/null
@@ -0,0 +1,12 @@
+#include <gflags/gflags.h>
+
+DEFINE_string(message, "", "The message to print");
+void print_message(); // in gflags_declare_flags.cc
+
+int main(int argc, char **argv)
+{
+  gflags::SetUsageMessage("Test compilation and use of gflags_declare.h");
+  gflags::ParseCommandLineFlags(&argc, &argv, true);
+  print_message();
+  return 0;
+}