2 // Automated Testing Framework (atf)
4 // Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
5 // All rights reserved.
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "atf-c++/atffile.hpp"
33 #include "atf-c++/exceptions.hpp"
34 #include "atf-c++/expand.hpp"
35 #include "atf-c++/formats.hpp"
37 // ------------------------------------------------------------------------
38 // The "reader" helper class.
39 // ------------------------------------------------------------------------
41 class reader
: public atf::formats::atf_atffile_reader
{
42 const atf::fs::directory
& m_dir
;
43 atf::tests::vars_map m_conf
, m_props
;
44 std::vector
< std::string
> m_tps
;
47 got_tp(const std::string
& name
, bool isglob
)
50 std::vector
< std::string
> ms
=
51 atf::expand::expand_glob(name
, m_dir
.names());
52 // Cannot use m_tps.insert(iterator, begin, end) here because it
53 // does not work under Solaris.
54 for (std::vector
< std::string
>::const_iterator iter
= ms
.begin();
55 iter
!= ms
.end(); iter
++)
56 m_tps
.push_back(*iter
);
58 if (m_dir
.find(name
) == m_dir
.end())
59 throw atf::not_found_error
< atf::fs::path
>
60 ("Cannot locate the " + name
+ " file",
62 m_tps
.push_back(name
);
67 got_prop(const std::string
& name
, const std::string
& val
)
73 got_conf(const std::string
& var
, const std::string
& val
)
79 reader(std::istream
& is
, const atf::fs::directory
& dir
) :
80 atf::formats::atf_atffile_reader(is
),
85 const atf::tests::vars_map
&
92 const atf::tests::vars_map
&
99 const std::vector
< std::string
>&
107 // ------------------------------------------------------------------------
108 // The "atffile" class.
109 // ------------------------------------------------------------------------
111 atf::atffile::atffile(const atf::fs::path
& filename
)
113 // Scan the directory where the atffile lives in to gather a list of
114 // all possible test programs in it.
115 fs::directory
dir(filename
.branch_path());
116 dir
.erase(filename
.leaf_name());
117 fs::directory::iterator iter
= dir
.begin();
118 while (iter
!= dir
.end()) {
119 const std::string
& name
= (*iter
).first
;
120 const fs::file_info
& fi
= (*iter
).second
;
122 // Discard hidden files and non-executable ones so that they are
123 // not candidates for glob matching.
124 if (name
[0] == '.' || (!fi
.is_owner_executable() &&
125 !fi
.is_group_executable()))
131 // Parse the atffile.
132 std::ifstream
is(filename
.c_str());
134 throw atf::not_found_error
< fs::path
>
135 ("Cannot open Atffile", filename
);
140 // Update the atffile with the data accumulated in the reader.
146 if (m_props
.find("test-suite") == m_props
.end())
147 throw std::runtime_error("Undefined property `test-suite'");
150 const std::vector
< std::string
>&
151 atf::atffile::tps(void)
157 const atf::tests::vars_map
&
158 atf::atffile::conf(void)
164 const atf::tests::vars_map
&
165 atf::atffile::props(void)