OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef TOOLS_GN_TEST_WITH_SCOPE_H_ | 5 #ifndef TOOLS_GN_TEST_WITH_SCOPE_H_ |
6 #define TOOLS_GN_TEST_WITH_SCOPE_H_ | 6 #define TOOLS_GN_TEST_WITH_SCOPE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 public: | 27 public: |
28 TestWithScope(); | 28 TestWithScope(); |
29 ~TestWithScope(); | 29 ~TestWithScope(); |
30 | 30 |
31 BuildSettings* build_settings() { return &build_settings_; } | 31 BuildSettings* build_settings() { return &build_settings_; } |
32 Settings* settings() { return &settings_; } | 32 Settings* settings() { return &settings_; } |
33 const Settings* settings() const { return &settings_; } | 33 const Settings* settings() const { return &settings_; } |
34 Toolchain* toolchain() { return &toolchain_; } | 34 Toolchain* toolchain() { return &toolchain_; } |
35 const Toolchain* toolchain() const { return &toolchain_; } | 35 const Toolchain* toolchain() const { return &toolchain_; } |
36 Scope* scope() { return &scope_; } | 36 Scope* scope() { return &scope_; } |
| 37 const Scope::ItemVector& items() { return items_; } |
37 | 38 |
38 // This buffer accumulates output from any print() commands executed in the | 39 // This buffer accumulates output from any print() commands executed in the |
39 // context of this test. Note that the implementation of this is not | 40 // context of this test. Note that the implementation of this is not |
40 // threadsafe so don't write tests that call print from multiple threads. | 41 // threadsafe so don't write tests that call print from multiple threads. |
41 std::string& print_output() { return print_output_; } | 42 std::string& print_output() { return print_output_; } |
42 | 43 |
43 // Parse the given string into a label in the default toolchain. This will | 44 // Parse the given string into a label in the default toolchain. This will |
44 // assert if the label isn't valid (this is intended for hardcoded labels). | 45 // assert if the label isn't valid (this is intended for hardcoded labels). |
45 Label ParseLabel(const std::string& str) const; | 46 Label ParseLabel(const std::string& str) const; |
46 | 47 |
| 48 // Parses, evaluates, and resolves targets from the given snippet of code. |
| 49 // All targets must be defined in dependency order (does not use a Builder, |
| 50 // just blindly resolves all targets in order). |
| 51 bool ExecuteSnippet(const std::string& str, Err* err); |
| 52 |
47 // Fills in the tools for the given toolchain with reasonable default values. | 53 // Fills in the tools for the given toolchain with reasonable default values. |
48 // The toolchain in this object will be automatically set up with this | 54 // The toolchain in this object will be automatically set up with this |
49 // function, it is exposed to allow tests to get the same functionality for | 55 // function, it is exposed to allow tests to get the same functionality for |
50 // other toolchains they make. | 56 // other toolchains they make. |
51 static void SetupToolchain(Toolchain* toolchain); | 57 static void SetupToolchain(Toolchain* toolchain); |
52 | 58 |
53 // Sets the given text command on the given tool, parsing it as a | 59 // Sets the given text command on the given tool, parsing it as a |
54 // substitution pattern. This will assert if the input is malformed. This is | 60 // substitution pattern. This will assert if the input is malformed. This is |
55 // designed to help setting up Tools for tests. | 61 // designed to help setting up Tools for tests. |
56 static void SetCommandForTool(const std::string& cmd, Tool* tool); | 62 static void SetCommandForTool(const std::string& cmd, Tool* tool); |
57 | 63 |
58 private: | 64 private: |
59 void AppendPrintOutput(const std::string& str); | 65 void AppendPrintOutput(const std::string& str); |
60 | 66 |
61 BuildSettings build_settings_; | 67 BuildSettings build_settings_; |
62 Settings settings_; | 68 Settings settings_; |
63 Toolchain toolchain_; | 69 Toolchain toolchain_; |
64 Scope scope_; | 70 Scope scope_; |
| 71 Scope::ItemVector items_; |
65 | 72 |
66 // Supplies the scope with built-in variables like root_out_dir. | 73 // Supplies the scope with built-in variables like root_out_dir. |
67 ScopePerFileProvider scope_progammatic_provider_; | 74 ScopePerFileProvider scope_progammatic_provider_; |
68 | 75 |
69 std::string print_output_; | 76 std::string print_output_; |
70 | 77 |
71 DISALLOW_COPY_AND_ASSIGN(TestWithScope); | 78 DISALLOW_COPY_AND_ASSIGN(TestWithScope); |
72 }; | 79 }; |
73 | 80 |
74 // Helper class to treat some string input as a file. | 81 // Helper class to treat some string input as a file. |
(...skipping 29 matching lines...) Expand all Loading... |
104 // default to public visibility. | 111 // default to public visibility. |
105 class TestTarget : public Target { | 112 class TestTarget : public Target { |
106 public: | 113 public: |
107 TestTarget(const TestWithScope& setup, | 114 TestTarget(const TestWithScope& setup, |
108 const std::string& label_string, | 115 const std::string& label_string, |
109 Target::OutputType type); | 116 Target::OutputType type); |
110 ~TestTarget() override; | 117 ~TestTarget() override; |
111 }; | 118 }; |
112 | 119 |
113 #endif // TOOLS_GN_TEST_WITH_SCOPE_H_ | 120 #endif // TOOLS_GN_TEST_WITH_SCOPE_H_ |
OLD | NEW |