-
Notifications
You must be signed in to change notification settings - Fork 277
/
Copy pathexamples_build.cc
129 lines (107 loc) · 3.83 KB
/
examples_build.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (C) 2017 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <gtest/gtest.h>
#include <string>
#include <gz/common/Console.hh>
#include <gz/common/Filesystem.hh>
#include <gz/common/TempDirectory.hh>
#include <gz/common/Util.hh>
#include <gz/math/SemanticVersion.hh>
#include <gz/utils/ExtraTestMacros.hh>
#include "test_config.hh"
#include "../helpers/EnvTestFixture.hh"
// File copied from
// https://github.com/gazebosim/gz-gui/raw/ign-gui3/test/integration/ExamplesBuild_TEST.cc
using namespace gz;
auto kExampleTypes = std::vector<std::string>{"plugin", "standalone"};
//////////////////////////////////////////////////
struct ExampleEntry
{
/// Type of example (eg plugin/standalone)
std::string type;
/// Example plugin directory name
std::string base;
/// Full path to the source directory of the example
std::string sourceDir;
/// Used to pretty print with gtest
/// \param[in] _os stream to print to
/// \param[in] _example Entry to print to the stream
friend std::ostream& operator<<(std::ostream &_os,
const ExampleEntry &_entry)
{
return _os << "[" << _entry.type << ", " << _entry.base << "]";
}
};
//////////////////////////////////////////////////
/// Generate a list of examples to be built.
std::vector<ExampleEntry> GetExamples()
{
std::vector<ExampleEntry> examples;
for (auto type : kExampleTypes)
{
auto examplesDir =
common::joinPaths(PROJECT_SOURCE_PATH, "/examples/", type);
// Iterate over directory
gz::common::DirIter endIter;
for (gz::common::DirIter dirIter(examplesDir);
dirIter != endIter; ++dirIter)
{
auto base = gz::common::basename(*dirIter);
auto sourceDir = common::joinPaths(examplesDir, base);
examples.push_back({ type, base, sourceDir });
}
}
return examples;
}
//////////////////////////////////////////////////
class ExamplesBuild
: public InternalFixture<::testing::TestWithParam<ExampleEntry>>
{
/// \brief Build code in a temporary build folder.
/// \param[in] _type Type of example to build (plugins, standalone).
public: void Build(const ExampleEntry &_type);
};
//////////////////////////////////////////////////
void ExamplesBuild::Build(const ExampleEntry &_entry)
{
common::Console::SetVerbosity(4);
// Path to examples of the given type
ASSERT_TRUE(gz::common::exists(_entry.sourceDir));
gzdbg << "Source: " << _entry.sourceDir << std::endl;
// Create a temp build directory
common::TempDirectory tmpBuildDir;
ASSERT_TRUE(tmpBuildDir.Valid());
gzdbg << "Build directory: " << tmpBuildDir.Path() << std::endl;
char cmd[1024];
// cd build && cmake source
snprintf(cmd, sizeof(cmd), "cd %s && cmake %s",
tmpBuildDir.Path().c_str(), _entry.sourceDir.c_str());
ASSERT_EQ(system(cmd), 0) << _entry.sourceDir;
ASSERT_EQ(system("make"), 0);
}
//////////////////////////////////////////////////
// See https://github.com/gazebosim/gz-sim/issues/1175
TEST_P(ExamplesBuild, GZ_UTILS_TEST_DISABLED_ON_WIN32(Build))
{
Build(GetParam());
}
//////////////////////////////////////////////////
INSTANTIATE_TEST_SUITE_P(Plugins, ExamplesBuild,
::testing::ValuesIn(GetExamples()),
[](const ::testing::TestParamInfo<ExamplesBuild::ParamType>& param) {
return param.param.type + "_" + param.param.base;
});