Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / tools / gn / test_with_scope.h
blobce7d95c2e378d378366d3d10bc05881862f2342d
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
3 // found in the LICENSE file.
5 #ifndef TOOLS_GN_TEST_WITH_SCOPE_H_
6 #define TOOLS_GN_TEST_WITH_SCOPE_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "tools/gn/build_settings.h"
12 #include "tools/gn/err.h"
13 #include "tools/gn/input_file.h"
14 #include "tools/gn/parse_tree.h"
15 #include "tools/gn/scope.h"
16 #include "tools/gn/settings.h"
17 #include "tools/gn/token.h"
18 #include "tools/gn/toolchain.h"
19 #include "tools/gn/value.h"
21 // A helper class for setting up a Scope that a test can use. It makes a
22 // toolchain and sets up all the build state.
23 class TestWithScope {
24 public:
25 TestWithScope();
26 ~TestWithScope();
28 BuildSettings* build_settings() { return &build_settings_; }
29 Settings* settings() { return &settings_; }
30 Toolchain* toolchain() { return &toolchain_; }
31 Scope* scope() { return &scope_; }
33 // This buffer accumulates output from any print() commands executed in the
34 // context of this test. Note that the implementation of this is not
35 // threadsafe so don't write tests that call print from multiple threads.
36 std::string& print_output() { return print_output_; }
38 private:
39 void AppendPrintOutput(const std::string& str);
41 BuildSettings build_settings_;
42 Settings settings_;
43 Toolchain toolchain_;
44 Scope scope_;
46 std::string print_output_;
48 DISALLOW_COPY_AND_ASSIGN(TestWithScope);
51 // Helper class to treat some string input as a file.
53 // Instantiate it with the contents you want, be sure to check for error, and
54 // then you can execute the ParseNode or whatever.
55 class TestParseInput {
56 public:
57 TestParseInput(const std::string& input);
58 ~TestParseInput();
60 // Indicates whether and what error occurred during tokenizing and parsing.
61 bool has_error() const { return parse_err_.has_error(); }
62 const Err& parse_err() const { return parse_err_; }
64 const InputFile& input_file() const { return input_file_; }
65 const std::vector<Token>& tokens() const { return tokens_; }
66 const ParseNode* parsed() const { return parsed_.get(); }
68 private:
69 InputFile input_file_;
71 std::vector<Token> tokens_;
72 scoped_ptr<ParseNode> parsed_;
74 Err parse_err_;
76 DISALLOW_COPY_AND_ASSIGN(TestParseInput);
79 #endif // TOOLS_GN_TEST_WITH_SCOPE_H_