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 
19 namespace {
20 
21 TEST(State, Basic) {
22  State state;
23 
24  EvalString command;
25  command.AddText("cat ");
26  command.AddSpecial("in");
27  command.AddText(" > ");
28  command.AddSpecial("out");
29 
30  Rule* rule = new Rule("cat");
31  rule->AddBinding("command", command);
32  state.AddRule(rule);
33 
34  Edge* edge = state.AddEdge(rule);
35  state.AddIn(edge, "in1", 0);
36  state.AddIn(edge, "in2", 0);
37  state.AddOut(edge, "out", 0);
38 
39  EXPECT_EQ("cat in1 in2 > out", edge->EvaluateCommand());
40 
41  EXPECT_FALSE(state.GetNode("in1", 0)->dirty());
42  EXPECT_FALSE(state.GetNode("in2", 0)->dirty());
43  EXPECT_FALSE(state.GetNode("out", 0)->dirty());
44 }
45 
46 } // namespace
#define TEST(x, y)
Definition: test.h:61
#define EXPECT_FALSE(a)
Definition: test.h:77
Node * GetNode(StringPiece path, unsigned int slash_bits)
Definition: state.cc:114
An edge in the dependency graph; links between Nodes using Rules.
Definition: graph.h:146
string EvaluateCommand(bool incl_rsp_file=false)
Expand all variables in a command and return it as a string.
Definition: graph.cc:273
Edge * AddEdge(const Rule *rule)
Definition: state.cc:105
void AddSpecial(StringPiece text)
Definition: eval_env.cc:65
#define EXPECT_EQ(a, b)
Definition: test.h:63
void AddRule(const Rule *rule)
Definition: state.cc:81
An invokable build command and associated metadata (description, etc.).
Definition: graph.h:125
bool dirty() const
Definition: graph.h:80
void AddBinding(const string &key, const EvalString &val)
Definition: graph.cc:36
void AddText(StringPiece text)
Definition: eval_env.cc:57
void AddOut(Edge *edge, StringPiece path, unsigned int slash_bits)
Definition: state.cc:154
Global state (file status, loaded rules) for a single run.
Definition: state.h:83
void AddIn(Edge *edge, StringPiece path, unsigned int slash_bits)
Definition: state.cc:148
A tokenized string that contains variable references.
Definition: eval_env.h:59