xref: /minix3/external/bsd/atf/dist/atf-c++/detail/process_test.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
111be35a1SLionel Sambuc //
211be35a1SLionel Sambuc // Automated Testing Framework (atf)
311be35a1SLionel Sambuc //
411be35a1SLionel Sambuc // Copyright (c) 2008 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc // All rights reserved.
611be35a1SLionel Sambuc //
711be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
811be35a1SLionel Sambuc // modification, are permitted provided that the following conditions
911be35a1SLionel Sambuc // are met:
1011be35a1SLionel Sambuc // 1. Redistributions of source code must retain the above copyright
1111be35a1SLionel Sambuc //    notice, this list of conditions and the following disclaimer.
1211be35a1SLionel Sambuc // 2. Redistributions in binary form must reproduce the above copyright
1311be35a1SLionel Sambuc //    notice, this list of conditions and the following disclaimer in the
1411be35a1SLionel Sambuc //    documentation and/or other materials provided with the distribution.
1511be35a1SLionel Sambuc //
1611be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1711be35a1SLionel Sambuc // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1811be35a1SLionel Sambuc // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1911be35a1SLionel Sambuc // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2011be35a1SLionel Sambuc // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
2111be35a1SLionel Sambuc // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2211be35a1SLionel Sambuc // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2311be35a1SLionel Sambuc // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2411be35a1SLionel Sambuc // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2511be35a1SLionel Sambuc // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2611be35a1SLionel Sambuc // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2711be35a1SLionel Sambuc // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2811be35a1SLionel Sambuc //
2911be35a1SLionel Sambuc 
3011be35a1SLionel Sambuc #include <cstdlib>
3111be35a1SLionel Sambuc #include <cstring>
3211be35a1SLionel Sambuc 
3311be35a1SLionel Sambuc #include "../macros.hpp"
3411be35a1SLionel Sambuc 
3511be35a1SLionel Sambuc #include "process.hpp"
3611be35a1SLionel Sambuc #include "test_helpers.hpp"
3711be35a1SLionel Sambuc 
3811be35a1SLionel Sambuc // TODO: Testing the fork function is a huge task and I'm afraid of
3911be35a1SLionel Sambuc // copy/pasting tons of stuff from the C version.  I'd rather not do that
4011be35a1SLionel Sambuc // until some code can be shared, which cannot happen until the C++ binding
4111be35a1SLionel Sambuc // is cleaned by a fair amount.  Instead... just rely (at the moment) on
4211be35a1SLionel Sambuc // the system tests for the tools using this module.
4311be35a1SLionel Sambuc 
4411be35a1SLionel Sambuc // ------------------------------------------------------------------------
4511be35a1SLionel Sambuc // Auxiliary functions.
4611be35a1SLionel Sambuc // ------------------------------------------------------------------------
4711be35a1SLionel Sambuc 
4811be35a1SLionel Sambuc static
4911be35a1SLionel Sambuc std::size_t
array_size(const char * const * array)5011be35a1SLionel Sambuc array_size(const char* const* array)
5111be35a1SLionel Sambuc {
5211be35a1SLionel Sambuc     std::size_t size = 0;
5311be35a1SLionel Sambuc 
5411be35a1SLionel Sambuc     for (const char* const* ptr = array; *ptr != NULL; ptr++)
5511be35a1SLionel Sambuc         size++;
5611be35a1SLionel Sambuc 
5711be35a1SLionel Sambuc     return size;
5811be35a1SLionel Sambuc }
5911be35a1SLionel Sambuc 
6011be35a1SLionel Sambuc static
6111be35a1SLionel Sambuc atf::process::status
exec_process_helpers(const atf::tests::tc & tc,const char * helper_name)6211be35a1SLionel Sambuc exec_process_helpers(const atf::tests::tc& tc, const char* helper_name)
6311be35a1SLionel Sambuc {
6411be35a1SLionel Sambuc     using atf::process::exec;
6511be35a1SLionel Sambuc 
6611be35a1SLionel Sambuc     std::vector< std::string > argv;
67*0a6a1f1dSLionel Sambuc     argv.push_back(get_process_helpers_path(tc, true).leaf_name());
6811be35a1SLionel Sambuc     argv.push_back(helper_name);
6911be35a1SLionel Sambuc 
70*0a6a1f1dSLionel Sambuc     return exec(get_process_helpers_path(tc, true),
7111be35a1SLionel Sambuc                 atf::process::argv_array(argv),
7211be35a1SLionel Sambuc                 atf::process::stream_inherit(),
7311be35a1SLionel Sambuc                 atf::process::stream_inherit());
7411be35a1SLionel Sambuc }
7511be35a1SLionel Sambuc 
7611be35a1SLionel Sambuc // ------------------------------------------------------------------------
7711be35a1SLionel Sambuc // Tests for the "argv_array" type.
7811be35a1SLionel Sambuc // ------------------------------------------------------------------------
7911be35a1SLionel Sambuc 
8011be35a1SLionel Sambuc ATF_TEST_CASE(argv_array_init_carray);
ATF_TEST_CASE_HEAD(argv_array_init_carray)8111be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(argv_array_init_carray)
8211be35a1SLionel Sambuc {
8311be35a1SLionel Sambuc     set_md_var("descr", "Tests that argv_array is correctly constructed "
8411be35a1SLionel Sambuc                "from a C-style array of strings");
8511be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(argv_array_init_carray)8611be35a1SLionel Sambuc ATF_TEST_CASE_BODY(argv_array_init_carray)
8711be35a1SLionel Sambuc {
8811be35a1SLionel Sambuc     {
8911be35a1SLionel Sambuc         const char* const carray[] = { NULL };
9011be35a1SLionel Sambuc         atf::process::argv_array argv(carray);
9111be35a1SLionel Sambuc 
9211be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv.size(), 0);
9311be35a1SLionel Sambuc     }
9411be35a1SLionel Sambuc 
9511be35a1SLionel Sambuc     {
9611be35a1SLionel Sambuc         const char* const carray[] = { "arg0", NULL };
9711be35a1SLionel Sambuc         atf::process::argv_array argv(carray);
9811be35a1SLionel Sambuc 
9911be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv.size(), 1);
10011be35a1SLionel Sambuc         ATF_REQUIRE(std::strcmp(argv[0], carray[0]) == 0);
10111be35a1SLionel Sambuc     }
10211be35a1SLionel Sambuc 
10311be35a1SLionel Sambuc     {
10411be35a1SLionel Sambuc         const char* const carray[] = { "arg0", "arg1", "arg2", NULL };
10511be35a1SLionel Sambuc         atf::process::argv_array argv(carray);
10611be35a1SLionel Sambuc 
10711be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv.size(), 3);
10811be35a1SLionel Sambuc         ATF_REQUIRE(std::strcmp(argv[0], carray[0]) == 0);
10911be35a1SLionel Sambuc         ATF_REQUIRE(std::strcmp(argv[1], carray[1]) == 0);
11011be35a1SLionel Sambuc         ATF_REQUIRE(std::strcmp(argv[2], carray[2]) == 0);
11111be35a1SLionel Sambuc     }
11211be35a1SLionel Sambuc }
11311be35a1SLionel Sambuc 
11411be35a1SLionel Sambuc ATF_TEST_CASE(argv_array_init_col);
ATF_TEST_CASE_HEAD(argv_array_init_col)11511be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(argv_array_init_col)
11611be35a1SLionel Sambuc {
11711be35a1SLionel Sambuc     set_md_var("descr", "Tests that argv_array is correctly constructed "
11811be35a1SLionel Sambuc                "from a string collection");
11911be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(argv_array_init_col)12011be35a1SLionel Sambuc ATF_TEST_CASE_BODY(argv_array_init_col)
12111be35a1SLionel Sambuc {
12211be35a1SLionel Sambuc     {
12311be35a1SLionel Sambuc         std::vector< std::string > col;
12411be35a1SLionel Sambuc         atf::process::argv_array argv(col);
12511be35a1SLionel Sambuc 
12611be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv.size(), 0);
12711be35a1SLionel Sambuc     }
12811be35a1SLionel Sambuc 
12911be35a1SLionel Sambuc     {
13011be35a1SLionel Sambuc         std::vector< std::string > col;
13111be35a1SLionel Sambuc         col.push_back("arg0");
13211be35a1SLionel Sambuc         atf::process::argv_array argv(col);
13311be35a1SLionel Sambuc 
13411be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv.size(), 1);
13511be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv[0], col[0]);
13611be35a1SLionel Sambuc     }
13711be35a1SLionel Sambuc 
13811be35a1SLionel Sambuc     {
13911be35a1SLionel Sambuc         std::vector< std::string > col;
14011be35a1SLionel Sambuc         col.push_back("arg0");
14111be35a1SLionel Sambuc         col.push_back("arg1");
14211be35a1SLionel Sambuc         col.push_back("arg2");
14311be35a1SLionel Sambuc         atf::process::argv_array argv(col);
14411be35a1SLionel Sambuc 
14511be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv.size(), 3);
14611be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv[0], col[0]);
14711be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv[1], col[1]);
14811be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv[2], col[2]);
14911be35a1SLionel Sambuc     }
15011be35a1SLionel Sambuc }
15111be35a1SLionel Sambuc 
15211be35a1SLionel Sambuc ATF_TEST_CASE(argv_array_init_empty);
ATF_TEST_CASE_HEAD(argv_array_init_empty)15311be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(argv_array_init_empty)
15411be35a1SLionel Sambuc {
15511be35a1SLionel Sambuc     set_md_var("descr", "Tests that argv_array is correctly constructed "
15611be35a1SLionel Sambuc                "by the default constructor");
15711be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(argv_array_init_empty)15811be35a1SLionel Sambuc ATF_TEST_CASE_BODY(argv_array_init_empty)
15911be35a1SLionel Sambuc {
16011be35a1SLionel Sambuc     atf::process::argv_array argv;
16111be35a1SLionel Sambuc 
16211be35a1SLionel Sambuc     ATF_REQUIRE_EQ(argv.size(), 0);
16311be35a1SLionel Sambuc }
16411be35a1SLionel Sambuc 
16511be35a1SLionel Sambuc ATF_TEST_CASE(argv_array_init_varargs);
ATF_TEST_CASE_HEAD(argv_array_init_varargs)16611be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(argv_array_init_varargs)
16711be35a1SLionel Sambuc {
16811be35a1SLionel Sambuc     set_md_var("descr", "Tests that argv_array is correctly constructed "
16911be35a1SLionel Sambuc                "from a variable list of arguments");
17011be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(argv_array_init_varargs)17111be35a1SLionel Sambuc ATF_TEST_CASE_BODY(argv_array_init_varargs)
17211be35a1SLionel Sambuc {
17311be35a1SLionel Sambuc     {
17411be35a1SLionel Sambuc         atf::process::argv_array argv("arg0", NULL);
17511be35a1SLionel Sambuc 
17611be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv.size(), 1);
17711be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv[0], std::string("arg0"));
17811be35a1SLionel Sambuc     }
17911be35a1SLionel Sambuc 
18011be35a1SLionel Sambuc     {
18111be35a1SLionel Sambuc         atf::process::argv_array argv("arg0", "arg1", "arg2", NULL);
18211be35a1SLionel Sambuc 
18311be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv.size(), 3);
18411be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv[0], std::string("arg0"));
18511be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv[1], std::string("arg1"));
18611be35a1SLionel Sambuc         ATF_REQUIRE_EQ(argv[2], std::string("arg2"));
18711be35a1SLionel Sambuc     }
18811be35a1SLionel Sambuc }
18911be35a1SLionel Sambuc 
19011be35a1SLionel Sambuc ATF_TEST_CASE(argv_array_assign);
ATF_TEST_CASE_HEAD(argv_array_assign)19111be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(argv_array_assign)
19211be35a1SLionel Sambuc {
19311be35a1SLionel Sambuc     set_md_var("descr", "Tests that assigning an argv_array works");
19411be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(argv_array_assign)19511be35a1SLionel Sambuc ATF_TEST_CASE_BODY(argv_array_assign)
19611be35a1SLionel Sambuc {
19711be35a1SLionel Sambuc     using atf::process::argv_array;
19811be35a1SLionel Sambuc 
19911be35a1SLionel Sambuc     const char* const carray1[] = { "arg1", NULL };
20011be35a1SLionel Sambuc     const char* const carray2[] = { "arg1", "arg2", NULL };
20111be35a1SLionel Sambuc 
20211be35a1SLionel Sambuc     std::auto_ptr< argv_array > argv1(new argv_array(carray1));
20311be35a1SLionel Sambuc     std::auto_ptr< argv_array > argv2(new argv_array(carray2));
20411be35a1SLionel Sambuc 
20511be35a1SLionel Sambuc     *argv2 = *argv1;
20611be35a1SLionel Sambuc     ATF_REQUIRE_EQ(argv2->size(), argv1->size());
20711be35a1SLionel Sambuc     ATF_REQUIRE(std::strcmp((*argv2)[0], (*argv1)[0]) == 0);
20811be35a1SLionel Sambuc 
20911be35a1SLionel Sambuc     ATF_REQUIRE(argv2->exec_argv() != argv1->exec_argv());
21011be35a1SLionel Sambuc     argv1.release();
21111be35a1SLionel Sambuc     {
21211be35a1SLionel Sambuc         const char* const* eargv2 = argv2->exec_argv();
21311be35a1SLionel Sambuc         ATF_REQUIRE(std::strcmp(eargv2[0], carray1[0]) == 0);
21411be35a1SLionel Sambuc         ATF_REQUIRE_EQ(eargv2[1], static_cast< const char* >(NULL));
21511be35a1SLionel Sambuc     }
21611be35a1SLionel Sambuc 
21711be35a1SLionel Sambuc     argv2.release();
21811be35a1SLionel Sambuc }
21911be35a1SLionel Sambuc 
22011be35a1SLionel Sambuc ATF_TEST_CASE(argv_array_copy);
ATF_TEST_CASE_HEAD(argv_array_copy)22111be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(argv_array_copy)
22211be35a1SLionel Sambuc {
22311be35a1SLionel Sambuc     set_md_var("descr", "Tests that copying an argv_array constructed from "
22411be35a1SLionel Sambuc                "a C-style array of strings works");
22511be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(argv_array_copy)22611be35a1SLionel Sambuc ATF_TEST_CASE_BODY(argv_array_copy)
22711be35a1SLionel Sambuc {
22811be35a1SLionel Sambuc     using atf::process::argv_array;
22911be35a1SLionel Sambuc 
23011be35a1SLionel Sambuc     const char* const carray[] = { "arg0", NULL };
23111be35a1SLionel Sambuc 
23211be35a1SLionel Sambuc     std::auto_ptr< argv_array > argv1(new argv_array(carray));
23311be35a1SLionel Sambuc     std::auto_ptr< argv_array > argv2(new argv_array(*argv1));
23411be35a1SLionel Sambuc 
23511be35a1SLionel Sambuc     ATF_REQUIRE_EQ(argv2->size(), argv1->size());
23611be35a1SLionel Sambuc     ATF_REQUIRE(std::strcmp((*argv2)[0], (*argv1)[0]) == 0);
23711be35a1SLionel Sambuc 
23811be35a1SLionel Sambuc     ATF_REQUIRE(argv2->exec_argv() != argv1->exec_argv());
23911be35a1SLionel Sambuc     argv1.release();
24011be35a1SLionel Sambuc     {
24111be35a1SLionel Sambuc         const char* const* eargv2 = argv2->exec_argv();
24211be35a1SLionel Sambuc         ATF_REQUIRE(std::strcmp(eargv2[0], carray[0]) == 0);
24311be35a1SLionel Sambuc         ATF_REQUIRE_EQ(eargv2[1], static_cast< const char* >(NULL));
24411be35a1SLionel Sambuc     }
24511be35a1SLionel Sambuc 
24611be35a1SLionel Sambuc     argv2.release();
24711be35a1SLionel Sambuc }
24811be35a1SLionel Sambuc 
24911be35a1SLionel Sambuc ATF_TEST_CASE(argv_array_exec_argv);
ATF_TEST_CASE_HEAD(argv_array_exec_argv)25011be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(argv_array_exec_argv)
25111be35a1SLionel Sambuc {
25211be35a1SLionel Sambuc     set_md_var("descr", "Tests that the exec argv provided by an argv_array "
25311be35a1SLionel Sambuc                "is correct");
25411be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(argv_array_exec_argv)25511be35a1SLionel Sambuc ATF_TEST_CASE_BODY(argv_array_exec_argv)
25611be35a1SLionel Sambuc {
25711be35a1SLionel Sambuc     using atf::process::argv_array;
25811be35a1SLionel Sambuc 
25911be35a1SLionel Sambuc     {
26011be35a1SLionel Sambuc         argv_array argv;
26111be35a1SLionel Sambuc         const char* const* eargv = argv.exec_argv();
26211be35a1SLionel Sambuc         ATF_REQUIRE_EQ(array_size(eargv), 0);
26311be35a1SLionel Sambuc         ATF_REQUIRE_EQ(eargv[0], static_cast< const char* >(NULL));
26411be35a1SLionel Sambuc     }
26511be35a1SLionel Sambuc 
26611be35a1SLionel Sambuc     {
26711be35a1SLionel Sambuc         const char* const carray[] = { "arg0", NULL };
26811be35a1SLionel Sambuc         argv_array argv(carray);
26911be35a1SLionel Sambuc         const char* const* eargv = argv.exec_argv();
27011be35a1SLionel Sambuc         ATF_REQUIRE_EQ(array_size(eargv), 1);
27111be35a1SLionel Sambuc         ATF_REQUIRE(std::strcmp(eargv[0], "arg0") == 0);
27211be35a1SLionel Sambuc         ATF_REQUIRE_EQ(eargv[1], static_cast< const char* >(NULL));
27311be35a1SLionel Sambuc     }
27411be35a1SLionel Sambuc 
27511be35a1SLionel Sambuc     {
27611be35a1SLionel Sambuc         std::vector< std::string > col;
27711be35a1SLionel Sambuc         col.push_back("arg0");
27811be35a1SLionel Sambuc         argv_array argv(col);
27911be35a1SLionel Sambuc         const char* const* eargv = argv.exec_argv();
28011be35a1SLionel Sambuc         ATF_REQUIRE_EQ(array_size(eargv), 1);
28111be35a1SLionel Sambuc         ATF_REQUIRE(std::strcmp(eargv[0], "arg0") == 0);
28211be35a1SLionel Sambuc         ATF_REQUIRE_EQ(eargv[1], static_cast< const char* >(NULL));
28311be35a1SLionel Sambuc     }
28411be35a1SLionel Sambuc }
28511be35a1SLionel Sambuc 
28611be35a1SLionel Sambuc ATF_TEST_CASE(argv_array_iter);
ATF_TEST_CASE_HEAD(argv_array_iter)28711be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(argv_array_iter)
28811be35a1SLionel Sambuc {
28911be35a1SLionel Sambuc     set_md_var("descr", "Tests that an argv_array can be iterated");
29011be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(argv_array_iter)29111be35a1SLionel Sambuc ATF_TEST_CASE_BODY(argv_array_iter)
29211be35a1SLionel Sambuc {
29311be35a1SLionel Sambuc     using atf::process::argv_array;
29411be35a1SLionel Sambuc 
29511be35a1SLionel Sambuc     std::vector< std::string > vector;
29611be35a1SLionel Sambuc     vector.push_back("arg0");
29711be35a1SLionel Sambuc     vector.push_back("arg1");
29811be35a1SLionel Sambuc     vector.push_back("arg2");
29911be35a1SLionel Sambuc 
30011be35a1SLionel Sambuc     argv_array argv(vector);
30111be35a1SLionel Sambuc     ATF_REQUIRE_EQ(argv.size(), 3);
30211be35a1SLionel Sambuc     std::vector< std::string >::size_type pos = 0;
30311be35a1SLionel Sambuc     for (argv_array::const_iterator iter = argv.begin(); iter != argv.end();
30411be35a1SLionel Sambuc          iter++) {
30511be35a1SLionel Sambuc         ATF_REQUIRE_EQ(*iter, vector[pos]);
30611be35a1SLionel Sambuc         pos++;
30711be35a1SLionel Sambuc     }
30811be35a1SLionel Sambuc }
30911be35a1SLionel Sambuc 
31011be35a1SLionel Sambuc // ------------------------------------------------------------------------
31111be35a1SLionel Sambuc // Tests cases for the free functions.
31211be35a1SLionel Sambuc // ------------------------------------------------------------------------
31311be35a1SLionel Sambuc 
31411be35a1SLionel Sambuc ATF_TEST_CASE(exec_failure);
ATF_TEST_CASE_HEAD(exec_failure)31511be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(exec_failure)
31611be35a1SLionel Sambuc {
31711be35a1SLionel Sambuc     set_md_var("descr", "Tests execing a command that reports failure");
31811be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(exec_failure)31911be35a1SLionel Sambuc ATF_TEST_CASE_BODY(exec_failure)
32011be35a1SLionel Sambuc {
32111be35a1SLionel Sambuc     const atf::process::status s = exec_process_helpers(*this, "exit-failure");
32211be35a1SLionel Sambuc     ATF_REQUIRE(s.exited());
32311be35a1SLionel Sambuc     ATF_REQUIRE_EQ(s.exitstatus(), EXIT_FAILURE);
32411be35a1SLionel Sambuc }
32511be35a1SLionel Sambuc 
32611be35a1SLionel Sambuc ATF_TEST_CASE(exec_success);
ATF_TEST_CASE_HEAD(exec_success)32711be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(exec_success)
32811be35a1SLionel Sambuc {
32911be35a1SLionel Sambuc     set_md_var("descr", "Tests execing a command that reports success");
33011be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(exec_success)33111be35a1SLionel Sambuc ATF_TEST_CASE_BODY(exec_success)
33211be35a1SLionel Sambuc {
33311be35a1SLionel Sambuc     const atf::process::status s = exec_process_helpers(*this, "exit-success");
33411be35a1SLionel Sambuc     ATF_REQUIRE(s.exited());
33511be35a1SLionel Sambuc     ATF_REQUIRE_EQ(s.exitstatus(), EXIT_SUCCESS);
33611be35a1SLionel Sambuc }
33711be35a1SLionel Sambuc 
33811be35a1SLionel Sambuc // ------------------------------------------------------------------------
33911be35a1SLionel Sambuc // Main.
34011be35a1SLionel Sambuc // ------------------------------------------------------------------------
34111be35a1SLionel Sambuc 
ATF_INIT_TEST_CASES(tcs)34211be35a1SLionel Sambuc ATF_INIT_TEST_CASES(tcs)
34311be35a1SLionel Sambuc {
34411be35a1SLionel Sambuc     // Add the test cases for the "argv_array" type.
34511be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, argv_array_assign);
34611be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, argv_array_copy);
34711be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, argv_array_exec_argv);
34811be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, argv_array_init_carray);
34911be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, argv_array_init_col);
35011be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, argv_array_init_empty);
35111be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, argv_array_init_varargs);
35211be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, argv_array_iter);
35311be35a1SLionel Sambuc 
35411be35a1SLionel Sambuc     // Add the test cases for the free functions.
35511be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, exec_failure);
35611be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, exec_success);
35711be35a1SLionel Sambuc }
358