summaryrefslogtreecommitdiff
path: root/src/gflags_unittest.sh
diff options
context:
space:
mode:
authorCraig Silverstein <csilvers+gflags@google.com>2011-07-29 04:26:49 +0000
committerCraig Silverstein <csilvers+gflags@google.com>2011-07-29 04:26:49 +0000
commit917f4e7bf3c36b4c56a77faca639758d3aca2a92 (patch)
tree65ee3102df263ae4da6d6fd57ac0326775a11b4c /src/gflags_unittest.sh
parentb7ea0659625be5cf8c9c3954ea2fe28f39300f81 (diff)
downloadgflags-917f4e7bf3c36b4c56a77faca639758d3aca2a92.tar.gz
gflags-917f4e7bf3c36b4c56a77faca639758d3aca2a92.tar.bz2
gflags-917f4e7bf3c36b4c56a77faca639758d3aca2a92.zip
Some reorganization that results from a new method I'm moving to to
maintaining this opensource tree. Some of this reorganization is entirely a result of reorganization: blank lines in a few different places, etc. Here are the others: 1) I've added a new file, util.h, with lots of new, helpful routines, most notably StringPrintf (printf returning a string). I've also moved some routines from the .cc and unittest.cc file here, such as the CHECK macros, testing framework, and #ifdefs for 16-bit ints. Quite a bit of code was rewritten to use these new routines. 2) I noticed that the special-case setenv() code was only needed for windows systems, so I moved it to port.h/cc. 3) I also had to add a new vsnprintf wrapper in port.h/cc, to support StringPrintf. 4) A few places I used an old name, commandlineflags, instead of gflags. Most or all of these should be fixed now. 5) Some of my copyright dates weren't quite right. Fixed them up. 6) In some .cc files, I added using directives to not have to use std:: so much. 7) I've added a minor new test, adding 10000 or so flags to see how the system scales. 8) Some compile-warning fixes, such as int -> size_t when appropriate, and better protected #defines in mutex.h 9) The .h files gained some logic defining GFLAGS_DLL_DECL. This is true even for .h files outside the windows directory, which will never have these dll issues. But one big advantage of my new organization is auto-generating the windows versions of these files from the unix versions, so there's some unnecessary (but harmless) duplication as a result. 10) Fixed a bug in rpm.sh which would cause an unnecessary crash when dpkg was missing. git-svn-id: https://gflags.googlecode.com/svn/trunk@52 6586e3c6-dcc4-952a-343f-ff74eb82781d
Diffstat (limited to 'src/gflags_unittest.sh')
-rwxr-xr-xsrc/gflags_unittest.sh65
1 files changed, 34 insertions, 31 deletions
diff --git a/src/gflags_unittest.sh b/src/gflags_unittest.sh
index 20c84a0..39b03c5 100755
--- a/src/gflags_unittest.sh
+++ b/src/gflags_unittest.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# Copyright (c) 2006, Google Inc.
# All rights reserved.
@@ -32,21 +32,17 @@
# ---
# Author: Craig Silverstein
#
-# Just tries to run gflags_unittest with various flags defined in
-# gflags.cc, and make sure they give the appropriate exit
-# status and appropriate error message.
-
-if [ -z "$1" ]
-then
- echo "USAGE: $0 <unittest exe> [top_srcdir] [tmpdir]"
- exit 1
-fi
-
+# Just tries to run the gflags_unittest with various flags
+# defined in gflags.cc, and make sure they give the
+# appropriate exit status and appropriate error message.
+
+if [ -z "$1" ]; then
+ echo "USAGE: $0 <unittest exe> [top_srcdir] [tmpdir]"
+ exit 1
+fi
EXE="$1"
SRCDIR="${2:-./}"
TMPDIR="${3:-/tmp/gflags}"
-
-# Executables built with the main source file suffixed with "-main" and "_main".
EXE2="${EXE}2" # eg, gflags_unittest2
EXE3="${EXE}3" # eg, gflags_unittest3
@@ -65,8 +61,9 @@ ExpectExe() {
local unexpected_output="$1"
shift
- # We always add --srcdir=$SRCDIR because it's needed for correctness
- "$executable" --srcdir="$SRCDIR" "$@" > "$TMPDIR/test.$line_number" 2>&1
+ # We always add --srcdir because it's needed for correctness
+ "$executable" --srcdir="$SRCDIR" "$@" > "$TMPDIR/test.$line_number" 2>&1
+
local actual_rc=$?
if [ $actual_rc != $expected_rc ]; then
echo "Test on line $line_number failed:" \
@@ -111,7 +108,7 @@ export FLAGS_help=false
# First, just make sure the unittest works as-is
Expect $LINENO 0 "PASS" ""
-# --help should show all flags, including flags from gflags_reporting.cc
+# --help should show all flags, including flags from gflags_reporting
Expect $LINENO 1 "/gflags_reporting.cc" "" --help
# Make sure --help reflects flag changes made before flag-parsing
@@ -133,17 +130,18 @@ Expect $LINENO 0 "PASS" "" --help=false
Expect $LINENO 1 "/gflags_reporting.cc" "" -helpfull
# --helpshort should show only flags from the unittest itself
-Expect $LINENO 1 "/gflags_unittest.cc" "/gflags_reporting.cc" --helpshort
+Expect $LINENO 1 "/gflags_unittest.cc" \
+ "/gflags_reporting.cc" --helpshort
# --helpshort should show the tldflag we created in the unittest dir
Expect $LINENO 1 "tldflag1" "/google.cc" --helpshort
Expect $LINENO 1 "tldflag2" "/google.cc" --helpshort
# --helpshort should work if the main source file is suffixed with [_-]main
-ExpectExe "$EXE2" $LINENO 1 "/gflags_unittest-main.cc" "/gflags_reporting.cc" \
- --helpshort
-ExpectExe "$EXE3" $LINENO 1 "/gflags_unittest_main.cc" "/gflags_reporting.cc" \
- --helpshort
+ExpectExe "$EXE2" $LINENO 1 "/gflags_unittest-main.cc" \
+ "/gflags_reporting.cc" --helpshort
+ExpectExe "$EXE3" $LINENO 1 "/gflags_unittest_main.cc" \
+ "/gflags_reporting.cc" --helpshort
# --helpon needs an argument
Expect $LINENO 1 \
@@ -151,20 +149,22 @@ Expect $LINENO 1 \
"" --helpon
# --helpon argument indicates what file we'll show args from
-Expect $LINENO 1 "/gflags.cc" "/gflags_unittest.cc" --helpon=gflags
+Expect $LINENO 1 "/gflags.cc" "/gflags_unittest.cc" \
+ --helpon=gflags
# another way of specifying the argument
-Expect $LINENO 1 "/gflags.cc" "/gflags_unittest.cc" --helpon gflags
+Expect $LINENO 1 "/gflags.cc" "/gflags_unittest.cc" \
+ --helpon gflags
# test another argument
Expect $LINENO 1 "/gflags_unittest.cc" "/gflags.cc" \
- --helpon gflags_unittest
+ --helpon=gflags_unittest
# helpmatch is like helpon but takes substrings
-Expect $LINENO 1 "/gflags_reporting.cc" "/gflags_unittest.cc" \
- -helpmatch reporting
-Expect $LINENO 1 "/gflags_unittest.cc" "/gflags.cc" \
- -helpmatch=unittest
+Expect $LINENO 1 "/gflags_reporting.cc" \
+ "/gflags_unittest.cc" -helpmatch reporting
+Expect $LINENO 1 "/gflags_unittest.cc" \
+ "/gflags.cc" -helpmatch=unittest
# if no flags are found with helpmatch or helpon, suggest --help
Expect $LINENO 1 "No modules matched" "/gflags_unittest.cc" \
@@ -202,8 +202,10 @@ Expect $LINENO 0 "PASS" "" --flagfile="$TMPDIR/flagfile.2"
Expect $LINENO 0 "PASS" "" --flagfile="$TMPDIR/flagfile.3"
# Also try to load flags from the environment
-Expect $LINENO 0 "gflags_unittest" "gflags_unittest.cc" --fromenv=version
-Expect $LINENO 0 "gflags_unittest" "gflags_unittest.cc" --tryfromenv=version
+Expect $LINENO 0 "gflags_unittest" "gflags_unittest.cc" \
+ --fromenv=version
+Expect $LINENO 0 "gflags_unittest" "gflags_unittest.cc" \
+ --tryfromenv=version
Expect $LINENO 0 "PASS" "" --fromenv=help
Expect $LINENO 0 "PASS" "" --tryfromenv=help
Expect $LINENO 1 "helpfull not found in environment" "" --fromenv=helpfull
@@ -221,10 +223,11 @@ Expect $LINENO 0 "gflags_unittest" "gflags_unittest.cc" \
# Make sure -- by itself stops argv processing
Expect $LINENO 0 "PASS" "" -- --help
+
# And we should die if the flag value doesn't pass the validator
Expect $LINENO 1 "ERROR: failed validation of new value 'true' for flag 'always_fail'" "" --always_fail
-# TODO(wojtekm) And if locking in validators fails.
+# TODO(user) And if locking in validators fails.
# Expect $LINENO 0 "PASS" "" --deadlock_if_cant_lock
echo "PASS"