OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "tools/gn/runtime_deps.h" | 10 #include "tools/gn/runtime_deps.h" |
| 11 #include "tools/gn/scheduler.h" |
11 #include "tools/gn/target.h" | 12 #include "tools/gn/target.h" |
12 #include "tools/gn/test_with_scope.h" | 13 #include "tools/gn/test_with_scope.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 void InitTargetWithType(TestWithScope& setup, | 17 void InitTargetWithType(TestWithScope& setup, |
17 Target* target, | 18 Target* target, |
18 Target::OutputType type) { | 19 Target::OutputType type) { |
19 target->set_output_type(type); | 20 target->set_output_type(type); |
20 target->visibility().SetPublic(); | 21 target->visibility().SetPublic(); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 target.data_deps().push_back(LabelTargetPair(&action)); | 276 target.data_deps().push_back(LabelTargetPair(&action)); |
276 ASSERT_TRUE(target.OnResolved(&err)); | 277 ASSERT_TRUE(target.OnResolved(&err)); |
277 | 278 |
278 // The results should be the executable and the copy output. | 279 // The results should be the executable and the copy output. |
279 std::vector<std::pair<OutputFile, const Target*>> result = | 280 std::vector<std::pair<OutputFile, const Target*>> result = |
280 ComputeRuntimeDeps(&target); | 281 ComputeRuntimeDeps(&target); |
281 EXPECT_TRUE(std::find(result.begin(), result.end(), | 282 EXPECT_TRUE(std::find(result.begin(), result.end(), |
282 MakePair("../../action.output", &action)) != | 283 MakePair("../../action.output", &action)) != |
283 result.end()) << GetVectorDescription(result); | 284 result.end()) << GetVectorDescription(result); |
284 } | 285 } |
| 286 |
| 287 // Tests that actions can't have output substitutions. |
| 288 TEST(RuntimeDeps, WriteRuntimeDepsVariable) { |
| 289 Scheduler scheduler; |
| 290 TestWithScope setup; |
| 291 Err err; |
| 292 |
| 293 // Should refuse to write files outside of the output dir. |
| 294 EXPECT_FALSE(setup.ExecuteSnippet( |
| 295 "group(\"foo\") { write_runtime_deps = \"//foo.txt\" }", &err)); |
| 296 |
| 297 // Should fail for garbage inputs. |
| 298 err = Err(); |
| 299 EXPECT_FALSE(setup.ExecuteSnippet( |
| 300 "group(\"foo\") { write_runtime_deps = 0 }", &err)); |
| 301 |
| 302 // Should be able to write inside the out dir, and shouldn't write the one |
| 303 // in the else clause. |
| 304 err = Err(); |
| 305 EXPECT_TRUE(setup.ExecuteSnippet( |
| 306 "if (true) {\n" |
| 307 " group(\"foo\") { write_runtime_deps = \"//out/Debug/foo.txt\" }\n" |
| 308 "} else {\n" |
| 309 " group(\"bar\") { write_runtime_deps = \"//out/Debug/bar.txt\" }\n" |
| 310 "}", &err)); |
| 311 EXPECT_EQ(1U, setup.items().size()); |
| 312 EXPECT_EQ(1U, scheduler.GetWriteRuntimeDepsTargets().size()); |
| 313 } |
OLD | NEW |