summaryrefslogtreecommitdiffstats
path: root/contrib/atf/atf-c++
diff options
context:
space:
mode:
authorjmmv <jmmv@FreeBSD.org>2014-11-01 11:17:54 +0000
committerjmmv <jmmv@FreeBSD.org>2014-11-01 11:17:54 +0000
commit120021745eb3a1c1b24fdc54769f808151deb621 (patch)
tree7e1f2a559f61d17aad44cfb95b6fefcaa593c4af /contrib/atf/atf-c++
parent595e4e5bc797fd4a63eb344ae9df352db666a94d (diff)
parent3b6cf63a5c1f2de80b3b7fdd30eab1717f5c9407 (diff)
downloadFreeBSD-src-120021745eb3a1c1b24fdc54769f808151deb621.zip
FreeBSD-src-120021745eb3a1c1b24fdc54769f808151deb621.tar.gz
MFV: Import atf-0.21.
Diffstat (limited to 'contrib/atf/atf-c++')
-rw-r--r--contrib/atf/atf-c++/Kyuafile1
-rw-r--r--contrib/atf/atf-c++/atf-c++.3649
-rw-r--r--contrib/atf/atf-c++/atf_c++_test.cpp8
-rw-r--r--contrib/atf/atf-c++/build.cpp12
-rw-r--r--contrib/atf/atf-c++/build.hpp10
-rw-r--r--contrib/atf/atf-c++/build_test.cpp37
-rw-r--r--contrib/atf/atf-c++/check.cpp14
-rw-r--r--contrib/atf/atf-c++/check.hpp10
-rw-r--r--contrib/atf/atf-c++/check_test.cpp30
-rw-r--r--contrib/atf/atf-c++/config.cpp119
-rw-r--r--contrib/atf/atf-c++/config.hpp75
-rw-r--r--contrib/atf/atf-c++/config_test.cpp227
-rw-r--r--contrib/atf/atf-c++/detail/Kyuafile1
-rw-r--r--contrib/atf/atf-c++/detail/application.cpp11
-rw-r--r--contrib/atf/atf-c++/detail/application.hpp10
-rw-r--r--contrib/atf/atf-c++/detail/application_test.cpp10
-rw-r--r--contrib/atf/atf-c++/detail/auto_array.hpp10
-rw-r--r--contrib/atf/atf-c++/detail/auto_array_test.cpp14
-rw-r--r--contrib/atf/atf-c++/detail/env.cpp22
-rw-r--r--contrib/atf/atf-c++/detail/env.hpp15
-rw-r--r--contrib/atf/atf-c++/detail/env_test.cpp22
-rw-r--r--contrib/atf/atf-c++/detail/exceptions.cpp15
-rw-r--r--contrib/atf/atf-c++/detail/exceptions.hpp10
-rw-r--r--contrib/atf/atf-c++/detail/exceptions_test.cpp13
-rw-r--r--contrib/atf/atf-c++/detail/fs.cpp24
-rw-r--r--contrib/atf/atf-c++/detail/fs.hpp12
-rw-r--r--contrib/atf/atf-c++/detail/fs_test.cpp11
-rw-r--r--contrib/atf/atf-c++/detail/process.cpp21
-rw-r--r--contrib/atf/atf-c++/detail/process.hpp21
-rw-r--r--contrib/atf/atf-c++/detail/process_test.cpp11
-rw-r--r--contrib/atf/atf-c++/detail/sanity.hpp12
-rw-r--r--contrib/atf/atf-c++/detail/sanity_test.cpp41
-rw-r--r--contrib/atf/atf-c++/detail/test_helpers.cpp19
-rw-r--r--contrib/atf/atf-c++/detail/test_helpers.hpp14
-rw-r--r--contrib/atf/atf-c++/detail/text.cpp14
-rw-r--r--contrib/atf/atf-c++/detail/text.hpp10
-rw-r--r--contrib/atf/atf-c++/detail/text_test.cpp10
-rw-r--r--contrib/atf/atf-c++/detail/version_helper.cpp2
-rw-r--r--contrib/atf/atf-c++/macros.hpp85
-rw-r--r--contrib/atf/atf-c++/macros_hpp_test.cpp8
-rw-r--r--contrib/atf/atf-c++/macros_test.cpp22
-rw-r--r--contrib/atf/atf-c++/pkg_config_test.sh4
-rw-r--r--contrib/atf/atf-c++/tests.cpp388
-rw-r--r--contrib/atf/atf-c++/tests.hpp10
-rw-r--r--contrib/atf/atf-c++/tests_test.cpp21
-rw-r--r--contrib/atf/atf-c++/unused_test.cpp6
-rw-r--r--contrib/atf/atf-c++/utils.cpp8
-rw-r--r--contrib/atf/atf-c++/utils.hpp10
-rw-r--r--contrib/atf/atf-c++/utils_test.cpp66
49 files changed, 1097 insertions, 1098 deletions
diff --git a/contrib/atf/atf-c++/Kyuafile b/contrib/atf/atf-c++/Kyuafile
index 6df836f..9fd43af 100644
--- a/contrib/atf/atf-c++/Kyuafile
+++ b/contrib/atf/atf-c++/Kyuafile
@@ -5,7 +5,6 @@ test_suite("atf")
atf_test_program{name="atf_c++_test"}
atf_test_program{name="build_test"}
atf_test_program{name="check_test"}
-atf_test_program{name="config_test"}
atf_test_program{name="macros_test"}
atf_test_program{name="pkg_config_test"}
atf_test_program{name="tests_test"}
diff --git a/contrib/atf/atf-c++/atf-c++.3 b/contrib/atf/atf-c++/atf-c++.3
new file mode 100644
index 0000000..984ec93
--- /dev/null
+++ b/contrib/atf/atf-c++/atf-c++.3
@@ -0,0 +1,649 @@
+.\" Copyright (c) 2008 The NetBSD Foundation, 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:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+.Dd October 13, 2014
+.Dt ATF-C++ 3
+.Os
+.Sh NAME
+.Nm atf-c++ ,
+.Nm ATF_ADD_TEST_CASE ,
+.Nm ATF_CHECK_ERRNO ,
+.Nm ATF_FAIL ,
+.Nm ATF_INIT_TEST_CASES ,
+.Nm ATF_PASS ,
+.Nm ATF_REQUIRE ,
+.Nm ATF_REQUIRE_EQ ,
+.Nm ATF_REQUIRE_ERRNO ,
+.Nm ATF_REQUIRE_IN ,
+.Nm ATF_REQUIRE_MATCH ,
+.Nm ATF_REQUIRE_NOT_IN ,
+.Nm ATF_REQUIRE_THROW ,
+.Nm ATF_REQUIRE_THROW_RE ,
+.Nm ATF_SKIP ,
+.Nm ATF_TEST_CASE ,
+.Nm ATF_TEST_CASE_BODY ,
+.Nm ATF_TEST_CASE_CLEANUP ,
+.Nm ATF_TEST_CASE_HEAD ,
+.Nm ATF_TEST_CASE_NAME ,
+.Nm ATF_TEST_CASE_USE ,
+.Nm ATF_TEST_CASE_WITH_CLEANUP ,
+.Nm ATF_TEST_CASE_WITHOUT_HEAD ,
+.Nm atf::utils::cat_file ,
+.Nm atf::utils::compare_file ,
+.Nm atf::utils::copy_file ,
+.Nm atf::utils::create_file ,
+.Nm atf::utils::file_exists ,
+.Nm atf::utils::fork ,
+.Nm atf::utils::grep_collection ,
+.Nm atf::utils::grep_file ,
+.Nm atf::utils::grep_string ,
+.Nm atf::utils::redirect ,
+.Nm atf::utils::wait
+.Nd C++ API to write ATF-based test programs
+.Sh SYNOPSIS
+.In atf-c++.hpp
+.Fn ATF_ADD_TEST_CASE "tcs" "name"
+.Fn ATF_CHECK_ERRNO "expected_errno" "bool_expression"
+.Fn ATF_FAIL "reason"
+.Fn ATF_INIT_TEST_CASES "tcs"
+.Fn ATF_PASS
+.Fn ATF_REQUIRE "expression"
+.Fn ATF_REQUIRE_EQ "expected_expression" "actual_expression"
+.Fn ATF_REQUIRE_ERRNO "expected_errno" "bool_expression"
+.Fn ATF_REQUIRE_IN "element" "collection"
+.Fn ATF_REQUIRE_MATCH "regexp" "string_expression"
+.Fn ATF_REQUIRE_NOT_IN "element" "collection"
+.Fn ATF_REQUIRE_THROW "expected_exception" "statement"
+.Fn ATF_REQUIRE_THROW_RE "expected_exception" "regexp" "statement"
+.Fn ATF_SKIP "reason"
+.Fn ATF_TEST_CASE "name"
+.Fn ATF_TEST_CASE_BODY "name"
+.Fn ATF_TEST_CASE_CLEANUP "name"
+.Fn ATF_TEST_CASE_HEAD "name"
+.Fn ATF_TEST_CASE_NAME "name"
+.Fn ATF_TEST_CASE_USE "name"
+.Fn ATF_TEST_CASE_WITH_CLEANUP "name"
+.Fn ATF_TEST_CASE_WITHOUT_HEAD "name"
+.Ft void
+.Fo atf::utils::cat_file
+.Fa "const std::string& path"
+.Fa "const std::string& prefix"
+.Fc
+.Ft bool
+.Fo atf::utils::compare_file
+.Fa "const std::string& path"
+.Fa "const std::string& contents"
+.Fc
+.Ft void
+.Fo atf::utils::copy_file
+.Fa "const std::string& source"
+.Fa "const std::string& destination"
+.Fc
+.Ft void
+.Fo atf::utils::create_file
+.Fa "const std::string& path"
+.Fa "const std::string& contents"
+.Fc
+.Ft void
+.Fo atf::utils::file_exists
+.Fa "const std::string& path"
+.Fc
+.Ft pid_t
+.Fo atf::utils::fork
+.Fa "void"
+.Fc
+.Ft bool
+.Fo atf::utils::grep_collection
+.Fa "const std::string& regexp"
+.Fa "const Collection& collection"
+.Fc
+.Ft bool
+.Fo atf::utils::grep_file
+.Fa "const std::string& regexp"
+.Fa "const std::string& path"
+.Fc
+.Ft bool
+.Fo atf::utils::grep_string
+.Fa "const std::string& regexp"
+.Fa "const std::string& path"
+.Fc
+.Ft void
+.Fo atf::utils::redirect
+.Fa "const int fd"
+.Fa "const std::string& path"
+.Fc
+.Ft void
+.Fo atf::utils::wait
+.Fa "const pid_t pid"
+.Fa "const int expected_exit_status"
+.Fa "const std::string& expected_stdout"
+.Fa "const std::string& expected_stderr"
+.Fc
+.Sh DESCRIPTION
+ATF provides a C++ programming interface to implement test programs.
+C++-based test programs follow this template:
+.Bd -literal -offset indent
+extern "C" {
+.Ns ... C-specific includes go here ...
+}
+
+.Ns ... C++-specific includes go here ...
+
+#include <atf-c++.hpp>
+
+ATF_TEST_CASE(tc1);
+ATF_TEST_CASE_HEAD(tc1)
+{
+ ... first test case's header ...
+}
+ATF_TEST_CASE_BODY(tc1)
+{
+ ... first test case's body ...
+}
+
+ATF_TEST_CASE_WITH_CLEANUP(tc2);
+ATF_TEST_CASE_HEAD(tc2)
+{
+ ... second test case's header ...
+}
+ATF_TEST_CASE_BODY(tc2)
+{
+ ... second test case's body ...
+}
+ATF_TEST_CASE_CLEANUP(tc2)
+{
+ ... second test case's cleanup ...
+}
+
+ATF_TEST_CASE(tc3);
+ATF_TEST_CASE_BODY(tc3)
+{
+ ... third test case's body ...
+}
+
+.Ns ... additional test cases ...
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, tc1);
+ ATF_ADD_TEST_CASE(tcs, tc2);
+ ATF_ADD_TEST_CASE(tcs, tc3);
+ ... add additional test cases ...
+}
+.Ed
+.Ss Definition of test cases
+Test cases have an identifier and are composed of three different parts:
+the header, the body and an optional cleanup routine, all of which are
+described in
+.Xr atf-test-case 4 .
+To define test cases, one can use the
+.Fn ATF_TEST_CASE ,
+.Fn ATF_TEST_CASE_WITH_CLEANUP
+or the
+.Fn ATF_TEST_CASE_WITHOUT_HEAD
+macros, which take a single parameter specifiying the test case's
+name.
+.Fn ATF_TEST_CASE ,
+requires to define a head and a body for the test case,
+.Fn ATF_TEST_CASE_WITH_CLEANUP
+requires to define a head, a body and a cleanup for the test case and
+.Fn ATF_TEST_CASE_WITHOUT_HEAD
+requires only a body for the test case.
+It is important to note that these
+.Em do not
+set the test case up for execution when the program is run.
+In order to do so, a later registration is needed through the
+.Fn ATF_ADD_TEST_CASE
+macro detailed in
+.Sx Program initialization .
+.Pp
+Later on, one must define the three parts of the body by means of three
+functions.
+Their headers are given by the
+.Fn ATF_TEST_CASE_HEAD ,
+.Fn ATF_TEST_CASE_BODY
+and
+.Fn ATF_TEST_CASE_CLEANUP
+macros, all of which take the test case's name.
+Following each of these, a block of code is expected, surrounded by the
+opening and closing brackets.
+.Pp
+Additionally, the
+.Fn ATF_TEST_CASE_NAME
+macro can be used to obtain the name of the class corresponding to a
+particular test case, as the name is internally manged by the library to
+prevent clashes with other user identifiers.
+Similarly, the
+.Fn ATF_TEST_CASE_USE
+macro can be executed on a particular test case to mark it as "used" and
+thus prevent compiler warnings regarding unused symbols.
+Note that
+.Em you should never have to use these macros during regular operation.
+.Ss Program initialization
+The library provides a way to easily define the test program's
+.Fn main
+function.
+You should never define one on your own, but rely on the
+library to do it for you.
+This is done by using the
+.Fn ATF_INIT_TEST_CASES
+macro, which is passed the name of the list that will hold the test cases.
+This name can be whatever you want as long as it is a valid variable value.
+.Pp
+After the macro, you are supposed to provide the body of a function, which
+should only use the
+.Fn ATF_ADD_TEST_CASE
+macro to register the test cases the test program will execute.
+The first parameter of this macro matches the name you provided in the
+former call.
+.Ss Header definitions
+The test case's header can define the meta-data by using the
+.Fn set_md_var
+method, which takes two parameters: the first one specifies the
+meta-data variable to be set and the second one specifies its value.
+Both of them are strings.
+.Ss Configuration variables
+The test case has read-only access to the current configuration variables
+by means of the
+.Ft bool
+.Fn has_config_var
+and the
+.Ft std::string
+.Fn get_config_var
+methods, which can be called in any of the three parts of a test case.
+.Ss Access to the source directory
+It is possible to get the path to the test case's source directory from any
+of its three components by querying the
+.Sq srcdir
+configuration variable.
+.Ss Requiring programs
+Aside from the
+.Va require.progs
+meta-data variable available in the header only, one can also check for
+additional programs in the test case's body by using the
+.Fn require_prog
+function, which takes the base name or full path of a single binary.
+Relative paths are forbidden.
+If it is not found, the test case will be automatically skipped.
+.Ss Test case finalization
+The test case finalizes either when the body reaches its end, at which
+point the test is assumed to have
+.Em passed ,
+or at any explicit call to
+.Fn ATF_PASS ,
+.Fn ATF_FAIL
+or
+.Fn ATF_SKIP .
+These three macros terminate the execution of the test case immediately.
+The cleanup routine will be processed afterwards in a completely automated
+way, regardless of the test case's termination reason.
+.Pp
+.Fn ATF_PASS
+does not take any parameters.
+.Fn ATF_FAIL
+and
+.Fn ATF_SKIP
+take a single string that describes why the test case failed or
+was skipped, respectively.
+It is very important to provide a clear error message in both cases so that
+the user can quickly know why the test did not pass.
+.Ss Expectations
+Everything explained in the previous section changes when the test case
+expectations are redefined by the programmer.
+.Pp
+Each test case has an internal state called
+.Sq expect
+that describes what the test case expectations are at any point in time.
+The value of this property can change during execution by any of:
+.Bl -tag -width indent
+.It Fn expect_death "reason"
+Expects the test case to exit prematurely regardless of the nature of the
+exit.
+.It Fn expect_exit "exitcode" "reason"
+Expects the test case to exit cleanly.
+If
+.Va exitcode
+is not
+.Sq -1 ,
+the runtime engine will validate that the exit code of the test case
+matches the one provided in this call.
+Otherwise, the exact value will be ignored.
+.It Fn expect_fail "reason"
+Any failure (be it fatal or non-fatal) raised in this mode is recorded.
+However, such failures do not report the test case as failed; instead, the
+test case finalizes cleanly and is reported as
+.Sq expected failure ;
+this report includes the provided
+.Fa reason
+as part of it.
+If no error is raised while running in this mode, then the test case is
+reported as
+.Sq failed .
+.Pp
+This mode is useful to reproduce actual known bugs in tests.
+Whenever the developer fixes the bug later on, the test case will start
+reporting a failure, signaling the developer that the test case must be
+adjusted to the new conditions.
+In this situation, it is useful, for example, to set
+.Fa reason
+as the bug number for tracking purposes.
+.It Fn expect_pass
+This is the normal mode of execution.
+In this mode, any failure is reported as such to the user and the test case
+is marked as
+.Sq failed .
+.It Fn expect_race "reason"
+Any failure or timeout during the execution of the test case will be
+considered as if a race condition has been triggered and reported as such.
+If no problems arise, the test will continue execution as usual.
+.It Fn expect_signal "signo" "reason"
+Expects the test case to terminate due to the reception of a signal.
+If
+.Va signo
+is not
+.Sq -1 ,
+the runtime engine will validate that the signal that terminated the test
+case matches the one provided in this call.
+Otherwise, the exact value will be ignored.
+.It Fn expect_timeout "reason"
+Expects the test case to execute for longer than its timeout.
+.El
+.Ss Helper macros for common checks
+The library provides several macros that are very handy in multiple
+situations.
+These basically check some condition after executing a given statement or
+processing a given expression and, if the condition is not met, they
+automatically call
+.Fn ATF_FAIL
+with an appropriate error message.
+.Pp
+.Fn ATF_REQUIRE
+takes an expression and raises a failure if it evaluates to false.
+.Pp
+.Fn ATF_REQUIRE_EQ
+takes two expressions and raises a failure if the two do not evaluate to
+the same exact value.
+The common style is to put the expected value in the first parameter and the
+actual value in the second parameter.
+.Pp
+.Fn ATF_REQUIRE_IN
+takes an element and a collection and validates that the element is present in
+the collection.
+.Pp
+.Fn ATF_REQUIRE_MATCH
+takes a regular expression and a string and raises a failure if the regular
+expression does not match the string.
+.Pp
+.Fn ATF_REQUIRE_NOT_IN
+takes an element and a collection and validates that the element is not present
+in the collection.
+.Pp
+.Fn ATF_REQUIRE_THROW
+takes the name of an exception and a statement and raises a failure if
+the statement does not throw the specified exception.
+.Fn ATF_REQUIRE_THROW_RE
+takes the name of an exception, a regular expresion and a statement and raises a
+failure if the statement does not throw the specified exception and if the
+message of the exception does not match the regular expression.
+.Pp
+.Fn ATF_CHECK_ERRNO
+and
+.Fn ATF_REQUIRE_ERRNO
+take, first, the error code that the check is expecting to find in the
+.Va errno
+variable and, second, a boolean expression that, if evaluates to true,
+means that a call failed and
+.Va errno
+has to be checked against the first value.
+.Ss Utility functions
+The following functions are provided as part of the
+.Nm
+API to simplify the creation of a variety of tests.
+In particular, these are useful to write tests for command-line interfaces.
+.Pp
+.Ft void
+.Fo atf::utils::cat_file
+.Fa "const std::string& path"
+.Fa "const std::string& prefix"
+.Fc
+.Bd -ragged -offset indent
+Prints the contents of
+.Fa path
+to the standard output, prefixing every line with the string in
+.Fa prefix .
+.Ed
+.Pp
+.Ft bool
+.Fo atf::utils::compare_file
+.Fa "const std::string& path"
+.Fa "const std::string& contents"
+.Fc
+.Bd -ragged -offset indent
+Returns true if the given
+.Fa path
+matches exactly the expected inlined
+.Fa contents .
+.Ed
+.Pp
+.Ft void
+.Fo atf::utils::copy_file
+.Fa "const std::string& source"
+.Fa "const std::string& destination"
+.Fc
+.Bd -ragged -offset indent
+Copies the file
+.Fa source
+to
+.Fa destination .
+The permissions of the file are preserved during the code.
+.Ed
+.Pp
+.Ft void
+.Fo atf::utils::create_file
+.Fa "const std::string& path"
+.Fa "const std::string& contents"
+.Fc
+.Bd -ragged -offset indent
+Creates
+.Fa file
+with the text given in
+.Fa contents .
+.Ed
+.Pp
+.Ft void
+.Fo atf::utils::file_exists
+.Fa "const std::string& path"
+.Fc
+.Bd -ragged -offset indent
+Checks if
+.Fa path
+exists.
+.Ed
+.Pp
+.Ft pid_t
+.Fo atf::utils::fork
+.Fa "void"
+.Fc
+.Bd -ragged -offset indent
+Forks a process and redirects the standard output and standard error of the
+child to files for later validation with
+.Fn atf::utils::wait .
+Fails the test case if the fork fails, so this does not return an error.
+.Ed
+.Pp
+.Ft bool
+.Fo atf::utils::grep_collection
+.Fa "const std::string& regexp"
+.Fa "const Collection& collection"
+.Fc
+.Bd -ragged -offset indent
+Searches for the regular expression
+.Fa regexp
+in any of the strings contained in the
+.Fa collection .
+This is a template that accepts any one-dimensional container of strings.
+.Ed
+.Pp
+.Ft bool
+.Fo atf::utils::grep_file
+.Fa "const std::string& regexp"
+.Fa "const std::string& path"
+.Fc
+.Bd -ragged -offset indent
+Searches for the regular expression
+.Fa regexp
+in the file
+.Fa path .
+The variable arguments are used to construct the regular expression.
+.Ed
+.Pp
+.Ft bool
+.Fo atf::utils::grep_string
+.Fa "const std::string& regexp"
+.Fa "const std::string& str"
+.Fc
+.Bd -ragged -offset indent
+Searches for the regular expression
+.Fa regexp
+in the string
+.Fa str .
+.Ed
+.Ft void
+.Fo atf::utils::redirect
+.Fa "const int fd"
+.Fa "const std::string& path"
+.Fc
+.Bd -ragged -offset indent
+Redirects the given file descriptor
+.Fa fd
+to the file
+.Fa path .
+This function exits the process in case of an error and does not properly mark
+the test case as failed.
+As a result, it should only be used in subprocesses of the test case; specially
+those spawned by
+.Fn atf::utils::fork .
+.Ed
+.Pp
+.Ft void
+.Fo atf::utils::wait
+.Fa "const pid_t pid"
+.Fa "const int expected_exit_status"
+.Fa "const std::string& expected_stdout"
+.Fa "const std::string& expected_stderr"
+.Fc
+.Bd -ragged -offset indent
+Waits and validates the result of a subprocess spawned with
+.Fn atf::utils::wait .
+The validation involves checking that the subprocess exited cleanly and returned
+the code specified in
+.Fa expected_exit_status
+and that its standard output and standard error match the strings given in
+.Fa expected_stdout
+and
+.Fa expected_stderr .
+.Pp
+If any of the
+.Fa expected_stdout
+or
+.Fa expected_stderr
+strings are prefixed with
+.Sq save: ,
+then they specify the name of the file into which to store the stdout or stderr
+of the subprocess, and no comparison is performed.
+.Ed
+.Sh ENVIRONMENT
+The following variables are recognized by
+.Nm
+but should not be overridden other than for testing purposes:
+.Pp
+.Bl -tag -width ATFXBUILDXCXXFLAGSXX -compact
+.It Va ATF_BUILD_CC
+Path to the C compiler.
+.It Va ATF_BUILD_CFLAGS
+C compiler flags.
+.It Va ATF_BUILD_CPP
+Path to the C/C++ preprocessor.
+.It Va ATF_BUILD_CPPFLAGS
+C/C++ preprocessor flags.
+.It Va ATF_BUILD_CXX
+Path to the C++ compiler.
+.It Va ATF_BUILD_CXXFLAGS
+C++ compiler flags.
+.El
+.Sh EXAMPLES
+The following shows a complete test program with a single test case that
+validates the addition operator:
+.Bd -literal -offset indent
+#include <atf-c++.hpp>
+
+ATF_TEST_CASE(addition);
+ATF_TEST_CASE_HEAD(addition)
+{
+ set_md_var("descr", "Sample tests for the addition operator");
+}
+ATF_TEST_CASE_BODY(addition)
+{
+ ATF_REQUIRE_EQ(0, 0 + 0);
+ ATF_REQUIRE_EQ(1, 0 + 1);
+ ATF_REQUIRE_EQ(1, 1 + 0);
+
+ ATF_REQUIRE_EQ(2, 1 + 1);
+
+ ATF_REQUIRE_EQ(300, 100 + 200);
+}
+
+ATF_TEST_CASE(open_failure);
+ATF_TEST_CASE_HEAD(open_failure)
+{
+ set_md_var("descr", "Sample tests for the open function");
+}
+ATF_TEST_CASE_BODY(open_failure)
+{
+ ATF_REQUIRE_ERRNO(ENOENT, open("non-existent", O_RDONLY) == -1);
+}
+
+ATF_TEST_CASE(known_bug);
+ATF_TEST_CASE_HEAD(known_bug)
+{
+ set_md_var("descr", "Reproduces a known bug");
+}
+ATF_TEST_CASE_BODY(known_bug)
+{
+ expect_fail("See bug number foo/bar");
+ ATF_REQUIRE_EQ(3, 1 + 1);
+ expect_pass();
+ ATF_REQUIRE_EQ(3, 1 + 2);
+}
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, addition);
+ ATF_ADD_TEST_CASE(tcs, open_failure);
+ ATF_ADD_TEST_CASE(tcs, known_bug);
+}
+.Ed
+.Sh SEE ALSO
+.Xr atf-test-program 1 ,
+.Xr atf-test-case 4
diff --git a/contrib/atf/atf-c++/atf_c++_test.cpp b/contrib/atf/atf-c++/atf_c++_test.cpp
index c09e4b1..cc70886 100644
--- a/contrib/atf/atf-c++/atf_c++_test.cpp
+++ b/contrib/atf/atf-c++/atf_c++_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2009 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,11 +22,10 @@
// 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.
-//
-#include "macros.hpp"
+#include <atf-c++.hpp>
-#include "detail/test_helpers.hpp"
+#include "atf-c++/detail/test_helpers.hpp"
// ------------------------------------------------------------------------
// Tests cases for the header file.
diff --git a/contrib/atf/atf-c++/build.cpp b/contrib/atf/atf-c++/build.cpp
index 9ce134c..f2f80f4 100644
--- a/contrib/atf/atf-c++/build.cpp
+++ b/contrib/atf/atf-c++/build.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2009 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,8 @@
// 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.
-//
+
+#include "atf-c++/build.hpp"
extern "C" {
#include "atf-c/build.h"
@@ -33,10 +31,8 @@ extern "C" {
#include "atf-c/utils.h"
}
-#include "build.hpp"
-
-#include "detail/exceptions.hpp"
-#include "detail/process.hpp"
+#include "atf-c++/detail/exceptions.hpp"
+#include "atf-c++/detail/process.hpp"
namespace impl = atf::build;
#define IMPL_NAME "atf::build"
diff --git a/contrib/atf/atf-c++/build.hpp b/contrib/atf/atf-c++/build.hpp
index 5a291b4..7aa5a97 100644
--- a/contrib/atf/atf-c++/build.hpp
+++ b/contrib/atf/atf-c++/build.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2009 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_BUILD_HPP_)
-#define _ATF_CXX_BUILD_HPP_
+#if !defined(ATF_CXX_BUILD_HPP)
+#define ATF_CXX_BUILD_HPP
#include <string>
@@ -54,4 +50,4 @@ process::argv_array cxx_o(const std::string&, const std::string&,
} // namespace build
} // namespace atf
-#endif // !defined(_ATF_CXX_BUILD_HPP_)
+#endif // !defined(ATF_CXX_BUILD_HPP)
diff --git a/contrib/atf/atf-c++/build_test.cpp b/contrib/atf/atf-c++/build_test.cpp
index 6852905..0a5ab96 100644
--- a/contrib/atf/atf-c++/build_test.cpp
+++ b/contrib/atf/atf-c++/build_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2009 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,31 +22,25 @@
// 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.
-//
+
+#include "atf-c++/build.hpp"
#include <cstring>
#include <iostream>
-#include "../atf-c/h_build.h"
+#include <atf-c++.hpp>
-#include "build.hpp"
-#include "config.hpp"
-#include "macros.hpp"
+extern "C" {
+#include "atf-c/h_build.h"
+}
-#include "detail/env.hpp"
-#include "detail/process.hpp"
-#include "detail/test_helpers.hpp"
+#include "atf-c++/detail/env.hpp"
+#include "atf-c++/detail/process.hpp"
// ------------------------------------------------------------------------
// Auxiliary functions.
// ------------------------------------------------------------------------
-namespace atf {
- namespace config {
- void __reinit(void);
- }
-}
-
template< class C >
void
print_col(const char* prefix, const C& c)
@@ -168,7 +159,6 @@ ATF_TEST_CASE_BODY(c_o)
verbose_set_env("ATF_BUILD_CC", test->cc);
verbose_set_env("ATF_BUILD_CFLAGS", test->cflags);
verbose_set_env("ATF_BUILD_CPPFLAGS", test->cppflags);
- atf::config::__reinit();
atf::process::argv_array argv =
atf::build::c_o(test->sfile, test->ofile,
@@ -190,7 +180,6 @@ ATF_TEST_CASE_BODY(cpp)
verbose_set_env("ATF_BUILD_CPP", test->cpp);
verbose_set_env("ATF_BUILD_CPPFLAGS", test->cppflags);
- atf::config::__reinit();
atf::process::argv_array argv =
atf::build::cpp(test->sfile, test->ofile,
@@ -213,7 +202,6 @@ ATF_TEST_CASE_BODY(cxx_o)
verbose_set_env("ATF_BUILD_CXX", test->cxx);
verbose_set_env("ATF_BUILD_CXXFLAGS", test->cxxflags);
verbose_set_env("ATF_BUILD_CPPFLAGS", test->cppflags);
- atf::config::__reinit();
atf::process::argv_array argv =
atf::build::cxx_o(test->sfile, test->ofile,
@@ -223,12 +211,6 @@ ATF_TEST_CASE_BODY(cxx_o)
}
// ------------------------------------------------------------------------
-// Tests cases for the header file.
-// ------------------------------------------------------------------------
-
-HEADER_TC(include, "atf-c++/build.hpp");
-
-// ------------------------------------------------------------------------
// Main.
// ------------------------------------------------------------------------
@@ -241,7 +223,4 @@ ATF_INIT_TEST_CASES(tcs)
ATF_ADD_TEST_CASE(tcs, c_o);
ATF_ADD_TEST_CASE(tcs, cpp);
ATF_ADD_TEST_CASE(tcs, cxx_o);
-
- // Add the test cases for the header file.
- ATF_ADD_TEST_CASE(tcs, include);
}
diff --git a/contrib/atf/atf-c++/check.cpp b/contrib/atf/atf-c++/check.cpp
index b099b07..e4d7db4 100644
--- a/contrib/atf/atf-c++/check.cpp
+++ b/contrib/atf/atf-c++/check.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,8 @@
// 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.
-//
+
+#include "atf-c++/check.hpp"
#include <cstring>
@@ -34,11 +32,9 @@ extern "C" {
#include "atf-c/error.h"
}
-#include "check.hpp"
-
-#include "detail/exceptions.hpp"
-#include "detail/process.hpp"
-#include "detail/sanity.hpp"
+#include "atf-c++/detail/exceptions.hpp"
+#include "atf-c++/detail/process.hpp"
+#include "atf-c++/detail/sanity.hpp"
namespace impl = atf::check;
#define IMPL_NAME "atf::check"
diff --git a/contrib/atf/atf-c++/check.hpp b/contrib/atf/atf-c++/check.hpp
index f838efb..0144ded 100644
--- a/contrib/atf/atf-c++/check.hpp
+++ b/contrib/atf/atf-c++/check.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_CHECK_HPP_)
-#define _ATF_CXX_CHECK_HPP_
+#if !defined(ATF_CXX_CHECK_HPP)
+#define ATF_CXX_CHECK_HPP
extern "C" {
#include <atf-c/check.h>
@@ -132,4 +128,4 @@ check_result test_constructor(void);
} // namespace check
} // namespace atf
-#endif // !defined(_ATF_CXX_CHECK_HPP_)
+#endif // !defined(ATF_CXX_CHECK_HPP)
diff --git a/contrib/atf/atf-c++/check_test.cpp b/contrib/atf/atf-c++/check_test.cpp
index a92511c..7baf3fa 100644
--- a/contrib/atf/atf-c++/check_test.cpp
+++ b/contrib/atf/atf-c++/check_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,8 @@
// 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.
-//
+
+#include "atf-c++/check.hpp"
extern "C" {
#include <fcntl.h>
@@ -43,14 +41,11 @@ extern "C" {
#include <atf-c++.hpp>
-#include "check.hpp"
-#include "config.hpp"
-#include "utils.hpp"
-
-#include "detail/fs.hpp"
-#include "detail/process.hpp"
-#include "detail/test_helpers.hpp"
-#include "detail/text.hpp"
+#include "atf-c++/detail/fs.hpp"
+#include "atf-c++/detail/process.hpp"
+#include "atf-c++/detail/test_helpers.hpp"
+#include "atf-c++/detail/text.hpp"
+#include "atf-c++/utils.hpp"
// ------------------------------------------------------------------------
// Auxiliary functions.
@@ -374,7 +369,7 @@ ATF_TEST_CASE_HEAD(exec_unknown)
ATF_TEST_CASE_BODY(exec_unknown)
{
std::vector< std::string > argv;
- argv.push_back(atf::config::get("atf_workdir") + "/non-existent");
+ argv.push_back("/foo/bar/non-existent");
atf::process::argv_array argva(argv);
std::auto_ptr< atf::check::check_result > r = atf::check::exec(argva);
@@ -383,12 +378,6 @@ ATF_TEST_CASE_BODY(exec_unknown)
}
// ------------------------------------------------------------------------
-// Tests cases for the header file.
-// ------------------------------------------------------------------------
-
-HEADER_TC(include, "atf-c++/check.hpp");
-
-// ------------------------------------------------------------------------
// Main.
// ------------------------------------------------------------------------
@@ -402,7 +391,4 @@ ATF_INIT_TEST_CASES(tcs)
ATF_ADD_TEST_CASE(tcs, exec_exitstatus);
ATF_ADD_TEST_CASE(tcs, exec_stdout_stderr);
ATF_ADD_TEST_CASE(tcs, exec_unknown);
-
- // Add the test cases for the header file.
- ATF_ADD_TEST_CASE(tcs, include);
}
diff --git a/contrib/atf/atf-c++/config.cpp b/contrib/atf/atf-c++/config.cpp
deleted file mode 100644
index 1890ac0..0000000
--- a/contrib/atf/atf-c++/config.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-//
-// Automated Testing Framework (atf)
-//
-// Copyright (c) 2007 The NetBSD Foundation, 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:
-// 1. Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// 2. 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.
-//
-// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
-//
-
-#include <map>
-
-extern "C" {
-#include "atf-c/config.h"
-}
-
-#include "config.hpp"
-
-#include "detail/env.hpp"
-#include "detail/sanity.hpp"
-
-static std::map< std::string, std::string > m_variables;
-
-//
-// Adds all predefined standard build-time variables to the m_variables
-// map, considering the values a user may have provided in the environment.
-//
-// Can only be called once during the program's lifetime.
-//
-static
-void
-init_variables(void)
-{
- PRE(m_variables.empty());
-
- m_variables["atf_build_cc"] = atf_config_get("atf_build_cc");
- m_variables["atf_build_cflags"] = atf_config_get("atf_build_cflags");
- m_variables["atf_build_cpp"] = atf_config_get("atf_build_cpp");
- m_variables["atf_build_cppflags"] = atf_config_get("atf_build_cppflags");
- m_variables["atf_build_cxx"] = atf_config_get("atf_build_cxx");
- m_variables["atf_build_cxxflags"] = atf_config_get("atf_build_cxxflags");
- m_variables["atf_includedir"] = atf_config_get("atf_includedir");
- m_variables["atf_libexecdir"] = atf_config_get("atf_libexecdir");
- m_variables["atf_pkgdatadir"] = atf_config_get("atf_pkgdatadir");
- m_variables["atf_shell"] = atf_config_get("atf_shell");
- m_variables["atf_workdir"] = atf_config_get("atf_workdir");
-
- POST(!m_variables.empty());
-}
-
-const std::string&
-atf::config::get(const std::string& varname)
-{
- if (m_variables.empty())
- init_variables();
-
- PRE(has(varname));
- return m_variables[varname];
-}
-
-const std::map< std::string, std::string >&
-atf::config::get_all(void)
-{
- if (m_variables.empty())
- init_variables();
-
- return m_variables;
-}
-
-bool
-atf::config::has(const std::string& varname)
-{
- if (m_variables.empty())
- init_variables();
-
- return m_variables.find(varname) != m_variables.end();
-}
-
-extern "C" {
-void __atf_config_reinit(void);
-}
-
-namespace atf {
-namespace config {
-//
-// Auxiliary function for the t_config test program so that it can
-// revert the configuration's global status to an empty state and
-// do new tests from there on.
-//
-// Ideally this shouldn't be part of the production library... but
-// this is so small that it does not matter.
-//
-void
-__reinit(void)
-{
- __atf_config_reinit();
- m_variables.clear();
-}
-} // namespace config
-} // namespace atf
diff --git a/contrib/atf/atf-c++/config.hpp b/contrib/atf/atf-c++/config.hpp
deleted file mode 100644
index e11b9bb..0000000
--- a/contrib/atf/atf-c++/config.hpp
+++ /dev/null
@@ -1,75 +0,0 @@
-//
-// Automated Testing Framework (atf)
-//
-// Copyright (c) 2007 The NetBSD Foundation, 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:
-// 1. Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// 2. 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.
-//
-// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
-//
-
-#if !defined(_ATF_CXX_CONFIG_HPP_)
-#define _ATF_CXX_CONFIG_HPP_
-
-#include <map>
-#include <string>
-
-namespace atf {
-
-namespace config {
-
-//!
-//! \brief Gets a build-time configuration variable's value.
-//!
-//! Given the name of a build-time configuration variable, returns its
-//! textual value. The user is free to override these by setting their
-//! corresponding environment variables. Therefore always use this
-//! interface to get the value of these variables.
-//!
-//! \pre The variable must exist.
-//!
-const std::string& get(const std::string&);
-
-//!
-//! \brief Returns all the build-time configuration variables.
-//!
-//! Returns a name to value map containing all build-time configuration
-//! variables.
-//!
-const std::map< std::string, std::string >& get_all(void);
-
-//!
-//! \brief Checks whether a build-time configuration variable exists.
-//!
-//! Given the name of a build-time configuration variable, checks
-//! whether it is defined and returns a boolean indicating this
-//! condition. The program only has to use this function to sanity-check
-//! a variable name provided by the user. Otherwise it can assume that
-//! the variables are defined.
-//!
-bool has(const std::string&);
-
-} // namespace config
-
-} // namespace atf
-
-#endif // !defined(_ATF_CXX_CONFIG_HPP_)
diff --git a/contrib/atf/atf-c++/config_test.cpp b/contrib/atf/atf-c++/config_test.cpp
deleted file mode 100644
index 78e1584..0000000
--- a/contrib/atf/atf-c++/config_test.cpp
+++ /dev/null
@@ -1,227 +0,0 @@
-//
-// Automated Testing Framework (atf)
-//
-// Copyright (c) 2007 The NetBSD Foundation, 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:
-// 1. Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// 2. 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.
-//
-// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
-//
-
-#include <cstring>
-#include <iostream>
-
-#include "config.hpp"
-#include "macros.hpp"
-
-#include "detail/env.hpp"
-#include "detail/exceptions.hpp"
-#include "detail/test_helpers.hpp"
-
-static const char *test_value = "env-value";
-
-static struct varnames {
- const char *lc;
- const char *uc;
- bool can_be_empty;
-} all_vars[] = {
- { "atf_build_cc", "ATF_BUILD_CC", false },
- { "atf_build_cflags", "ATF_BUILD_CFLAGS", true },
- { "atf_build_cpp", "ATF_BUILD_CPP", false },
- { "atf_build_cppflags", "ATF_BUILD_CPPFLAGS", true },
- { "atf_build_cxx", "ATF_BUILD_CXX", false },
- { "atf_build_cxxflags", "ATF_BUILD_CXXFLAGS", true },
- { "atf_includedir", "ATF_INCLUDEDIR", false },
- { "atf_libexecdir", "ATF_LIBEXECDIR", false },
- { "atf_pkgdatadir", "ATF_PKGDATADIR", false },
- { "atf_shell", "ATF_SHELL", false },
- { "atf_workdir", "ATF_WORKDIR", false },
- { NULL, NULL, false }
-};
-
-// ------------------------------------------------------------------------
-// Auxiliary functions.
-// ------------------------------------------------------------------------
-
-namespace atf {
- namespace config {
- void __reinit(void);
- }
-}
-
-static
-void
-set_env_var(const char* name, const char* val)
-{
- try {
- atf::env::set(name, val);
- } catch (const atf::system_error&) {
- ATF_FAIL(std::string("set_env_var(") + name + ", " + val +
- ") failed");
- }
-}
-
-static
-void
-unset_env_var(const char* name)
-{
- try {
- atf::env::unset(name);
- } catch (const atf::system_error&) {
- ATF_FAIL(std::string("unset_env_var(") + name + ") failed");
- }
-}
-
-static
-size_t
-all_vars_count(void)
-{
- size_t count = 0;
- for (const struct varnames* v = all_vars; v->lc != NULL; v++)
- count++;
- return count;
-}
-
-static
-void
-unset_all(void)
-{
- for (const struct varnames* v = all_vars; v->lc != NULL; v++)
- unset_env_var(v->uc);
-}
-
-static
-void
-compare_one(const char* var, const char* expvalue)
-{
- std::cout << "Checking that " << var << " is set to " << expvalue << "\n";
-
- for (const struct varnames* v = all_vars; v->lc != NULL; v++) {
- if (std::strcmp(v->lc, var) == 0)
- ATF_REQUIRE_EQ(atf::config::get(v->lc), test_value);
- else
- ATF_REQUIRE(atf::config::get(v->lc) != test_value);
- }
-}
-
-// ------------------------------------------------------------------------
-// Test cases for the free functions.
-// ------------------------------------------------------------------------
-
-ATF_TEST_CASE(get);
-ATF_TEST_CASE_HEAD(get)
-{
- set_md_var("descr", "Tests the config::get function");
-}
-ATF_TEST_CASE_BODY(get)
-{
- // Unset all known environment variables and make sure the built-in
- // values do not match the bogus value we will use for testing.
- unset_all();
- atf::config::__reinit();
- for (const struct varnames* v = all_vars; v->lc != NULL; v++)
- ATF_REQUIRE(atf::config::get(v->lc) != test_value);
-
- // Test the behavior of empty values.
- for (const struct varnames* v = all_vars; v->lc != NULL; v++) {
- unset_all();
- if (!atf::config::get(v->lc).empty()) {
- set_env_var(v->uc, "");
- atf::config::__reinit();
- if (v->can_be_empty)
- ATF_REQUIRE(atf::config::get(v->lc).empty());
- else
- ATF_REQUIRE(!atf::config::get(v->lc).empty());
- }
- }
-
- // Check if the ATF_ARCH variable is recognized.
- for (const struct varnames* v = all_vars; v->lc != NULL; v++) {
- unset_all();
- set_env_var(v->uc, test_value);
- atf::config::__reinit();
- compare_one(v->lc, test_value);
- }
-}
-
-ATF_TEST_CASE(get_all);
-ATF_TEST_CASE_HEAD(get_all)
-{
- set_md_var("descr", "Tests the config::get_all function");
-}
-ATF_TEST_CASE_BODY(get_all)
-{
- atf::config::__reinit();
-
- // Check that the valid variables, and only those, are returned.
- std::map< std::string, std::string > vars = atf::config::get_all();
- ATF_REQUIRE_EQ(vars.size(), all_vars_count());
- for (const struct varnames* v = all_vars; v->lc != NULL; v++)
- ATF_REQUIRE(vars.find(v->lc) != vars.end());
-}
-
-ATF_TEST_CASE(has);
-ATF_TEST_CASE_HEAD(has)
-{
- set_md_var("descr", "Tests the config::has function");
-}
-ATF_TEST_CASE_BODY(has)
-{
- atf::config::__reinit();
-
- // Check for all the variables that must exist.
- for (const struct varnames* v = all_vars; v->lc != NULL; v++)
- ATF_REQUIRE(atf::config::has(v->lc));
-
- // Same as above, but using uppercase (which is incorrect).
- for (const struct varnames* v = all_vars; v->lc != NULL; v++)
- ATF_REQUIRE(!atf::config::has(v->uc));
-
- // Check for some other variables that cannot exist.
- ATF_REQUIRE(!atf::config::has("foo"));
- ATF_REQUIRE(!atf::config::has("BAR"));
- ATF_REQUIRE(!atf::config::has("atf_foo"));
- ATF_REQUIRE(!atf::config::has("ATF_BAR"));
- ATF_REQUIRE(!atf::config::has("atf_shel"));
- ATF_REQUIRE(!atf::config::has("atf_shells"));
-}
-
-// ------------------------------------------------------------------------
-// Tests cases for the header file.
-// ------------------------------------------------------------------------
-
-HEADER_TC(include, "atf-c++/config.hpp");
-
-// ------------------------------------------------------------------------
-// Main.
-// ------------------------------------------------------------------------
-
-ATF_INIT_TEST_CASES(tcs)
-{
- // Add the test cases for the free functions.
- ATF_ADD_TEST_CASE(tcs, has);
- ATF_ADD_TEST_CASE(tcs, get);
- ATF_ADD_TEST_CASE(tcs, get_all);
-
- // Add the test cases for the header file.
- ATF_ADD_TEST_CASE(tcs, include);
-}
diff --git a/contrib/atf/atf-c++/detail/Kyuafile b/contrib/atf/atf-c++/detail/Kyuafile
index 03388ba..fc799e6 100644
--- a/contrib/atf/atf-c++/detail/Kyuafile
+++ b/contrib/atf/atf-c++/detail/Kyuafile
@@ -8,5 +8,4 @@ atf_test_program{name="env_test"}
atf_test_program{name="exceptions_test"}
atf_test_program{name="fs_test"}
atf_test_program{name="process_test"}
-atf_test_program{name="sanity_test"}
atf_test_program{name="text_test"}
diff --git a/contrib/atf/atf-c++/detail/application.cpp b/contrib/atf/atf-c++/detail/application.cpp
index 454bc64..37086eb 100644
--- a/contrib/atf/atf-c++/detail/application.cpp
+++ b/contrib/atf/atf-c++/detail/application.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,11 @@
// 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.
-//
+
+#include "atf-c++/detail/application.hpp"
#if defined(HAVE_CONFIG_H)
-#include "bconfig.h"
+#include "config.h"
#endif
extern "C" {
@@ -45,8 +43,7 @@ extern "C" {
#include "atf-c/defs.h"
}
-#include "application.hpp"
-#include "sanity.hpp"
+#include "atf-c++/detail/sanity.hpp"
#if !defined(HAVE_VSNPRINTF_IN_STD)
namespace std {
diff --git a/contrib/atf/atf-c++/detail/application.hpp b/contrib/atf/atf-c++/detail/application.hpp
index d12b267..cdb4073 100644
--- a/contrib/atf/atf-c++/detail/application.hpp
+++ b/contrib/atf/atf-c++/detail/application.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_APPLICATION_HPP_)
-#define _ATF_CXX_APPLICATION_HPP_
+#if !defined(ATF_CXX_DETAIL_APPLICATION_HPP)
+#define ATF_CXX_DETAIL_APPLICATION_HPP
#include <ostream>
#include <set>
@@ -108,4 +104,4 @@ public:
} // namespace application
} // namespace atf
-#endif // !defined(_ATF_CXX_APPLICATION_HPP_)
+#endif // !defined(ATF_CXX_DETAIL_APPLICATION_HPP)
diff --git a/contrib/atf/atf-c++/detail/application_test.cpp b/contrib/atf/atf-c++/detail/application_test.cpp
index 4664a3a..28b7a2f 100644
--- a/contrib/atf/atf-c++/detail/application_test.cpp
+++ b/contrib/atf/atf-c++/detail/application_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2009 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,15 +22,14 @@
// 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.
-//
+
+#include "atf-c++/detail/application.hpp"
extern "C" {
#include <unistd.h>
}
-#include "application.hpp"
-
-#include "../macros.hpp"
+#include <atf-c++.hpp>
class getopt_app : public atf::application::app {
public:
diff --git a/contrib/atf/atf-c++/detail/auto_array.hpp b/contrib/atf/atf-c++/detail/auto_array.hpp
index 1459284..b434a58 100644
--- a/contrib/atf/atf-c++/detail/auto_array.hpp
+++ b/contrib/atf/atf-c++/detail/auto_array.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_AUTO_ARRAY_HPP_)
-#define _ATF_CXX_AUTO_ARRAY_HPP_
+#if !defined(ATF_CXX_DETAIL_AUTO_ARRAY_HPP)
+#define ATF_CXX_DETAIL_AUTO_ARRAY_HPP
#include <cstddef>
@@ -176,4 +172,4 @@ auto_array< T >::operator auto_array_ref< T >(void)
} // namespace atf
-#endif // !defined(_ATF_CXX_AUTO_ARRAY_HPP_)
+#endif // !defined(ATF_CXX_DETAIL_AUTO_ARRAY_HPP)
diff --git a/contrib/atf/atf-c++/detail/auto_array_test.cpp b/contrib/atf/atf-c++/detail/auto_array_test.cpp
index dcfe415..aaad90e 100644
--- a/contrib/atf/atf-c++/detail/auto_array_test.cpp
+++ b/contrib/atf/atf-c++/detail/auto_array_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,8 @@
// 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.
-//
+
+#include "atf-c++/detail/auto_array.hpp"
extern "C" {
#include <sys/types.h>
@@ -33,11 +31,11 @@ extern "C" {
#include <iostream>
-#include "atf-c/defs.h"
+#include <atf-c++.hpp>
-#include "../macros.hpp"
-
-#include "auto_array.hpp"
+extern "C" {
+#include "atf-c/defs.h"
+}
// ------------------------------------------------------------------------
// Tests for the "auto_array" class.
diff --git a/contrib/atf/atf-c++/detail/env.cpp b/contrib/atf/atf-c++/detail/env.cpp
index 5ca7f09..8855dcb 100644
--- a/contrib/atf/atf-c++/detail/env.cpp
+++ b/contrib/atf/atf-c++/detail/env.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,17 +22,16 @@
// 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.
-//
-extern "C" {
-#include "../../atf-c/error.h"
+#include "atf-c++/detail/env.hpp"
-#include "../../atf-c/detail/env.h"
+extern "C" {
+#include "atf-c/detail/env.h"
+#include "atf-c/error.h"
}
-#include "env.hpp"
-#include "exceptions.hpp"
-#include "sanity.hpp"
+#include "atf-c++/detail/exceptions.hpp"
+#include "atf-c++/detail/sanity.hpp"
namespace impl = atf::env;
#define IMPL_NAME "atf::env"
@@ -50,6 +46,12 @@ impl::get(const std::string& name)
return atf_env_get(name.c_str());
}
+std::string
+impl::get(const std::string& name, const std::string& default_value)
+{
+ return atf_env_get_with_default(name.c_str(), default_value.c_str());
+}
+
bool
impl::has(const std::string& name)
{
diff --git a/contrib/atf/atf-c++/detail/env.hpp b/contrib/atf/atf-c++/detail/env.hpp
index afdf69b..e1dcbc0 100644
--- a/contrib/atf/atf-c++/detail/env.hpp
+++ b/contrib/atf/atf-c++/detail/env.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_ENV_HPP_)
-#define _ATF_CXX_ENV_HPP_
+#if !defined(ATF_CXX_DETAIL_ENV_HPP)
+#define ATF_CXX_DETAIL_ENV_HPP
#include <string>
@@ -48,6 +44,11 @@ namespace env {
std::string get(const std::string&);
//!
+//! \brief Returns the value of an environment variable with a default.
+//!
+std::string get(const std::string&, const std::string&);
+
+//!
//! \brief Checks if the environment has a variable.
//!
//! Checks if the environment has a given variable.
@@ -81,4 +82,4 @@ void unset(const std::string&);
} // namespace env
} // namespace atf
-#endif // !defined(_ATF_CXX_ENV_HPP_)
+#endif // !defined(ATF_CXX_DETAIL_ENV_HPP)
diff --git a/contrib/atf/atf-c++/detail/env_test.cpp b/contrib/atf/atf-c++/detail/env_test.cpp
index a7b681d..91616f3 100644
--- a/contrib/atf/atf-c++/detail/env_test.cpp
+++ b/contrib/atf/atf-c++/detail/env_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,11 +22,10 @@
// 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.
-//
-#include "../macros.hpp"
+#include "atf-c++/detail/env.hpp"
-#include "env.hpp"
+#include <atf-c++.hpp>
// ------------------------------------------------------------------------
// Test cases for the free functions.
@@ -48,6 +44,19 @@ ATF_TEST_CASE_BODY(has_get)
ATF_REQUIRE(!atf::env::has("_UNDEFINED_VARIABLE_"));
}
+ATF_TEST_CASE(get_with_default);
+ATF_TEST_CASE_HEAD(get_with_default)
+{
+ set_md_var("descr", "Tests the get function with a default value");
+}
+ATF_TEST_CASE_BODY(get_with_default)
+{
+ ATF_REQUIRE(atf::env::has("PATH"));
+ ATF_REQUIRE(atf::env::get("PATH", "default value") != "default value");
+
+ ATF_REQUIRE_EQ(atf::env::get("_UNDEFINED_VARIABLE_", "foo bar"), "foo bar");
+}
+
ATF_TEST_CASE(set);
ATF_TEST_CASE_HEAD(set)
{
@@ -86,6 +95,7 @@ ATF_INIT_TEST_CASES(tcs)
{
// Add the test cases for the free functions.
ATF_ADD_TEST_CASE(tcs, has_get);
+ ATF_ADD_TEST_CASE(tcs, get_with_default);
ATF_ADD_TEST_CASE(tcs, set);
ATF_ADD_TEST_CASE(tcs, unset);
}
diff --git a/contrib/atf/atf-c++/detail/exceptions.cpp b/contrib/atf/atf-c++/detail/exceptions.cpp
index 79c5b48..a5b74a3 100644
--- a/contrib/atf/atf-c++/detail/exceptions.cpp
+++ b/contrib/atf/atf-c++/detail/exceptions.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,11 @@
// 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.
-//
+
+#include "atf-c++/detail/exceptions.hpp"
#if defined(HAVE_CONFIG_H)
-#include "bconfig.h"
+#include "config.h"
#endif
#include <cstdarg>
@@ -37,11 +35,10 @@
#include <new>
extern "C" {
-#include "../../atf-c/error.h"
-};
+#include "atf-c/error.h"
+}
-#include "exceptions.hpp"
-#include "sanity.hpp"
+#include "atf-c++/detail/sanity.hpp"
// ------------------------------------------------------------------------
// The "system_error" type.
diff --git a/contrib/atf/atf-c++/detail/exceptions.hpp b/contrib/atf/atf-c++/detail/exceptions.hpp
index 9bda62b..0728ad1 100644
--- a/contrib/atf/atf-c++/detail/exceptions.hpp
+++ b/contrib/atf/atf-c++/detail/exceptions.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_EXCEPTIONS_HPP_)
-#define _ATF_CXX_EXCEPTIONS_HPP_
+#if !defined(ATF_CXX_DETAIL_EXCEPTIONS_HPP)
+#define ATF_CXX_DETAIL_EXCEPTIONS_HPP
#include <stdexcept>
#include <string>
@@ -55,4 +51,4 @@ void throw_atf_error(struct atf_error *);
} // namespace atf
-#endif // !defined(_ATF_CXX_EXCEPTIONS_HPP_)
+#endif // !defined(ATF_CXX_DETAIL_EXCEPTIONS_HPP)
diff --git a/contrib/atf/atf-c++/detail/exceptions_test.cpp b/contrib/atf/atf-c++/detail/exceptions_test.cpp
index 821c192..c0bf4fc 100644
--- a/contrib/atf/atf-c++/detail/exceptions_test.cpp
+++ b/contrib/atf/atf-c++/detail/exceptions_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2009 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,19 +22,19 @@
// 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.
-//
+
+#include "atf-c++/detail/exceptions.hpp"
extern "C" {
-#include "../../atf-c/error.h"
+#include "atf-c/error.h"
}
#include <cstdio>
#include <new>
-#include "../macros.hpp"
+#include <atf-c++.hpp>
-#include "exceptions.hpp"
-#include "sanity.hpp"
+#include "atf-c++/detail/sanity.hpp"
// ------------------------------------------------------------------------
// The "test" error.
diff --git a/contrib/atf/atf-c++/detail/fs.cpp b/contrib/atf/atf-c++/detail/fs.cpp
index 3517e26..bcef920 100644
--- a/contrib/atf/atf-c++/detail/fs.cpp
+++ b/contrib/atf/atf-c++/detail/fs.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,11 @@
// 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.
-//
+
+#include "atf-c++/detail/fs.hpp"
#if defined(HAVE_CONFIG_H)
-#include "bconfig.h"
+#include "config.h"
#endif
extern "C" {
@@ -47,17 +45,15 @@ extern "C" {
#include <cstring>
extern "C" {
-#include "../../atf-c/error.h"
+#include "atf-c/error.h"
}
-#include "../utils.hpp"
-
-#include "exceptions.hpp"
-#include "env.hpp"
-#include "fs.hpp"
-#include "process.hpp"
-#include "sanity.hpp"
-#include "text.hpp"
+#include "atf-c++/detail/env.hpp"
+#include "atf-c++/detail/exceptions.hpp"
+#include "atf-c++/detail/process.hpp"
+#include "atf-c++/detail/sanity.hpp"
+#include "atf-c++/detail/text.hpp"
+#include "atf-c++/utils.hpp"
namespace impl = atf::fs;
#define IMPL_NAME "atf::fs"
diff --git a/contrib/atf/atf-c++/detail/fs.hpp b/contrib/atf/atf-c++/detail/fs.hpp
index 4ffb39b..d6670f6 100644
--- a/contrib/atf/atf-c++/detail/fs.hpp
+++ b/contrib/atf/atf-c++/detail/fs.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_FS_HPP_)
-#define _ATF_CXX_FS_HPP_
+#if !defined(ATF_CXX_DETAIL_FS_HPP)
+#define ATF_CXX_DETAIL_FS_HPP
extern "C" {
#include <sys/types.h>
@@ -42,7 +38,7 @@ extern "C" {
#include <string>
extern "C" {
-#include "../../atf-c/detail/fs.h"
+#include "atf-c/detail/fs.h"
}
namespace atf {
@@ -388,4 +384,4 @@ void rmdir(const path&);
} // namespace fs
} // namespace atf
-#endif // !defined(_ATF_CXX_FS_HPP_)
+#endif // !defined(ATF_CXX_DETAIL_FS_HPP)
diff --git a/contrib/atf/atf-c++/detail/fs_test.cpp b/contrib/atf/atf-c++/detail/fs_test.cpp
index 6cf9bf6..bf64ab2 100644
--- a/contrib/atf/atf-c++/detail/fs_test.cpp
+++ b/contrib/atf/atf-c++/detail/fs_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,8 @@
// 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.
-//
+
+#include "atf-c++/detail/fs.hpp"
extern "C" {
#include <sys/types.h>
@@ -36,10 +34,9 @@ extern "C" {
#include <cerrno>
#include <cstdio>
-#include "../macros.hpp"
+#include <atf-c++.hpp>
-#include "exceptions.hpp"
-#include "fs.hpp"
+#include "atf-c++/detail/exceptions.hpp"
// ------------------------------------------------------------------------
// Auxiliary functions.
diff --git a/contrib/atf/atf-c++/detail/process.cpp b/contrib/atf/atf-c++/detail/process.cpp
index f7ae6d4..8139536 100644
--- a/contrib/atf/atf-c++/detail/process.cpp
+++ b/contrib/atf/atf-c++/detail/process.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2008 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,21 +22,20 @@
// 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.
-//
+
+#include "atf-c++/detail/process.hpp"
extern "C" {
#include <signal.h>
-#include "../../atf-c/error.h"
-
-#include "../../atf-c/detail/process.h"
+#include "atf-c/detail/process.h"
+#include "atf-c/error.h"
}
#include <iostream>
-#include "exceptions.hpp"
-#include "process.hpp"
-#include "sanity.hpp"
+#include "atf-c++/detail/exceptions.hpp"
+#include "atf-c++/detail/sanity.hpp"
namespace detail = atf::process::detail;
namespace impl = atf::process;
@@ -341,11 +337,6 @@ impl::child::stderr_fd(void)
void
detail::flush_streams(void)
{
- // This is a weird hack to ensure that the output of the parent process
- // is flushed before executing a child which prevents, for example, the
- // output of the atf-run hooks to appear before the output of atf-run
- // itself.
- //
// TODO: This should only be executed when inheriting the stdout or
// stderr file descriptors. However, the flushing is specific to the
// iostreams, so we cannot do it from the C library where all the process
diff --git a/contrib/atf/atf-c++/detail/process.hpp b/contrib/atf/atf-c++/detail/process.hpp
index bc55a57..0d4989a 100644
--- a/contrib/atf/atf-c++/detail/process.hpp
+++ b/contrib/atf/atf-c++/detail/process.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2008 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,25 +22,23 @@
// 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.
-//
-#if !defined(_ATF_CXX_PROCESS_HPP_)
-#define _ATF_CXX_PROCESS_HPP_
+#if !defined(ATF_CXX_DETAIL_PROCESS_HPP)
+#define ATF_CXX_DETAIL_PROCESS_HPP
extern "C" {
#include <sys/types.h>
-#include "../../atf-c/error.h"
-
-#include "../../atf-c/detail/process.h"
+#include <atf-c/detail/process.h>
+#include <atf-c/error.h>
}
#include <string>
#include <vector>
-#include "auto_array.hpp"
-#include "exceptions.hpp"
-#include "fs.hpp"
+#include <atf-c++/detail/auto_array.hpp>
+#include <atf-c++/detail/exceptions.hpp>
+#include <atf-c++/detail/fs.hpp>
namespace atf {
namespace process {
@@ -276,4 +271,4 @@ exec(const atf::fs::path& prog, const argv_array& argv,
} // namespace process
} // namespace atf
-#endif // !defined(_ATF_CXX_PROCESS_HPP_)
+#endif // !defined(ATF_CXX_DETAIL_PROCESS_HPP)
diff --git a/contrib/atf/atf-c++/detail/process_test.cpp b/contrib/atf/atf-c++/detail/process_test.cpp
index a40f663..0686d2a 100644
--- a/contrib/atf/atf-c++/detail/process_test.cpp
+++ b/contrib/atf/atf-c++/detail/process_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2008 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,15 +22,15 @@
// 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.
-//
+
+#include "atf-c++/detail/process.hpp"
#include <cstdlib>
#include <cstring>
-#include "../macros.hpp"
+#include <atf-c++.hpp>
-#include "process.hpp"
-#include "test_helpers.hpp"
+#include "atf-c++/detail/test_helpers.hpp"
// TODO: Testing the fork function is a huge task and I'm afraid of
// copy/pasting tons of stuff from the C version. I'd rather not do that
diff --git a/contrib/atf/atf-c++/detail/sanity.hpp b/contrib/atf/atf-c++/detail/sanity.hpp
index 6021a6e..3d89ab4 100644
--- a/contrib/atf/atf-c++/detail/sanity.hpp
+++ b/contrib/atf/atf-c++/detail/sanity.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,13 +22,12 @@
// 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.
-//
-#if !defined(_ATF_CXX_SANITY_HPP_)
-#define _ATF_CXX_SANITY_HPP_
+#if !defined(ATF_CXX_DETAIL_SANITY_HPP)
+#define ATF_CXX_DETAIL_SANITY_HPP
extern "C" {
-#include "../../atf-c/detail/sanity.h"
+#include <atf-c/detail/sanity.h>
}
-#endif // !defined(_ATF_CXX_SANITY_HPP_)
+#endif // !defined(ATF_CXX_DETAIL_SANITY_HPP)
diff --git a/contrib/atf/atf-c++/detail/sanity_test.cpp b/contrib/atf/atf-c++/detail/sanity_test.cpp
deleted file mode 100644
index 8d3a07e..0000000
--- a/contrib/atf/atf-c++/detail/sanity_test.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// Automated Testing Framework (atf)
-//
-// Copyright (c) 2009 The NetBSD Foundation, 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:
-// 1. Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// 2. 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.
-//
-// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
-//
-
-#include "../macros.hpp"
-
-ATF_TEST_CASE_WITHOUT_HEAD(nothing);
-ATF_TEST_CASE_BODY(nothing)
-{
- // TODO
-}
-
-ATF_INIT_TEST_CASES(tcs)
-{
- ATF_ADD_TEST_CASE(tcs, nothing);
-}
diff --git a/contrib/atf/atf-c++/detail/test_helpers.cpp b/contrib/atf/atf-c++/detail/test_helpers.cpp
index 38e6516..d3f9400 100644
--- a/contrib/atf/atf-c++/detail/test_helpers.cpp
+++ b/contrib/atf/atf-c++/detail/test_helpers.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2009 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,20 +22,20 @@
// 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.
-//
+
+#include "atf-c++/detail/test_helpers.hpp"
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
-#include "../check.hpp"
-#include "../config.hpp"
-#include "../macros.hpp"
+#include <atf-c++.hpp>
-#include "fs.hpp"
-#include "process.hpp"
-#include "test_helpers.hpp"
+#include "atf-c++/check.hpp"
+#include "atf-c++/detail/env.hpp"
+#include "atf-c++/detail/fs.hpp"
+#include "atf-c++/detail/process.hpp"
// Path to the directory containing the libatf-c tests, used to locate the
// process_helpers program. If NULL (the default), the code will use a
@@ -56,7 +53,7 @@ bool
build_check_cxx_o(const char* sfile)
{
std::vector< std::string > optargs;
- optargs.push_back("-I" + atf::config::get("atf_includedir"));
+ optargs.push_back("-I" + atf::env::get("ATF_INCLUDEDIR", ATF_INCLUDEDIR));
optargs.push_back("-Wall");
optargs.push_back("-Werror");
diff --git a/contrib/atf/atf-c++/detail/test_helpers.hpp b/contrib/atf/atf-c++/detail/test_helpers.hpp
index 342a07d..f166ee2 100644
--- a/contrib/atf/atf-c++/detail/test_helpers.hpp
+++ b/contrib/atf/atf-c++/detail/test_helpers.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2009 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,12 +22,11 @@
// 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.
-//
-#if defined(TESTS_ATF_ATF_CXX_TEST_HELPERS_H)
+#if defined(ATF_CXX_DETAIL_TEST_HELPERS_H)
# error "Cannot include test_helpers.hpp more than once."
#else
-# define TESTS_ATF_ATF_CXX_TEST_HELPERS_H
+# define ATF_CXX_DETAIL_TEST_HELPERS_H
#endif
#include <cstdlib>
@@ -38,9 +34,9 @@
#include <sstream>
#include <utility>
-#include "../macros.hpp"
-#include "../tests.hpp"
-#include "process.hpp"
+#include <atf-c++.hpp>
+
+#include <atf-c++/detail/process.hpp>
#define HEADER_TC(name, hdrname) \
ATF_TEST_CASE(name); \
diff --git a/contrib/atf/atf-c++/detail/text.cpp b/contrib/atf/atf-c++/detail/text.cpp
index 66eebf0..35a0bec 100644
--- a/contrib/atf/atf-c++/detail/text.cpp
+++ b/contrib/atf/atf-c++/detail/text.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,8 @@
// 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.
-//
+
+#include "atf-c++/detail/text.hpp"
extern "C" {
#include <regex.h>
@@ -35,13 +33,11 @@ extern "C" {
#include <cstring>
extern "C" {
-#include "../../atf-c/error.h"
-
-#include "../../atf-c/detail/text.h"
+#include "atf-c/detail/text.h"
+#include "atf-c/error.h"
}
-#include "exceptions.hpp"
-#include "text.hpp"
+#include "atf-c++/detail/exceptions.hpp"
namespace impl = atf::text;
#define IMPL_NAME "atf::text"
diff --git a/contrib/atf/atf-c++/detail/text.hpp b/contrib/atf/atf-c++/detail/text.hpp
index 6a1b027..63c3190 100644
--- a/contrib/atf/atf-c++/detail/text.hpp
+++ b/contrib/atf/atf-c++/detail/text.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_TEXT_HPP_)
-#define _ATF_CXX_TEXT_HPP_
+#if !defined(ATF_CXX_DETAIL_TEXT_HPP)
+#define ATF_CXX_DETAIL_TEXT_HPP
extern "C" {
#include <stdint.h>
@@ -150,4 +146,4 @@ to_type(const std::string& str)
} // namespace text
} // namespace atf
-#endif // !defined(_ATF_CXX_TEXT_HPP_)
+#endif // !defined(ATF_CXX_DETAIL_TEXT_HPP)
diff --git a/contrib/atf/atf-c++/detail/text_test.cpp b/contrib/atf/atf-c++/detail/text_test.cpp
index b7c0ba1..49d3774 100644
--- a/contrib/atf/atf-c++/detail/text_test.cpp
+++ b/contrib/atf/atf-c++/detail/text_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,15 +22,14 @@
// 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.
-//
+
+#include "atf-c++/detail/text.hpp"
#include <cstring>
#include <set>
#include <vector>
-#include "../macros.hpp"
-
-#include "text.hpp"
+#include <atf-c++.hpp>
// ------------------------------------------------------------------------
// Test cases for the free functions.
diff --git a/contrib/atf/atf-c++/detail/version_helper.cpp b/contrib/atf/atf-c++/detail/version_helper.cpp
index b1101c9..0ee4791 100644
--- a/contrib/atf/atf-c++/detail/version_helper.cpp
+++ b/contrib/atf/atf-c++/detail/version_helper.cpp
@@ -27,7 +27,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if defined(HAVE_CONFIG_H)
-#include "bconfig.h"
+#include "config.h"
#endif
#include <cstdlib>
diff --git a/contrib/atf/atf-c++/macros.hpp b/contrib/atf/atf-c++/macros.hpp
index c6ce9c2..ea0b2dc 100644
--- a/contrib/atf/atf-c++/macros.hpp
+++ b/contrib/atf/atf-c++/macros.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_MACROS_HPP_)
-#define _ATF_CXX_MACROS_HPP_
+#if !defined(ATF_CXX_MACROS_HPP)
+#define ATF_CXX_MACROS_HPP
#include <sstream>
#include <stdexcept>
@@ -99,21 +95,23 @@
#define ATF_PASS() atf::tests::tc::pass()
-#define ATF_REQUIRE(x) \
+#define ATF_REQUIRE(expression) \
do { \
- if (!(x)) { \
+ if (!(expression)) { \
std::ostringstream atfu_ss; \
- atfu_ss << "Line " << __LINE__ << ": " << #x << " not met"; \
+ atfu_ss << "Line " << __LINE__ << ": " << #expression \
+ << " not met"; \
atf::tests::tc::fail(atfu_ss.str()); \
} \
} while (false)
-#define ATF_REQUIRE_EQ(x, y) \
+#define ATF_REQUIRE_EQ(expected, actual) \
do { \
- if ((x) != (y)) { \
+ if ((expected) != (actual)) { \
std::ostringstream atfu_ss; \
- atfu_ss << "Line " << __LINE__ << ": " << #x << " != " << #y \
- << " (" << (x) << " != " << (y) << ")"; \
+ atfu_ss << "Line " << __LINE__ << ": " \
+ << #expected << " != " << #actual \
+ << " (" << (expected) << " != " << (actual) << ")"; \
atf::tests::tc::fail(atfu_ss.str()); \
} \
} while (false)
@@ -134,69 +132,74 @@
} \
} while (false)
-#define ATF_REQUIRE_THROW(e, x) \
+#define ATF_REQUIRE_THROW(expected_exception, statement) \
do { \
try { \
- x; \
+ statement; \
std::ostringstream atfu_ss; \
- atfu_ss << "Line " << __LINE__ << ": " #x " did not throw " \
- #e " as expected"; \
+ atfu_ss << "Line " << __LINE__ \
+ << ": " #statement " did not throw " #expected_exception \
+ " as expected"; \
atf::tests::tc::fail(atfu_ss.str()); \
- } catch (const e&) { \
+ } catch (const expected_exception&) { \
} catch (const std::exception& atfu_e) { \
std::ostringstream atfu_ss; \
- atfu_ss << "Line " << __LINE__ << ": " #x " threw an " \
- "unexpected error (not " #e "): " << atfu_e.what(); \
+ atfu_ss << "Line " << __LINE__ << ": " #statement " threw an " \
+ "unexpected error (not " #expected_exception "): " \
+ << atfu_e.what(); \
atf::tests::tc::fail(atfu_ss.str()); \
} catch (...) { \
std::ostringstream atfu_ss; \
- atfu_ss << "Line " << __LINE__ << ": " #x " threw an " \
- "unexpected error (not " #e ")"; \
+ atfu_ss << "Line " << __LINE__ << ": " #statement " threw an " \
+ "unexpected error (not " #expected_exception ")"; \
atf::tests::tc::fail(atfu_ss.str()); \
} \
} while (false)
-#define ATF_REQUIRE_THROW_RE(type, regexp, x) \
+#define ATF_REQUIRE_THROW_RE(expected_exception, regexp, statement) \
do { \
try { \
- x; \
+ statement; \
std::ostringstream atfu_ss; \
- atfu_ss << "Line " << __LINE__ << ": " #x " did not throw " \
- #type " as expected"; \
+ atfu_ss << "Line " << __LINE__ \
+ << ": " #statement " did not throw " #expected_exception \
+ " as expected"; \
atf::tests::tc::fail(atfu_ss.str()); \
- } catch (const type& e) { \
+ } catch (const expected_exception& e) { \
if (!atf::tests::detail::match(regexp, e.what())) { \
std::ostringstream atfu_ss; \
- atfu_ss << "Line " << __LINE__ << ": " #x " threw " #type "(" \
+ atfu_ss << "Line " << __LINE__ \
+ << ": " #statement " threw " #expected_exception "(" \
<< e.what() << "), but does not match '" << regexp \
<< "'"; \
atf::tests::tc::fail(atfu_ss.str()); \
} \
} catch (const std::exception& atfu_e) { \
std::ostringstream atfu_ss; \
- atfu_ss << "Line " << __LINE__ << ": " #x " threw an " \
- "unexpected error (not " #type "): " << atfu_e.what(); \
+ atfu_ss << "Line " << __LINE__ << ": " #statement " threw an " \
+ "unexpected error (not " #expected_exception "): " \
+ << atfu_e.what(); \
atf::tests::tc::fail(atfu_ss.str()); \
} catch (...) { \
std::ostringstream atfu_ss; \
- atfu_ss << "Line " << __LINE__ << ": " #x " threw an " \
- "unexpected error (not " #type ")"; \
+ atfu_ss << "Line " << __LINE__ << ": " #statement " threw an " \
+ "unexpected error (not " #expected_exception ")"; \
atf::tests::tc::fail(atfu_ss.str()); \
} \
} while (false)
-#define ATF_CHECK_ERRNO(exp_errno, bool_expr) \
- atf::tests::tc::check_errno(__FILE__, __LINE__, exp_errno, #bool_expr, \
- bool_expr)
+#define ATF_CHECK_ERRNO(expected_errno, bool_expr) \
+ atf::tests::tc::check_errno(__FILE__, __LINE__, expected_errno, \
+ #bool_expr, bool_expr)
-#define ATF_REQUIRE_ERRNO(exp_errno, bool_expr) \
- atf::tests::tc::require_errno(__FILE__, __LINE__, exp_errno, #bool_expr, \
- bool_expr)
+#define ATF_REQUIRE_ERRNO(expected_errno, bool_expr) \
+ atf::tests::tc::require_errno(__FILE__, __LINE__, expected_errno, \
+ #bool_expr, bool_expr)
#define ATF_INIT_TEST_CASES(tcs) \
namespace atf { \
namespace tests { \
- int run_tp(int, char* const*, \
+ int run_tp(int, char**, \
void (*)(std::vector< atf::tests::tc * >&)); \
} \
} \
@@ -204,7 +207,7 @@
static void atfu_init_tcs(std::vector< atf::tests::tc * >&); \
\
int \
- main(int argc, char* const* argv) \
+ main(int argc, char** argv) \
{ \
return atf::tests::run_tp(argc, argv, atfu_init_tcs); \
} \
@@ -219,4 +222,4 @@
(tcs).push_back(atfu_tcptr_ ## tcname); \
} while (0);
-#endif // !defined(_ATF_CXX_MACROS_HPP_)
+#endif // !defined(ATF_CXX_MACROS_HPP)
diff --git a/contrib/atf/atf-c++/macros_hpp_test.cpp b/contrib/atf/atf-c++/macros_hpp_test.cpp
index 2cb7536..0bc27c6 100644
--- a/contrib/atf/atf-c++/macros_hpp_test.cpp
+++ b/contrib/atf/atf-c++/macros_hpp_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2008 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,12 +22,11 @@
// 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.
-//
-
-#include <stdexcept>
#include <atf-c++/macros.hpp>
+#include <stdexcept>
+
void
atf_check_errno_semicolons(void)
{
diff --git a/contrib/atf/atf-c++/macros_test.cpp b/contrib/atf/atf-c++/macros_test.cpp
index 4113ed0..23b5e5c 100644
--- a/contrib/atf/atf-c++/macros_test.cpp
+++ b/contrib/atf/atf-c++/macros_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2008 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,8 @@
// 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.
-//
+
+#include "atf-c++/macros.hpp"
extern "C" {
#include <fcntl.h>
@@ -37,14 +35,14 @@ extern "C" {
#include <iostream>
#include <stdexcept>
-#include "macros.hpp"
-#include "utils.hpp"
+#include <atf-c++.hpp>
-#include "detail/fs.hpp"
-#include "detail/process.hpp"
-#include "detail/sanity.hpp"
-#include "detail/test_helpers.hpp"
-#include "detail/text.hpp"
+#include "atf-c++/detail/fs.hpp"
+#include "atf-c++/detail/process.hpp"
+#include "atf-c++/detail/sanity.hpp"
+#include "atf-c++/detail/test_helpers.hpp"
+#include "atf-c++/detail/text.hpp"
+#include "atf-c++/utils.hpp"
// ------------------------------------------------------------------------
// Auxiliary functions.
@@ -757,7 +755,6 @@ ATF_TEST_CASE_BODY(require_errno)
// Tests cases for the header file.
// ------------------------------------------------------------------------
-HEADER_TC(include, "atf-c++/macros.hpp");
BUILD_TC(use, "macros_hpp_test.cpp",
"Tests that the macros provided by the atf-c++/macros.hpp file "
"do not cause syntax errors when used",
@@ -809,7 +806,6 @@ ATF_INIT_TEST_CASES(tcs)
ATF_ADD_TEST_CASE(tcs, require_errno);
// Add the test cases for the header file.
- ATF_ADD_TEST_CASE(tcs, include);
ATF_ADD_TEST_CASE(tcs, use);
ATF_ADD_TEST_CASE(tcs, detect_unused_tests);
}
diff --git a/contrib/atf/atf-c++/pkg_config_test.sh b/contrib/atf/atf-c++/pkg_config_test.sh
index d0b0656..af541f6 100644
--- a/contrib/atf/atf-c++/pkg_config_test.sh
+++ b/contrib/atf/atf-c++/pkg_config_test.sh
@@ -1,6 +1,3 @@
-#
-# Automated Testing Framework (atf)
-#
# Copyright (c) 2008 The NetBSD Foundation, Inc.
# All rights reserved.
#
@@ -25,7 +22,6 @@
# 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.
-#
# The following tests assume that the atfc++.pc file is installed in a
# directory that is known by pkg-config. Otherwise they will fail,
diff --git a/contrib/atf/atf-c++/tests.cpp b/contrib/atf/atf-c++/tests.cpp
index 801ed7c..ede9609 100644
--- a/contrib/atf/atf-c++/tests.cpp
+++ b/contrib/atf/atf-c++/tests.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,12 @@
// 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.
-//
+
+#include "atf-c++/tests.hpp"
+
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#endif
extern "C" {
#include <sys/types.h>
@@ -55,20 +57,26 @@ extern "C" {
#include "atf-c/utils.h"
}
-#include "tests.hpp"
+#include "atf-c++/detail/application.hpp"
+#include "atf-c++/detail/auto_array.hpp"
+#include "atf-c++/detail/env.hpp"
+#include "atf-c++/detail/exceptions.hpp"
+#include "atf-c++/detail/fs.hpp"
+#include "atf-c++/detail/sanity.hpp"
+#include "atf-c++/detail/text.hpp"
-#include "detail/application.hpp"
-#include "detail/auto_array.hpp"
-#include "detail/env.hpp"
-#include "detail/exceptions.hpp"
-#include "detail/fs.hpp"
-#include "detail/sanity.hpp"
-#include "detail/text.hpp"
+#if defined(HAVE_GNU_GETOPT)
+# define GETOPT_POSIX "+"
+#else
+# define GETOPT_POSIX ""
+#endif
namespace impl = atf::tests;
namespace detail = atf::tests::detail;
#define IMPL_NAME "atf::tests"
+using atf::application::usage_error;
+
// ------------------------------------------------------------------------
// The "atf_tp_writer" class.
// ------------------------------------------------------------------------
@@ -109,6 +117,21 @@ detail::atf_tp_writer::tc_meta_data(const std::string& name,
// Free helper functions.
// ------------------------------------------------------------------------
+std::string Program_Name;
+
+static void
+set_program_name(const char* argv0)
+{
+ const std::string program_name = atf::fs::path(argv0).leaf_name();
+ // Libtool workaround: if running from within the source tree (binaries
+ // that are not installed yet), skip the "lt-" prefix added to files in
+ // the ".libs" directory to show the real (not temporary) name.
+ if (program_name.substr(0, 3) == "lt-")
+ Program_Name = program_name.substr(3);
+ else
+ Program_Name = program_name;
+}
+
bool
detail::match(const std::string& regexp, const std::string& str)
{
@@ -153,14 +176,7 @@ public:
std::map< const atf_tc_t*, const impl::tc* >::const_iterator iter =
cwraps.find(tc);
INV(iter != cwraps.end());
- try {
- (*iter).second->body();
- } catch (const std::exception& e) {
- (*iter).second->fail("Caught unhandled exception: " + std::string(
- e.what()));
- } catch (...) {
- (*iter).second->fail("Caught unknown exception");
- }
+ (*iter).second->body();
}
static void
@@ -384,197 +400,70 @@ impl::tc::expect_timeout(const std::string& reason)
}
// ------------------------------------------------------------------------
-// The "tp" class.
+// Test program main code.
// ------------------------------------------------------------------------
-class tp : public atf::application::app {
-public:
- typedef std::vector< impl::tc * > tc_vector;
-
-private:
- static const char* m_description;
-
- bool m_lflag;
- atf::fs::path m_resfile;
- std::string m_srcdir_arg;
- atf::fs::path m_srcdir;
-
- atf::tests::vars_map m_vars;
-
- std::string specific_args(void) const;
- options_set specific_options(void) const;
- void process_option(int, const char*);
-
- void (*m_add_tcs)(tc_vector&);
- tc_vector m_tcs;
-
- void parse_vflag(const std::string&);
- void handle_srcdir(void);
-
- tc_vector init_tcs(void);
-
- enum tc_part {
- BODY,
- CLEANUP,
- };
+namespace {
- void list_tcs(void);
- impl::tc* find_tc(tc_vector, const std::string&);
- static std::pair< std::string, tc_part > process_tcarg(const std::string&);
- int run_tc(const std::string&);
+typedef std::vector< impl::tc * > tc_vector;
-public:
- tp(void (*)(tc_vector&));
- ~tp(void);
-
- int main(void);
-};
-
-const char* tp::m_description =
- "This is an independent atf test program.";
-
-tp::tp(void (*add_tcs)(tc_vector&)) :
- app(m_description, "atf-test-program(1)"),
- m_lflag(false),
- m_resfile("/dev/stdout"),
- m_srcdir("."),
- m_add_tcs(add_tcs)
-{
-}
+enum tc_part { BODY, CLEANUP };
-tp::~tp(void)
-{
- for (tc_vector::iterator iter = m_tcs.begin();
- iter != m_tcs.end(); iter++) {
- impl::tc* tc = *iter;
-
- delete tc;
- }
-}
-
-std::string
-tp::specific_args(void)
- const
-{
- return "test_case";
-}
-
-tp::options_set
-tp::specific_options(void)
- const
-{
- using atf::application::option;
- options_set opts;
- opts.insert(option('l', "", "List test cases and their purpose"));
- opts.insert(option('r', "resfile", "The file to which the test program "
- "will write the results of the "
- "executed test case"));
- opts.insert(option('s', "srcdir", "Directory where the test's data "
- "files are located"));
- opts.insert(option('v', "var=value", "Sets the configuration variable "
- "`var' to `value'"));
- return opts;
-}
-
-void
-tp::process_option(int ch, const char* arg)
-{
- switch (ch) {
- case 'l':
- m_lflag = true;
- break;
-
- case 'r':
- m_resfile = atf::fs::path(arg);
- break;
-
- case 's':
- m_srcdir_arg = arg;
- break;
-
- case 'v':
- parse_vflag(arg);
- break;
-
- default:
- UNREACHABLE;
- }
-}
-
-void
-tp::parse_vflag(const std::string& str)
+static void
+parse_vflag(const std::string& str, atf::tests::vars_map& vars)
{
if (str.empty())
throw std::runtime_error("-v requires a non-empty argument");
std::vector< std::string > ws = atf::text::split(str, "=");
if (ws.size() == 1 && str[str.length() - 1] == '=') {
- m_vars[ws[0]] = "";
+ vars[ws[0]] = "";
} else {
if (ws.size() != 2)
throw std::runtime_error("-v requires an argument of the form "
"var=value");
- m_vars[ws[0]] = ws[1];
+ vars[ws[0]] = ws[1];
}
}
-void
-tp::handle_srcdir(void)
+static atf::fs::path
+handle_srcdir(const char* argv0, const std::string& srcdir_arg)
{
- if (m_srcdir_arg.empty()) {
- m_srcdir = atf::fs::path(m_argv0).branch_path();
- if (m_srcdir.leaf_name() == ".libs")
- m_srcdir = m_srcdir.branch_path();
+ atf::fs::path srcdir(".");
+
+ if (srcdir_arg.empty()) {
+ srcdir = atf::fs::path(argv0).branch_path();
+ if (srcdir.leaf_name() == ".libs")
+ srcdir = srcdir.branch_path();
} else
- m_srcdir = atf::fs::path(m_srcdir_arg);
+ srcdir = atf::fs::path(srcdir_arg);
- if (!atf::fs::exists(m_srcdir / m_prog_name))
- throw std::runtime_error("Cannot find the test program in the "
- "source directory `" + m_srcdir.str() + "'");
+ if (!atf::fs::exists(srcdir / Program_Name))
+ throw usage_error("Cannot find the test program in the source "
+ "directory `%s'", srcdir.c_str());
- if (!m_srcdir.is_absolute())
- m_srcdir = m_srcdir.to_absolute();
+ if (!srcdir.is_absolute())
+ srcdir = srcdir.to_absolute();
- m_vars["srcdir"] = m_srcdir.str();
+ return srcdir;
}
-tp::tc_vector
-tp::init_tcs(void)
+static void
+init_tcs(void (*add_tcs)(tc_vector&), tc_vector& tcs,
+ const atf::tests::vars_map& vars)
{
- m_add_tcs(m_tcs);
- for (tc_vector::iterator iter = m_tcs.begin();
- iter != m_tcs.end(); iter++) {
+ add_tcs(tcs);
+ for (tc_vector::iterator iter = tcs.begin(); iter != tcs.end(); iter++) {
impl::tc* tc = *iter;
- tc->init(m_vars);
+ tc->init(vars);
}
- return m_tcs;
}
-//
-// An auxiliary unary predicate that compares the given test case's
-// identifier to the identifier stored in it.
-//
-class tc_equal_to_ident {
- const std::string& m_ident;
-
-public:
- tc_equal_to_ident(const std::string& i) :
- m_ident(i)
- {
- }
-
- bool operator()(const impl::tc* tc)
- {
- return tc->get_md_var("ident") == m_ident;
- }
-};
-
-void
-tp::list_tcs(void)
+static int
+list_tcs(const tc_vector& tcs)
{
- tc_vector tcs = init_tcs();
detail::atf_tp_writer writer(std::cout);
for (tc_vector::const_iterator iter = tcs.begin();
@@ -596,10 +485,12 @@ tp::list_tcs(void)
writer.end_tc();
}
+
+ return EXIT_SUCCESS;
}
-impl::tc*
-tp::find_tc(tc_vector tcs, const std::string& name)
+static impl::tc*
+find_tc(tc_vector tcs, const std::string& name)
{
std::vector< std::string > ids;
for (tc_vector::iterator iter = tcs.begin();
@@ -609,12 +500,11 @@ tp::find_tc(tc_vector tcs, const std::string& name)
if (tc->get_md_var("ident") == name)
return tc;
}
- throw atf::application::usage_error("Unknown test case `%s'",
- name.c_str());
+ throw usage_error("Unknown test case `%s'", name.c_str());
}
-std::pair< std::string, tp::tc_part >
-tp::process_tcarg(const std::string& tcarg)
+static std::pair< std::string, tc_part >
+process_tcarg(const std::string& tcarg)
{
const std::string::size_type pos = tcarg.find(':');
if (pos == std::string::npos) {
@@ -628,83 +518,141 @@ tp::process_tcarg(const std::string& tcarg)
else if (partname == "cleanup")
return std::make_pair(tcname, CLEANUP);
else {
- using atf::application::usage_error;
throw usage_error("Invalid test case part `%s'", partname.c_str());
}
}
}
-int
-tp::run_tc(const std::string& tcarg)
+static int
+run_tc(tc_vector& tcs, const std::string& tcarg, const atf::fs::path& resfile)
{
const std::pair< std::string, tc_part > fields = process_tcarg(tcarg);
- impl::tc* tc = find_tc(init_tcs(), fields.first);
+ impl::tc* tc = find_tc(tcs, fields.first);
if (!atf::env::has("__RUNNING_INSIDE_ATF_RUN") || atf::env::get(
"__RUNNING_INSIDE_ATF_RUN") != "internal-yes-value")
{
- std::cerr << m_prog_name << ": WARNING: Running test cases without "
- "atf-run(1) is unsupported\n";
- std::cerr << m_prog_name << ": WARNING: No isolation nor timeout "
+ std::cerr << Program_Name << ": WARNING: Running test cases outside "
+ "of kyua(1) is unsupported\n";
+ std::cerr << Program_Name << ": WARNING: No isolation nor timeout "
"control is being applied; you may get unexpected failures; see "
"atf-test-case(4)\n";
}
- try {
- switch (fields.second) {
- case BODY:
- tc->run(m_resfile.str());
+ switch (fields.second) {
+ case BODY:
+ tc->run(resfile.str());
+ break;
+ case CLEANUP:
+ tc->run_cleanup();
+ break;
+ default:
+ UNREACHABLE;
+ }
+ return EXIT_SUCCESS;
+}
+
+static int
+safe_main(int argc, char** argv, void (*add_tcs)(tc_vector&))
+{
+ const char* argv0 = argv[0];
+
+ bool lflag = false;
+ atf::fs::path resfile("/dev/stdout");
+ std::string srcdir_arg;
+ atf::tests::vars_map vars;
+
+ int ch;
+ int old_opterr;
+
+ old_opterr = opterr;
+ ::opterr = 0;
+ while ((ch = ::getopt(argc, argv, GETOPT_POSIX ":lr:s:v:")) != -1) {
+ switch (ch) {
+ case 'l':
+ lflag = true;
+ break;
+
+ case 'r':
+ resfile = atf::fs::path(::optarg);
break;
- case CLEANUP:
- tc->run_cleanup();
+
+ case 's':
+ srcdir_arg = ::optarg;
+ break;
+
+ case 'v':
+ parse_vflag(::optarg, vars);
break;
+
+ case ':':
+ throw usage_error("Option -%c requires an argument.", ::optopt);
+ break;
+
+ case '?':
default:
- UNREACHABLE;
+ throw usage_error("Unknown option -%c.", ::optopt);
}
- return EXIT_SUCCESS;
- } catch (const std::runtime_error& e) {
- std::cerr << "ERROR: " << e.what() << "\n";
- return EXIT_FAILURE;
}
-}
+ argc -= optind;
+ argv += optind;
-int
-tp::main(void)
-{
- using atf::application::usage_error;
+ // Clear getopt state just in case the test wants to use it.
+ ::opterr = old_opterr;
+ ::optind = 1;
+#if defined(HAVE_OPTRESET)
+ ::optreset = 1;
+#endif
- int errcode;
+ vars["srcdir"] = handle_srcdir(argv0, srcdir_arg).str();
- handle_srcdir();
+ int errcode;
- if (m_lflag) {
- if (m_argc > 0)
+ tc_vector tcs;
+ if (lflag) {
+ if (argc > 0)
throw usage_error("Cannot provide test case names with -l");
- list_tcs();
- errcode = EXIT_SUCCESS;
+ init_tcs(add_tcs, tcs, vars);
+ errcode = list_tcs(tcs);
} else {
- if (m_argc == 0)
+ if (argc == 0)
throw usage_error("Must provide a test case name");
- else if (m_argc > 1)
+ else if (argc > 1)
throw usage_error("Cannot provide more than one test case name");
- INV(m_argc == 1);
+ INV(argc == 1);
- errcode = run_tc(m_argv[0]);
+ init_tcs(add_tcs, tcs, vars);
+ errcode = run_tc(tcs, argv[0], resfile);
+ }
+ for (tc_vector::iterator iter = tcs.begin(); iter != tcs.end(); iter++) {
+ impl::tc* tc = *iter;
+
+ delete tc;
}
return errcode;
}
+} // anonymous namespace
+
namespace atf {
namespace tests {
- int run_tp(int, char* const*, void (*)(tp::tc_vector&));
+ int run_tp(int, char**, void (*)(tc_vector&));
}
}
int
-impl::run_tp(int argc, char* const* argv, void (*add_tcs)(tp::tc_vector&))
+impl::run_tp(int argc, char** argv, void (*add_tcs)(tc_vector&))
{
- return tp(add_tcs).run(argc, argv);
+ try {
+ set_program_name(argv[0]);
+ return ::safe_main(argc, argv, add_tcs);
+ } catch (const usage_error& e) {
+ std::cerr
+ << Program_Name << ": ERROR: " << e.what() << '\n'
+ << Program_Name << ": See atf-test-program(1) for usage details.\n";
+ return EXIT_FAILURE;
+ }
}
diff --git a/contrib/atf/atf-c++/tests.hpp b/contrib/atf/atf-c++/tests.hpp
index 4c8ca91..ce2fb1d 100644
--- a/contrib/atf/atf-c++/tests.hpp
+++ b/contrib/atf/atf-c++/tests.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_TESTS_HPP_)
-#define _ATF_CXX_TESTS_HPP_
+#if !defined(ATF_CXX_TESTS_HPP)
+#define ATF_CXX_TESTS_HPP
#include <map>
#include <memory>
@@ -126,4 +122,4 @@ public:
} // namespace tests
} // namespace atf
-#endif // !defined(_ATF_CXX_TESTS_HPP_)
+#endif // !defined(ATF_CXX_TESTS_HPP)
diff --git a/contrib/atf/atf-c++/tests_test.cpp b/contrib/atf/atf-c++/tests_test.cpp
index 5f19a4e..ed9fef0 100644
--- a/contrib/atf/atf-c++/tests_test.cpp
+++ b/contrib/atf/atf-c++/tests_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,8 @@
// 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.
-//
+
+#include "atf-c++/tests.hpp"
extern "C" {
#include <sys/types.h>
@@ -36,12 +34,12 @@ extern "C" {
}
#include <fstream>
+#include <iostream>
#include <sstream>
-#include "macros.hpp"
+#include <atf-c++.hpp>
-#include "detail/test_helpers.hpp"
-#include "detail/text.hpp"
+#include "atf-c++/detail/text.hpp"
// ------------------------------------------------------------------------
// Tests for the "atf_tp_writer" class.
@@ -182,12 +180,6 @@ ATF_TEST_CASE_BODY(atf_tp_writer)
}
// ------------------------------------------------------------------------
-// Tests cases for the header file.
-// ------------------------------------------------------------------------
-
-HEADER_TC(include, "atf-c++/tests.hpp");
-
-// ------------------------------------------------------------------------
// Main.
// ------------------------------------------------------------------------
@@ -195,7 +187,4 @@ ATF_INIT_TEST_CASES(tcs)
{
// Add tests for the "atf_tp_writer" class.
ATF_ADD_TEST_CASE(tcs, atf_tp_writer);
-
- // Add the test cases for the header file.
- ATF_ADD_TEST_CASE(tcs, include);
}
diff --git a/contrib/atf/atf-c++/unused_test.cpp b/contrib/atf/atf-c++/unused_test.cpp
index 2a18a45..1a577e1 100644
--- a/contrib/atf/atf-c++/unused_test.cpp
+++ b/contrib/atf/atf-c++/unused_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2012 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,9 +22,8 @@
// 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.
-//
-#include <atf-c++/macros.hpp>
+#include <atf-c++.hpp>
ATF_TEST_CASE(this_is_used);
ATF_TEST_CASE_HEAD(this_is_used)
diff --git a/contrib/atf/atf-c++/utils.cpp b/contrib/atf/atf-c++/utils.cpp
index cc338bb..a6ab08f 100644
--- a/contrib/atf/atf-c++/utils.cpp
+++ b/contrib/atf/atf-c++/utils.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,8 @@
// 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.
-//
+
+#include "atf-c++/utils.hpp"
extern "C" {
#include "atf-c/utils.h"
@@ -34,8 +32,6 @@ extern "C" {
#include <cstdlib>
#include <iostream>
-#include "utils.hpp"
-
void
atf::utils::cat_file(const std::string& path, const std::string& prefix)
{
diff --git a/contrib/atf/atf-c++/utils.hpp b/contrib/atf/atf-c++/utils.hpp
index b8596ae..8f5c5e3 100644
--- a/contrib/atf/atf-c++/utils.hpp
+++ b/contrib/atf/atf-c++/utils.hpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,10 +22,9 @@
// 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.
-//
-#if !defined(_ATF_CXX_UTILS_HPP_)
-#define _ATF_CXX_UTILS_HPP_
+#if !defined(ATF_CXX_UTILS_HPP)
+#define ATF_CXX_UTILS_HPP
extern "C" {
#include <unistd.h>
@@ -65,4 +61,4 @@ grep_collection(const std::string& regexp, const Collection& collection)
} // namespace utils
} // namespace atf
-#endif // !defined(_ATF_CXX_UTILS_HPP_)
+#endif // !defined(ATF_CXX_UTILS_HPP)
diff --git a/contrib/atf/atf-c++/utils_test.cpp b/contrib/atf/atf-c++/utils_test.cpp
index 37457ff..34e0709 100644
--- a/contrib/atf/atf-c++/utils_test.cpp
+++ b/contrib/atf/atf-c++/utils_test.cpp
@@ -1,6 +1,3 @@
-//
-// Automated Testing Framework (atf)
-//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
@@ -25,7 +22,8 @@
// 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.
-//
+
+#include "atf-c++/utils.hpp"
extern "C" {
#include <sys/stat.h>
@@ -38,22 +36,20 @@ extern "C" {
#include <cstdlib>
#include <iostream>
#include <set>
+#include <sstream>
#include <string>
#include <vector>
-#include "macros.hpp"
-#include "utils.hpp"
-
-#include "detail/test_helpers.hpp"
+#include <atf-c++.hpp>
static std::string
-read_file(const char *path)
+read_file(const std::string& path)
{
char buffer[1024];
- const int fd = open(path, O_RDONLY);
+ const int fd = open(path.c_str(), O_RDONLY);
if (fd == -1)
- ATF_FAIL("Cannot open " + std::string(path));
+ ATF_FAIL("Cannot open " + path);
const ssize_t length = read(fd, buffer, sizeof(buffer) - 1);
close(fd);
ATF_REQUIRE(length != -1);
@@ -238,8 +234,13 @@ ATF_TEST_CASE_BODY(fork)
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
- ATF_REQUIRE_EQ("Child stdout\n", read_file("atf_utils_fork_out.txt"));
- ATF_REQUIRE_EQ("Child stderr\n", read_file("atf_utils_fork_err.txt"));
+ std::ostringstream out_name;
+ out_name << "atf_utils_fork_" << pid << "_out.txt";
+ std::ostringstream err_name;
+ err_name << "atf_utils_fork_" << pid << "_err.txt";
+
+ ATF_REQUIRE_EQ("Child stdout\n", read_file(out_name.str()));
+ ATF_REQUIRE_EQ("Child stderr\n", read_file(err_name.str()));
}
ATF_TEST_CASE_WITHOUT_HEAD(grep_collection__set);
@@ -353,6 +354,35 @@ ATF_TEST_CASE_BODY(wait__ok)
}
}
+ATF_TEST_CASE_WITHOUT_HEAD(wait__ok_nested);
+ATF_TEST_CASE_BODY(wait__ok_nested)
+{
+ const pid_t parent = atf::utils::fork();
+ ATF_REQUIRE(parent != -1);
+ if (parent == 0) {
+ const pid_t child = atf::utils::fork();
+ ATF_REQUIRE(child != -1);
+ if (child == 0) {
+ std::cerr.flush();
+ std::cout << "Child output\n";
+ std::cout.flush();
+ std::cerr << "Child error\n";
+ std::exit(50);
+ } else {
+ std::cout << "Parent output\n";
+ std::cerr << "Parent error\n";
+ atf::utils::wait(child, 50, "Child output\n", "Child error\n");
+ std::exit(40);
+ }
+ } else {
+ atf::utils::wait(parent, 40,
+ "Parent output\n"
+ "subprocess stdout: Child output\n"
+ "subprocess stderr: Child error\n",
+ "Parent error\n");
+ }
+}
+
ATF_TEST_CASE_WITHOUT_HEAD(wait__invalid_exitstatus);
ATF_TEST_CASE_BODY(wait__invalid_exitstatus)
{
@@ -433,12 +463,6 @@ ATF_TEST_CASE_BODY(wait__save_stderr)
}
// ------------------------------------------------------------------------
-// Tests cases for the header file.
-// ------------------------------------------------------------------------
-
-HEADER_TC(include, "atf-c++/utils.hpp");
-
-// ------------------------------------------------------------------------
// Main.
// ------------------------------------------------------------------------
@@ -476,12 +500,10 @@ ATF_INIT_TEST_CASES(tcs)
ATF_ADD_TEST_CASE(tcs, redirect__other);
ATF_ADD_TEST_CASE(tcs, wait__ok);
+ ATF_ADD_TEST_CASE(tcs, wait__ok_nested);
ATF_ADD_TEST_CASE(tcs, wait__invalid_exitstatus);
ATF_ADD_TEST_CASE(tcs, wait__invalid_stdout);
ATF_ADD_TEST_CASE(tcs, wait__invalid_stderr);
ATF_ADD_TEST_CASE(tcs, wait__save_stdout);
ATF_ADD_TEST_CASE(tcs, wait__save_stderr);
-
- // Add the test cases for the header file.
- ATF_ADD_TEST_CASE(tcs, include);
}
OpenPOWER on IntegriCloud