Line data Source code
1 : // Copyright (c) 2006-2021 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/snapdev
4 : // contact@m2osw.com
5 : //
6 : // This program is free software; you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation; either version 2 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License along
17 : // with this program; if not, write to the Free Software Foundation, Inc.,
18 : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 :
20 :
21 : /** \file
22 : * \brief Start the catch test for snapdev.
23 : *
24 : * This file implements the main test functions (initialization).
25 : */
26 :
27 : // Tell catch we want it to add the runner code in this file.
28 : #define CATCH_CONFIG_RUNNER
29 :
30 : // self
31 : //
32 : #include "catch_main.h"
33 :
34 :
35 : // snapdev lib
36 : //
37 : #include <snapdev/not_used.h>
38 : #include <snapdev/version.h>
39 :
40 :
41 : // libexcept lib
42 : //
43 : #include <libexcept/exception.h>
44 :
45 :
46 : // C++ lib
47 : //
48 : #include <sstream>
49 :
50 :
51 : // last include
52 : //
53 : #include <snapdev/poison.h>
54 :
55 :
56 :
57 :
58 : namespace SNAP_CATCH2_NAMESPACE
59 : {
60 :
61 :
62 2 : std::string g_tmp_dir;
63 :
64 :
65 :
66 : }
67 : // SNAP_CATCH2_NAMESPACE namespace
68 :
69 :
70 : namespace
71 : {
72 :
73 :
74 2 : Catch::clara::Parser add_command_line_options(Catch::clara::Parser const & cli)
75 : {
76 : return cli
77 4 : | Catch::clara::Opt(SNAP_CATCH2_NAMESPACE::g_tmp_dir, "tmp")
78 6 : ["-T"]["--tmp"]
79 10 : ("a path to a temporary directory used by the tests.");
80 : }
81 :
82 :
83 :
84 1 : int finish_init(Catch::Session & session)
85 : {
86 1 : snap::NOT_USED(session);
87 :
88 1 : if(!SNAP_CATCH2_NAMESPACE::g_tmp_dir.empty())
89 : {
90 1 : if(SNAP_CATCH2_NAMESPACE::g_tmp_dir == "/tmp")
91 : {
92 0 : std::cerr << "fatal error: you must specify a sub-directory for your temporary directory such as /tmp/snapdev";
93 0 : exit(1);
94 : }
95 : }
96 : else
97 : {
98 0 : SNAP_CATCH2_NAMESPACE::g_tmp_dir = "/tmp/snapdev";
99 : }
100 :
101 : // delete the existing tmp directory
102 : {
103 2 : std::stringstream ss;
104 1 : ss << "rm -rf \"" << SNAP_CATCH2_NAMESPACE::g_tmp_dir << "\"";
105 1 : if(system(ss.str().c_str()) != 0)
106 : {
107 0 : std::cerr << "fatal error: could not delete temporary directory \"" << SNAP_CATCH2_NAMESPACE::g_tmp_dir << "\".";
108 0 : exit(1);
109 : }
110 : }
111 :
112 : // then re-create the directory
113 : {
114 2 : std::stringstream ss;
115 1 : ss << "mkdir -p \"" << SNAP_CATCH2_NAMESPACE::g_tmp_dir << "\"";
116 1 : if(system(ss.str().c_str()) != 0)
117 : {
118 0 : std::cerr << "fatal error: could not create temporary directory \"" << SNAP_CATCH2_NAMESPACE::g_tmp_dir << "\".";
119 0 : exit(1);
120 : }
121 : }
122 :
123 1 : return 0;
124 : }
125 :
126 :
127 :
128 : }
129 :
130 :
131 2 : int main(int argc, char * argv[])
132 : {
133 4 : return SNAP_CATCH2_NAMESPACE::snap_catch2_main(
134 : "snapdev"
135 : , SNAPDEV_VERSION_STRING
136 : , argc
137 : , argv
138 6 : , []() { libexcept::set_collect_stack(false); }
139 : , &add_command_line_options
140 : , &finish_init
141 4 : );
142 6 : }
143 :
144 : // vim: ts=4 sw=4 et
|