133
133
chmod(child.c_str(), 0777); // Don't leave the dir behind without permissions.
136
TEST(Utils, split_exec_args)
138
// Test empty executable
141
split_exec_args("test", "");
144
catch (std::exception const& e)
146
EXPECT_STREQ("unity::InvalidArgumentException: Invalid empty executable for scope: 'test'", e.what());
149
// Test invalid executable
152
split_exec_args("test", "\"");
155
catch (std::exception const& e)
157
EXPECT_STREQ("unity::InvalidArgumentException: Invalid executable for scope: 'test'", e.what());
160
// Test argument splitting
161
auto exec_args = split_exec_args("test", "/path\\ to/exec' 'file arg \"arg 2\" arg' '3 arg\\ 4");
162
ASSERT_EQ(5, exec_args.size());
163
EXPECT_STREQ("\"/path to/exec file\"", exec_args[0].c_str());
164
EXPECT_STREQ("arg", exec_args[1].c_str());
165
EXPECT_STREQ("\"arg 2\"", exec_args[2].c_str());
166
EXPECT_STREQ("\"arg 3\"", exec_args[3].c_str());
167
EXPECT_STREQ("\"arg 4\"", exec_args[4].c_str());
170
TEST(Utils, convert_exec_rel_to_abs)
172
// Test empty executable
175
convert_exec_rel_to_abs("test", boost::filesystem::path(TEST_DIR), "");
178
catch (std::exception const& e)
180
EXPECT_STREQ("unity::InvalidArgumentException: Invalid empty executable for scope: 'test'", e.what());
183
// Test invalid executable
186
convert_exec_rel_to_abs("test", boost::filesystem::path(TEST_DIR), "\"");
189
catch (std::exception const& e)
191
EXPECT_STREQ("unity::InvalidArgumentException: Invalid executable for scope: 'test'", e.what());
194
// Test nonexistent executable
197
convert_exec_rel_to_abs("test", boost::filesystem::path(TEST_DIR), "noexec");
200
catch (std::exception const& e)
202
EXPECT_STREQ("unity::InvalidArgumentException: Nonexistent scope runner executable: 'noexec' for scope: 'test'", e.what());
205
// Test absolute executable
206
auto abs_exec = convert_exec_rel_to_abs("test", boost::filesystem::path(TEST_DIR), "/bin/bash");
207
EXPECT_STREQ("/bin/bash", abs_exec.c_str());
209
// Test absolute executable w/ args
210
abs_exec = convert_exec_rel_to_abs("test", boost::filesystem::path(TEST_DIR), "/bin/bash arg \"arg 2\" arg' '3 arg\\ 4");
211
EXPECT_STREQ("/bin/bash arg \"arg 2\" \"arg 3\" \"arg 4\"", abs_exec.c_str());
213
// Test relative executable (w/ ./)
214
abs_exec = convert_exec_rel_to_abs("test", boost::filesystem::path(TEST_DIR), "./Utils_test");
215
EXPECT_TRUE(boost::filesystem::exists(abs_exec));
217
// Test relative executable (w/o ./)
218
abs_exec = convert_exec_rel_to_abs("test", boost::filesystem::path(TEST_DIR), "Utils_test");
219
EXPECT_TRUE(boost::filesystem::exists(abs_exec));