Improves documentation on gtest's macros.
Adds script to automate releasing new version of wiki docs.
This commit is contained in:
parent
4f7018ed61
commit
d3eb97f321
|
@ -30,8 +30,11 @@
|
|||
// Authors: wan@google.com (Zhanyong Wan)
|
||||
//
|
||||
// Low-level types and utilities for porting Google Test to various
|
||||
// platforms. They are subject to change without notice. DO NOT USE
|
||||
// THEM IN USER CODE.
|
||||
// platforms. All macros ending with _ and symbols defined in an
|
||||
// internal namespace are subject to change without notice. Code
|
||||
// outside Google Test MUST NOT USE THEM DIRECTLY. Macros that don't
|
||||
// end with _ are part of Google Test's public API and can be used by
|
||||
// code outside Google Test.
|
||||
//
|
||||
// This file is fundamental to Google Test. All other Google Test source
|
||||
// files are expected to #include this. Therefore, it cannot #include
|
||||
|
@ -40,9 +43,30 @@
|
|||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
|
||||
|
||||
// The user can define the following macros in the build script to
|
||||
// control Google Test's behavior. If the user doesn't define a macro
|
||||
// in this list, Google Test will define it.
|
||||
// Environment-describing macros
|
||||
// -----------------------------
|
||||
//
|
||||
// Google Test can be used in many different environments. Macros in
|
||||
// this section tell Google Test what kind of environment it is being
|
||||
// used in, such that Google Test can provide environment-specific
|
||||
// features and implementations.
|
||||
//
|
||||
// Google Test tries to automatically detect the properties of its
|
||||
// environment, so users usually don't need to worry about these
|
||||
// macros. However, the automatic detection is not perfect.
|
||||
// Sometimes it's necessary for a user to define some of the following
|
||||
// macros in the build script to override Google Test's decisions.
|
||||
//
|
||||
// If the user doesn't define a macro in the list, Google Test will
|
||||
// provide a default definition. After this header is #included, all
|
||||
// macros in this list will be defined to either 1 or 0.
|
||||
//
|
||||
// Notes to maintainers:
|
||||
// - Each macro here is a user-tweakable knob; do not grow the list
|
||||
// lightly.
|
||||
// - Use #if to key off these macros. Don't use #ifdef or "#if
|
||||
// defined(...)", which will not work as these macros are ALWAYS
|
||||
// defined.
|
||||
//
|
||||
// GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2)
|
||||
// is/isn't available.
|
||||
|
@ -86,10 +110,15 @@
|
|||
// - Define to 1 when compiling Google Test itself
|
||||
// as a shared library.
|
||||
|
||||
// This header defines the following utilities:
|
||||
// Platform-indicating macros
|
||||
// --------------------------
|
||||
//
|
||||
// Macros indicating the platform on which Google Test is being used
|
||||
// (a macro is defined to 1 if compiled on the given platform;
|
||||
// otherwise UNDEFINED -- it's never defined to 0.). Google Test
|
||||
// defines these macros automatically. Code outside Google Test MUST
|
||||
// NOT define them.
|
||||
//
|
||||
// Macros indicating the current platform (defined to 1 if compiled on
|
||||
// the given platform; otherwise undefined):
|
||||
// GTEST_OS_AIX - IBM AIX
|
||||
// GTEST_OS_CYGWIN - Cygwin
|
||||
// GTEST_OS_HPUX - HP-UX
|
||||
|
@ -116,22 +145,50 @@
|
|||
// googletestframework@googlegroups.com (patches for fixing them are
|
||||
// even more welcome!).
|
||||
//
|
||||
// Note that it is possible that none of the GTEST_OS_* macros are defined.
|
||||
// It is possible that none of the GTEST_OS_* macros are defined.
|
||||
|
||||
// Feature-indicating macros
|
||||
// -------------------------
|
||||
//
|
||||
// Macros indicating which Google Test features are available (a macro
|
||||
// is defined to 1 if the corresponding feature is supported;
|
||||
// otherwise UNDEFINED -- it's never defined to 0.). Google Test
|
||||
// defines these macros automatically. Code outside Google Test MUST
|
||||
// NOT define them.
|
||||
//
|
||||
// These macros are public so that portable tests can be written.
|
||||
// Such tests typically surround code using a feature with an #if
|
||||
// which controls that code. For example:
|
||||
//
|
||||
// #if GTEST_HAS_DEATH_TEST
|
||||
// EXPECT_DEATH(DoSomethingDeadly());
|
||||
// #endif
|
||||
//
|
||||
// Macros indicating available Google Test features (defined to 1 if
|
||||
// the corresponding feature is supported; otherwise undefined):
|
||||
// GTEST_HAS_COMBINE - the Combine() function (for value-parameterized
|
||||
// tests)
|
||||
// GTEST_HAS_DEATH_TEST - death tests
|
||||
// GTEST_HAS_PARAM_TEST - value-parameterized tests
|
||||
// GTEST_HAS_TYPED_TEST - typed tests
|
||||
// GTEST_HAS_TYPED_TEST_P - type-parameterized tests
|
||||
// GTEST_IS_THREADSAFE - Google Test is thread-safe.
|
||||
// GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse with
|
||||
// GTEST_HAS_POSIX_RE (see above) which users can
|
||||
// define themselves.
|
||||
// GTEST_USES_SIMPLE_RE - our own simple regex is used;
|
||||
// the above two are mutually exclusive.
|
||||
// GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
|
||||
|
||||
// Misc public macros
|
||||
// ------------------
|
||||
//
|
||||
// GTEST_FLAG(flag_name) - references the variable corresponding to
|
||||
// the given Google Test flag.
|
||||
|
||||
// Internal utilities
|
||||
// ------------------
|
||||
//
|
||||
// The following macros and utilities are for Google Test's INTERNAL
|
||||
// use only. Code outside Google Test MUST NOT USE THEM DIRECTLY.
|
||||
//
|
||||
// Macros for basic C++ coding:
|
||||
// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
|
||||
|
@ -143,10 +200,7 @@
|
|||
//
|
||||
// Synchronization:
|
||||
// Mutex, MutexLock, ThreadLocal, GetThreadCount()
|
||||
// - synchronization primitives.
|
||||
// GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
|
||||
// synchronization primitives have real implementations
|
||||
// and Google Test is thread-safe; or 0 otherwise.
|
||||
// - synchronization primitives.
|
||||
//
|
||||
// Template meta programming:
|
||||
// is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only.
|
||||
|
@ -182,7 +236,6 @@
|
|||
// BiggestInt - the biggest signed integer type.
|
||||
//
|
||||
// Command-line utilities:
|
||||
// GTEST_FLAG() - references a flag.
|
||||
// GTEST_DECLARE_*() - declares a flag.
|
||||
// GTEST_DEFINE_*() - defines a flag.
|
||||
// GetInjectableArgvs() - returns the command line as a vector of strings.
|
||||
|
|
83
scripts/common.py
Normal file
83
scripts/common.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
# Copyright 2013 Google Inc. All Rights Reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""Shared utilities for writing scripts for Google Test/Mock."""
|
||||
|
||||
__author__ = 'wan@google.com (Zhanyong Wan)'
|
||||
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
# Matches the line from 'svn info .' output that describes what SVN
|
||||
# path the current local directory corresponds to. For example, in
|
||||
# a googletest SVN workspace's trunk/test directory, the output will be:
|
||||
#
|
||||
# URL: https://googletest.googlecode.com/svn/trunk/test
|
||||
_SVN_INFO_URL_RE = re.compile(r'^URL: https://(\w+)\.googlecode\.com/svn(.*)')
|
||||
|
||||
|
||||
def GetCommandOutput(command):
|
||||
"""Runs the shell command and returns its stdout as a list of lines."""
|
||||
|
||||
f = os.popen(command, 'r')
|
||||
lines = [line.strip() for line in f.readlines()]
|
||||
f.close()
|
||||
return lines
|
||||
|
||||
|
||||
def GetSvnInfo():
|
||||
"""Returns the project name and the current SVN workspace's root path."""
|
||||
|
||||
for line in GetCommandOutput('svn info .'):
|
||||
m = _SVN_INFO_URL_RE.match(line)
|
||||
if m:
|
||||
project = m.group(1) # googletest or googlemock
|
||||
rel_path = m.group(2)
|
||||
root = os.path.realpath(rel_path.count('/') * '../')
|
||||
return project, root
|
||||
|
||||
return None, None
|
||||
|
||||
|
||||
def GetSvnTrunk():
|
||||
"""Returns the current SVN workspace's trunk root path."""
|
||||
|
||||
_, root = GetSvnInfo()
|
||||
return root + '/trunk' if root else None
|
||||
|
||||
|
||||
def IsInGTestSvn():
|
||||
project, _ = GetSvnInfo()
|
||||
return project == 'googletest'
|
||||
|
||||
|
||||
def IsInGMockSvn():
|
||||
project, _ = GetSvnInfo()
|
||||
return project == 'googlemock'
|
158
scripts/release_docs.py
Executable file
158
scripts/release_docs.py
Executable file
|
@ -0,0 +1,158 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2013 Google Inc. All Rights Reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""Script for branching Google Test/Mock wiki pages for a new version.
|
||||
|
||||
SYNOPSIS
|
||||
release_docs.py NEW_RELEASE_VERSION
|
||||
|
||||
Google Test and Google Mock's external user documentation is in
|
||||
interlinked wiki files. When we release a new version of
|
||||
Google Test or Google Mock, we need to branch the wiki files
|
||||
such that users of a specific version of Google Test/Mock can
|
||||
look up documenation relevant for that version. This script
|
||||
automates that process by:
|
||||
|
||||
- branching the current wiki pages (which document the
|
||||
behavior of the SVN trunk head) to pages for the specified
|
||||
version (e.g. branching FAQ.wiki to V2_6_FAQ.wiki when
|
||||
NEW_RELEASE_VERSION is 2.6);
|
||||
- updating the links in the branched files to point to the branched
|
||||
version (e.g. a link in V2_6_FAQ.wiki that pointed to
|
||||
Primer.wiki#Anchor will now point to V2_6_Primer.wiki#Anchor).
|
||||
|
||||
NOTE: NEW_RELEASE_VERSION must be a NEW version number for
|
||||
which the wiki pages don't yet exist; otherwise you'll get SVN
|
||||
errors like "svn: Path 'V1_7_PumpManual.wiki' is not a
|
||||
directory" when running the script.
|
||||
|
||||
EXAMPLE
|
||||
$ cd PATH/TO/GTEST_SVN_WORKSPACE/trunk
|
||||
$ scripts/release_docs.py 2.6 # create wiki pages for v2.6
|
||||
$ svn status # verify the file list
|
||||
$ svn diff # verify the file contents
|
||||
$ svn commit -m "release wiki pages for v2.6"
|
||||
"""
|
||||
|
||||
__author__ = 'wan@google.com (Zhanyong Wan)'
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
import common
|
||||
|
||||
|
||||
# Wiki pages that shouldn't be branched for every gtest/gmock release.
|
||||
GTEST_UNVERSIONED_WIKIS = ['DevGuide.wiki']
|
||||
GMOCK_UNVERSIONED_WIKIS = [
|
||||
'DesignDoc.wiki',
|
||||
'DevGuide.wiki',
|
||||
'KnownIssues.wiki'
|
||||
]
|
||||
|
||||
|
||||
def DropWikiSuffix(wiki_filename):
|
||||
"""Removes the .wiki suffix (if any) from the given filename."""
|
||||
|
||||
return (wiki_filename[:-len('.wiki')] if wiki_filename.endswith('.wiki')
|
||||
else wiki_filename)
|
||||
|
||||
|
||||
class WikiBrancher(object):
|
||||
"""Branches ..."""
|
||||
|
||||
def __init__(self, dot_version):
|
||||
self.project, svn_root_path = common.GetSvnInfo()
|
||||
if self.project not in ('googletest', 'googlemock'):
|
||||
sys.exit('This script must be run in a gtest or gmock SVN workspace.')
|
||||
self.wiki_dir = svn_root_path + '/wiki'
|
||||
# Turn '2.6' to 'V2_6_'.
|
||||
self.version_prefix = 'V' + dot_version.replace('.', '_') + '_'
|
||||
self.files_to_branch = self.GetFilesToBranch()
|
||||
page_names = [DropWikiSuffix(f) for f in self.files_to_branch]
|
||||
# A link to Foo.wiki is in one of the following forms:
|
||||
# [Foo words]
|
||||
# [Foo#Anchor words]
|
||||
# [http://code.google.com/.../wiki/Foo words]
|
||||
# [http://code.google.com/.../wiki/Foo#Anchor words]
|
||||
# We want to replace 'Foo' with 'V2_6_Foo' in the above cases.
|
||||
self.search_for_re = re.compile(
|
||||
# This regex matches either
|
||||
# [Foo
|
||||
# or
|
||||
# /wiki/Foo
|
||||
# followed by a space or a #, where Foo is the name of an
|
||||
# unversioned wiki page.
|
||||
r'(\[|/wiki/)(%s)([ #])' % '|'.join(page_names))
|
||||
self.replace_with = r'\1%s\2\3' % (self.version_prefix,)
|
||||
|
||||
def GetFilesToBranch(self):
|
||||
"""Returns a list of .wiki file names that need to be branched."""
|
||||
|
||||
unversioned_wikis = (GTEST_UNVERSIONED_WIKIS if self.project == 'googletest'
|
||||
else GMOCK_UNVERSIONED_WIKIS)
|
||||
return [f for f in os.listdir(self.wiki_dir)
|
||||
if (f.endswith('.wiki') and
|
||||
not re.match(r'^V\d', f) and # Excluded versioned .wiki files.
|
||||
f not in unversioned_wikis)]
|
||||
|
||||
def BranchFiles(self):
|
||||
"""Branches the .wiki files needed to be branched."""
|
||||
|
||||
print 'Branching %d .wiki files:' % (len(self.files_to_branch),)
|
||||
os.chdir(self.wiki_dir)
|
||||
for f in self.files_to_branch:
|
||||
command = 'svn cp %s %s%s' % (f, self.version_prefix, f)
|
||||
print command
|
||||
os.system(command)
|
||||
|
||||
def UpdateLinksInBranchedFiles(self):
|
||||
|
||||
for f in self.files_to_branch:
|
||||
source_file = os.path.join(self.wiki_dir, f)
|
||||
versioned_file = os.path.join(self.wiki_dir, self.version_prefix + f)
|
||||
print 'Updating links in %s.' % (versioned_file,)
|
||||
text = file(source_file, 'r').read()
|
||||
new_text = self.search_for_re.sub(self.replace_with, text)
|
||||
file(versioned_file, 'w').write(new_text)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
sys.exit(__doc__)
|
||||
|
||||
brancher = WikiBrancher(sys.argv[1])
|
||||
brancher.BranchFiles()
|
||||
brancher.UpdateLinksInBranchedFiles()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user