Ninja
state_test.cc
Go to the documentation of this file.
1// Copyright 2011 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "graph.h"
16#include "state.h"
17#include "test.h"
18
19using namespace std;
20
21namespace {
22
23TEST(State, Basic) {
24 State state;
25
26 EvalString command;
27 command.AddText("cat ");
28 command.AddSpecial("in");
29 command.AddText(" > ");
30 command.AddSpecial("out");
31
32 Rule* rule = new Rule("cat");
33 rule->AddBinding("command", command);
34 state.bindings_.AddRule(std::unique_ptr<Rule>(rule));
35
36 Edge* edge = state.AddEdge(rule);
37 state.AddIn(edge, "in1", 0);
38 state.AddIn(edge, "in2", 0);
39 state.AddOut(edge, "out", 0, nullptr);
40
41 EXPECT_EQ("cat in1 in2 > out", edge->EvaluateCommand());
42
43 EXPECT_FALSE(state.GetNode("in1", 0)->dirty());
44 EXPECT_FALSE(state.GetNode("in2", 0)->dirty());
45 EXPECT_FALSE(state.GetNode("out", 0)->dirty());
46}
47
48} // namespace
TEST(CLParserTest, ShowIncludes)
Definition hash_map.h:26
void AddRule(std::unique_ptr< const Rule > rule)
Definition eval_env.cc:34
An edge in the dependency graph; links between Nodes using Rules.
Definition graph.h:175
std::string EvaluateCommand(bool incl_rsp_file=false) const
Expand all variables in a command and return it as a string.
Definition graph.cc:501
A tokenized string that contains variable references.
Definition eval_env.h:35
void AddSpecial(StringPiece text)
Definition eval_env.cc:136
void AddText(StringPiece text)
Definition eval_env.cc:126
bool dirty() const
Definition graph.h:93
An invocable build command and associated metadata (description, etc.).
Definition eval_env.h:66
void AddBinding(const std::string &key, const EvalString &val)
Definition eval_env.cc:55
Global state (file status) for a single run.
Definition state.h:95
Edge * AddEdge(const Rule *rule)
Definition state.cc:85
Node * GetNode(StringPiece path, uint64_t slash_bits)
Definition state.cc:95
void AddIn(Edge *edge, StringPiece path, uint64_t slash_bits)
Add input / output / validation nodes to a given edge.
Definition state.cc:128
BindingEnv bindings_
Definition state.h:140
bool AddOut(Edge *edge, StringPiece path, uint64_t slash_bits, std::string *err)
Definition state.cc:135