~marcustomlinson/unity-scopes-api/fix-querymetadata-tests

« back to all changes in this revision

Viewing changes to test/gtest/scopes/internal/Utils/Utils_test.cpp

  • Committer: Tarmac
  • Author(s): Marcus Tomlinson
  • Date: 2015-09-15 11:36:04 UTC
  • mfrom: (629.2.2 devel)
  • Revision ID: tarmac-20150915113604-0u44np98g9jqnf1u
Loop through each argument of the custom scope runner command and ensure that all path arguments are absolute.

Approved by Pawel Stolowski, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
 
133
133
    chmod(child.c_str(), 0777);  // Don't leave the dir behind without permissions.
134
134
}
 
135
 
 
136
TEST(Utils, split_exec_args)
 
137
{
 
138
    // Test empty executable
 
139
    try
 
140
    {
 
141
        split_exec_args("test", "");
 
142
        FAIL();
 
143
    }
 
144
    catch (std::exception const& e)
 
145
    {
 
146
        EXPECT_STREQ("unity::InvalidArgumentException: Invalid empty executable for scope: 'test'", e.what());
 
147
    }
 
148
 
 
149
    // Test invalid executable
 
150
    try
 
151
    {
 
152
        split_exec_args("test", "\"");
 
153
        FAIL();
 
154
    }
 
155
    catch (std::exception const& e)
 
156
    {
 
157
        EXPECT_STREQ("unity::InvalidArgumentException: Invalid executable for scope: 'test'", e.what());
 
158
    }
 
159
 
 
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());
 
168
}
 
169
 
 
170
TEST(Utils, convert_exec_rel_to_abs)
 
171
{
 
172
    // Test empty executable
 
173
    try
 
174
    {
 
175
        convert_exec_rel_to_abs("test", boost::filesystem::path(TEST_DIR), "");
 
176
        FAIL();
 
177
    }
 
178
    catch (std::exception const& e)
 
179
    {
 
180
        EXPECT_STREQ("unity::InvalidArgumentException: Invalid empty executable for scope: 'test'", e.what());
 
181
    }
 
182
 
 
183
    // Test invalid executable
 
184
    try
 
185
    {
 
186
        convert_exec_rel_to_abs("test", boost::filesystem::path(TEST_DIR), "\"");
 
187
        FAIL();
 
188
    }
 
189
    catch (std::exception const& e)
 
190
    {
 
191
        EXPECT_STREQ("unity::InvalidArgumentException: Invalid executable for scope: 'test'", e.what());
 
192
    }
 
193
 
 
194
    // Test nonexistent executable
 
195
    try
 
196
    {
 
197
        convert_exec_rel_to_abs("test", boost::filesystem::path(TEST_DIR), "noexec");
 
198
        FAIL();
 
199
    }
 
200
    catch (std::exception const& e)
 
201
    {
 
202
        EXPECT_STREQ("unity::InvalidArgumentException: Nonexistent scope runner executable: 'noexec' for scope: 'test'", e.what());
 
203
    }
 
204
 
 
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());
 
208
 
 
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());
 
212
 
 
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));
 
216
 
 
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));
 
220
}