Merge pull request #455 from azuk/master
[platform/upstream/ninja.git] / src / build_test.cc
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 "build.h"
16
17 #include "build_log.h"
18 #include "graph.h"
19 #include "test.h"
20
21 /// Fixture for tests involving Plan.
22 // Though Plan doesn't use State, it's useful to have one around
23 // to create Nodes and Edges.
24 struct PlanTest : public StateTestWithBuiltinRules {
25   Plan plan_;
26 };
27
28 TEST_F(PlanTest, Basic) {
29   AssertParse(&state_,
30 "build out: cat mid\n"
31 "build mid: cat in\n");
32   GetNode("mid")->MarkDirty();
33   GetNode("out")->MarkDirty();
34   string err;
35   EXPECT_TRUE(plan_.AddTarget(GetNode("out"), &err));
36   ASSERT_EQ("", err);
37   ASSERT_TRUE(plan_.more_to_do());
38
39   Edge* edge = plan_.FindWork();
40   ASSERT_TRUE(edge);
41   ASSERT_EQ("in",  edge->inputs_[0]->path());
42   ASSERT_EQ("mid", edge->outputs_[0]->path());
43
44   ASSERT_FALSE(plan_.FindWork());
45
46   plan_.EdgeFinished(edge);
47
48   edge = plan_.FindWork();
49   ASSERT_TRUE(edge);
50   ASSERT_EQ("mid", edge->inputs_[0]->path());
51   ASSERT_EQ("out", edge->outputs_[0]->path());
52
53   plan_.EdgeFinished(edge);
54
55   ASSERT_FALSE(plan_.more_to_do());
56   edge = plan_.FindWork();
57   ASSERT_EQ(0, edge);
58 }
59
60 // Test that two outputs from one rule can be handled as inputs to the next.
61 TEST_F(PlanTest, DoubleOutputDirect) {
62   AssertParse(&state_,
63 "build out: cat mid1 mid2\n"
64 "build mid1 mid2: cat in\n");
65   GetNode("mid1")->MarkDirty();
66   GetNode("mid2")->MarkDirty();
67   GetNode("out")->MarkDirty();
68
69   string err;
70   EXPECT_TRUE(plan_.AddTarget(GetNode("out"), &err));
71   ASSERT_EQ("", err);
72   ASSERT_TRUE(plan_.more_to_do());
73
74   Edge* edge;
75   edge = plan_.FindWork();
76   ASSERT_TRUE(edge);  // cat in
77   plan_.EdgeFinished(edge);
78
79   edge = plan_.FindWork();
80   ASSERT_TRUE(edge);  // cat mid1 mid2
81   plan_.EdgeFinished(edge);
82
83   edge = plan_.FindWork();
84   ASSERT_FALSE(edge);  // done
85 }
86
87 // Test that two outputs from one rule can eventually be routed to another.
88 TEST_F(PlanTest, DoubleOutputIndirect) {
89   AssertParse(&state_,
90 "build out: cat b1 b2\n"
91 "build b1: cat a1\n"
92 "build b2: cat a2\n"
93 "build a1 a2: cat in\n");
94   GetNode("a1")->MarkDirty();
95   GetNode("a2")->MarkDirty();
96   GetNode("b1")->MarkDirty();
97   GetNode("b2")->MarkDirty();
98   GetNode("out")->MarkDirty();
99   string err;
100   EXPECT_TRUE(plan_.AddTarget(GetNode("out"), &err));
101   ASSERT_EQ("", err);
102   ASSERT_TRUE(plan_.more_to_do());
103
104   Edge* edge;
105   edge = plan_.FindWork();
106   ASSERT_TRUE(edge);  // cat in
107   plan_.EdgeFinished(edge);
108
109   edge = plan_.FindWork();
110   ASSERT_TRUE(edge);  // cat a1
111   plan_.EdgeFinished(edge);
112
113   edge = plan_.FindWork();
114   ASSERT_TRUE(edge);  // cat a2
115   plan_.EdgeFinished(edge);
116
117   edge = plan_.FindWork();
118   ASSERT_TRUE(edge);  // cat b1 b2
119   plan_.EdgeFinished(edge);
120
121   edge = plan_.FindWork();
122   ASSERT_FALSE(edge);  // done
123 }
124
125 // Test that two edges from one output can both execute.
126 TEST_F(PlanTest, DoubleDependent) {
127   AssertParse(&state_,
128 "build out: cat a1 a2\n"
129 "build a1: cat mid\n"
130 "build a2: cat mid\n"
131 "build mid: cat in\n");
132   GetNode("mid")->MarkDirty();
133   GetNode("a1")->MarkDirty();
134   GetNode("a2")->MarkDirty();
135   GetNode("out")->MarkDirty();
136
137   string err;
138   EXPECT_TRUE(plan_.AddTarget(GetNode("out"), &err));
139   ASSERT_EQ("", err);
140   ASSERT_TRUE(plan_.more_to_do());
141
142   Edge* edge;
143   edge = plan_.FindWork();
144   ASSERT_TRUE(edge);  // cat in
145   plan_.EdgeFinished(edge);
146
147   edge = plan_.FindWork();
148   ASSERT_TRUE(edge);  // cat mid
149   plan_.EdgeFinished(edge);
150
151   edge = plan_.FindWork();
152   ASSERT_TRUE(edge);  // cat mid
153   plan_.EdgeFinished(edge);
154
155   edge = plan_.FindWork();
156   ASSERT_TRUE(edge);  // cat a1 a2
157   plan_.EdgeFinished(edge);
158
159   edge = plan_.FindWork();
160   ASSERT_FALSE(edge);  // done
161 }
162
163 TEST_F(PlanTest, DependencyCycle) {
164   AssertParse(&state_,
165 "build out: cat mid\n"
166 "build mid: cat in\n"
167 "build in: cat pre\n"
168 "build pre: cat out\n");
169   GetNode("out")->MarkDirty();
170   GetNode("mid")->MarkDirty();
171   GetNode("in")->MarkDirty();
172   GetNode("pre")->MarkDirty();
173
174   string err;
175   EXPECT_FALSE(plan_.AddTarget(GetNode("out"), &err));
176   ASSERT_EQ("dependency cycle: out -> mid -> in -> pre -> out", err);
177 }
178
179 TEST_F(PlanTest, PoolWithDepthOne) {
180   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
181 "pool foobar\n"
182 "  depth = 1\n"
183 "rule poolcat\n"
184 "  command = cat $in > $out\n"
185 "  pool = foobar\n"
186 "build out1: poolcat in\n"
187 "build out2: poolcat in\n"));
188   GetNode("out1")->MarkDirty();
189   GetNode("out2")->MarkDirty();
190   string err;
191   EXPECT_TRUE(plan_.AddTarget(GetNode("out1"), &err));
192   ASSERT_EQ("", err);
193   EXPECT_TRUE(plan_.AddTarget(GetNode("out2"), &err));
194   ASSERT_EQ("", err);
195   ASSERT_TRUE(plan_.more_to_do());
196
197   Edge* edge = plan_.FindWork();
198   ASSERT_TRUE(edge);
199   ASSERT_EQ("in",  edge->inputs_[0]->path());
200   ASSERT_EQ("out1", edge->outputs_[0]->path());
201
202   // This will be false since poolcat is serialized
203   ASSERT_FALSE(plan_.FindWork());
204
205   plan_.EdgeFinished(edge);
206
207   edge = plan_.FindWork();
208   ASSERT_TRUE(edge);
209   ASSERT_EQ("in", edge->inputs_[0]->path());
210   ASSERT_EQ("out2", edge->outputs_[0]->path());
211
212   ASSERT_FALSE(plan_.FindWork());
213
214   plan_.EdgeFinished(edge);
215
216   ASSERT_FALSE(plan_.more_to_do());
217   edge = plan_.FindWork();
218   ASSERT_EQ(0, edge);
219 }
220
221 TEST_F(PlanTest, PoolsWithDepthTwo) {
222   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
223 "pool foobar\n"
224 "  depth = 2\n"
225 "pool bazbin\n"
226 "  depth = 2\n"
227 "rule foocat\n"
228 "  command = cat $in > $out\n"
229 "  pool = foobar\n"
230 "rule bazcat\n"
231 "  command = cat $in > $out\n"
232 "  pool = bazbin\n"
233 "build out1: foocat in\n"
234 "build out2: foocat in\n"
235 "build out3: foocat in\n"
236 "build outb1: bazcat in\n"
237 "build outb2: bazcat in\n"
238 "build outb3: bazcat in\n"
239 "  pool =\n"
240 "build allTheThings: cat out1 out2 out3 outb1 outb2 outb3\n"
241 ));
242   // Mark all the out* nodes dirty
243   for (int i = 0; i < 3; ++i) {
244     GetNode("out" + string(1, '1' + i))->MarkDirty();
245     GetNode("outb" + string(1, '1' + i))->MarkDirty();
246   }
247   GetNode("allTheThings")->MarkDirty();
248
249   string err;
250   EXPECT_TRUE(plan_.AddTarget(GetNode("allTheThings"), &err));
251   ASSERT_EQ("", err);
252
253   // Grab the first 4 edges, out1 out2 outb1 outb2
254   deque<Edge*> edges;
255   for (int i = 0; i < 4; ++i) {
256     ASSERT_TRUE(plan_.more_to_do());
257     Edge* edge = plan_.FindWork();
258     ASSERT_TRUE(edge);
259     ASSERT_EQ("in",  edge->inputs_[0]->path());
260     string base_name(i < 2 ? "out" : "outb");
261     ASSERT_EQ(base_name + string(1, '1' + (i % 2)), edge->outputs_[0]->path());
262     edges.push_back(edge);
263   }
264
265   // outb3 is exempt because it has an empty pool
266   ASSERT_TRUE(plan_.more_to_do());
267   Edge* edge = plan_.FindWork();
268   ASSERT_TRUE(edge);
269   ASSERT_EQ("in",  edge->inputs_[0]->path());
270   ASSERT_EQ("outb3", edge->outputs_[0]->path());
271   edges.push_back(edge);
272
273   ASSERT_FALSE(plan_.FindWork());
274
275   // finish out1
276   plan_.EdgeFinished(edges.front());
277   edges.pop_front();
278
279   // out3 should be available
280   Edge* out3 = plan_.FindWork();
281   ASSERT_TRUE(out3);
282   ASSERT_EQ("in",  out3->inputs_[0]->path());
283   ASSERT_EQ("out3", out3->outputs_[0]->path());
284
285   ASSERT_FALSE(plan_.FindWork());
286
287   plan_.EdgeFinished(out3);
288
289   ASSERT_FALSE(plan_.FindWork());
290
291   for (deque<Edge*>::iterator it = edges.begin(); it != edges.end(); ++it) {
292     plan_.EdgeFinished(*it);
293   }
294
295   Edge* final = plan_.FindWork();
296   ASSERT_TRUE(final);
297   ASSERT_EQ("allTheThings", final->outputs_[0]->path());
298
299   plan_.EdgeFinished(final);
300
301   ASSERT_FALSE(plan_.more_to_do());
302   ASSERT_FALSE(plan_.FindWork());
303 }
304
305 struct BuildTest : public StateTestWithBuiltinRules,
306                    public CommandRunner {
307   BuildTest() : config_(MakeConfig()),
308                 builder_(&state_, config_, NULL, &fs_),
309                 now_(1), last_command_(NULL), status_(config_) {
310     builder_.command_runner_.reset(this);
311     AssertParse(&state_,
312 "build cat1: cat in1\n"
313 "build cat2: cat in1 in2\n"
314 "build cat12: cat cat1 cat2\n");
315
316     fs_.Create("in1", now_, "");
317     fs_.Create("in2", now_, "");
318   }
319
320   ~BuildTest() {
321     builder_.command_runner_.release();
322   }
323
324   // Mark a path dirty.
325   void Dirty(const string& path);
326
327   // CommandRunner impl
328   virtual bool CanRunMore();
329   virtual bool StartCommand(Edge* edge);
330   virtual Edge* WaitForCommand(ExitStatus* status, string* output);
331   virtual vector<Edge*> GetActiveEdges();
332   virtual void Abort();
333
334   BuildConfig MakeConfig() {
335     BuildConfig config;
336     config.verbosity = BuildConfig::QUIET;
337     return config;
338   }
339
340   BuildConfig config_;
341   VirtualFileSystem fs_;
342   Builder builder_;
343   int now_;
344
345   vector<string> commands_ran_;
346   Edge* last_command_;
347   BuildStatus status_;
348 };
349
350 void BuildTest::Dirty(const string& path) {
351   Node* node = GetNode(path);
352   node->MarkDirty();
353
354   // If it's an input file, mark that we've already stat()ed it and
355   // it's missing.
356   if (!node->in_edge())
357     node->MarkMissing();
358 }
359
360 bool BuildTest::CanRunMore() {
361   // Only run one at a time.
362   return last_command_ == NULL;
363 }
364
365 bool BuildTest::StartCommand(Edge* edge) {
366   assert(!last_command_);
367   commands_ran_.push_back(edge->EvaluateCommand());
368   if (edge->rule().name() == "cat"  ||
369       edge->rule().name() == "cat_rsp" ||
370       edge->rule().name() == "cc" ||
371       edge->rule().name() == "touch" ||
372       edge->rule().name() == "touch-interrupt") {
373     for (vector<Node*>::iterator out = edge->outputs_.begin();
374          out != edge->outputs_.end(); ++out) {
375       fs_.Create((*out)->path(), now_, "");
376     }
377   } else if (edge->rule().name() == "true" ||
378              edge->rule().name() == "fail" ||
379              edge->rule().name() == "interrupt") {
380     // Don't do anything.
381   } else {
382     printf("unknown command\n");
383     return false;
384   }
385
386   last_command_ = edge;
387   return true;
388 }
389
390 Edge* BuildTest::WaitForCommand(ExitStatus* status, string* /* output */) {
391   if (Edge* edge = last_command_) {
392     if (edge->rule().name() == "interrupt" ||
393         edge->rule().name() == "touch-interrupt") {
394       *status = ExitInterrupted;
395       return NULL;
396     }
397
398     if (edge->rule().name() == "fail")
399       *status = ExitFailure;
400     else
401       *status = ExitSuccess;
402     last_command_ = NULL;
403     return edge;
404   }
405   *status = ExitFailure;
406   return NULL;
407 }
408
409 vector<Edge*> BuildTest::GetActiveEdges() {
410   vector<Edge*> edges;
411   if (last_command_)
412     edges.push_back(last_command_);
413   return edges;
414 }
415
416 void BuildTest::Abort() {
417   last_command_ = NULL;
418 }
419
420 TEST_F(BuildTest, NoWork) {
421   string err;
422   EXPECT_TRUE(builder_.AlreadyUpToDate());
423 }
424
425 TEST_F(BuildTest, OneStep) {
426   // Given a dirty target with one ready input,
427   // we should rebuild the target.
428   Dirty("cat1");
429   string err;
430   EXPECT_TRUE(builder_.AddTarget("cat1", &err));
431   ASSERT_EQ("", err);
432   EXPECT_TRUE(builder_.Build(&err));
433   ASSERT_EQ("", err);
434
435   ASSERT_EQ(1u, commands_ran_.size());
436   EXPECT_EQ("cat in1 > cat1", commands_ran_[0]);
437 }
438
439 TEST_F(BuildTest, OneStep2) {
440   // Given a target with one dirty input,
441   // we should rebuild the target.
442   Dirty("cat1");
443   string err;
444   EXPECT_TRUE(builder_.AddTarget("cat1", &err));
445   ASSERT_EQ("", err);
446   EXPECT_TRUE(builder_.Build(&err));
447   EXPECT_EQ("", err);
448
449   ASSERT_EQ(1u, commands_ran_.size());
450   EXPECT_EQ("cat in1 > cat1", commands_ran_[0]);
451 }
452
453 TEST_F(BuildTest, TwoStep) {
454   string err;
455   EXPECT_TRUE(builder_.AddTarget("cat12", &err));
456   ASSERT_EQ("", err);
457   EXPECT_TRUE(builder_.Build(&err));
458   EXPECT_EQ("", err);
459   ASSERT_EQ(3u, commands_ran_.size());
460   // Depending on how the pointers work out, we could've ran
461   // the first two commands in either order.
462   EXPECT_TRUE((commands_ran_[0] == "cat in1 > cat1" &&
463                commands_ran_[1] == "cat in1 in2 > cat2") ||
464               (commands_ran_[1] == "cat in1 > cat1" &&
465                commands_ran_[0] == "cat in1 in2 > cat2"));
466
467   EXPECT_EQ("cat cat1 cat2 > cat12", commands_ran_[2]);
468
469   now_++;
470
471   // Modifying in2 requires rebuilding one intermediate file
472   // and the final file.
473   fs_.Create("in2", now_, "");
474   state_.Reset();
475   EXPECT_TRUE(builder_.AddTarget("cat12", &err));
476   ASSERT_EQ("", err);
477   EXPECT_TRUE(builder_.Build(&err));
478   ASSERT_EQ("", err);
479   ASSERT_EQ(5u, commands_ran_.size());
480   EXPECT_EQ("cat in1 in2 > cat2", commands_ran_[3]);
481   EXPECT_EQ("cat cat1 cat2 > cat12", commands_ran_[4]);
482 }
483
484 TEST_F(BuildTest, TwoOutputs) {
485   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
486 "rule touch\n"
487 "  command = touch $out\n"
488 "build out1 out2: touch in.txt\n"));
489
490   fs_.Create("in.txt", now_, "");
491
492   string err;
493   EXPECT_TRUE(builder_.AddTarget("out1", &err));
494   ASSERT_EQ("", err);
495   EXPECT_TRUE(builder_.Build(&err));
496   EXPECT_EQ("", err);
497   ASSERT_EQ(1u, commands_ran_.size());
498   EXPECT_EQ("touch out1 out2", commands_ran_[0]);
499 }
500
501 // Test case from
502 //   https://github.com/martine/ninja/issues/148
503 TEST_F(BuildTest, MultiOutIn) {
504   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
505 "rule touch\n"
506 "  command = touch $out\n"
507 "build in1 otherfile: touch in\n"
508 "build out: touch in | in1\n"));
509
510   fs_.Create("in", now_, "");
511   fs_.Create("in1", ++now_, "");
512
513   string err;
514   EXPECT_TRUE(builder_.AddTarget("out", &err));
515   ASSERT_EQ("", err);
516   EXPECT_TRUE(builder_.Build(&err));
517   EXPECT_EQ("", err);
518 }
519
520 TEST_F(BuildTest, Chain) {
521   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
522 "build c2: cat c1\n"
523 "build c3: cat c2\n"
524 "build c4: cat c3\n"
525 "build c5: cat c4\n"));
526
527   fs_.Create("c1", now_, "");
528
529   string err;
530   EXPECT_TRUE(builder_.AddTarget("c5", &err));
531   ASSERT_EQ("", err);
532   EXPECT_TRUE(builder_.Build(&err));
533   EXPECT_EQ("", err);
534   ASSERT_EQ(4u, commands_ran_.size());
535
536   err.clear();
537   commands_ran_.clear();
538   state_.Reset();
539   EXPECT_TRUE(builder_.AddTarget("c5", &err));
540   ASSERT_EQ("", err);
541   EXPECT_TRUE(builder_.AlreadyUpToDate());
542
543   now_++;
544
545   fs_.Create("c3", now_, "");
546   err.clear();
547   commands_ran_.clear();
548   state_.Reset();
549   EXPECT_TRUE(builder_.AddTarget("c5", &err));
550   ASSERT_EQ("", err);
551   EXPECT_FALSE(builder_.AlreadyUpToDate());
552   EXPECT_TRUE(builder_.Build(&err));
553   ASSERT_EQ(2u, commands_ran_.size());  // 3->4, 4->5
554 }
555
556 TEST_F(BuildTest, MissingInput) {
557   // Input is referenced by build file, but no rule for it.
558   string err;
559   Dirty("in1");
560   EXPECT_FALSE(builder_.AddTarget("cat1", &err));
561   EXPECT_EQ("'in1', needed by 'cat1', missing and no known rule to make it",
562             err);
563 }
564
565 TEST_F(BuildTest, MissingTarget) {
566   // Target is not referenced by build file.
567   string err;
568   EXPECT_FALSE(builder_.AddTarget("meow", &err));
569   EXPECT_EQ("unknown target: 'meow'", err);
570 }
571
572 TEST_F(BuildTest, MakeDirs) {
573   string err;
574
575 #ifdef _WIN32
576   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, "build subdir\\dir2\\file: cat in1\n"));
577   EXPECT_TRUE(builder_.AddTarget("subdir\\dir2\\file", &err));
578 #else
579   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, "build subdir/dir2/file: cat in1\n"));
580   EXPECT_TRUE(builder_.AddTarget("subdir/dir2/file", &err));
581 #endif
582
583   EXPECT_EQ("", err);
584   now_ = 0;  // Make all stat()s return file not found.
585   EXPECT_TRUE(builder_.Build(&err));
586   ASSERT_EQ("", err);
587   ASSERT_EQ(2u, fs_.directories_made_.size());
588   EXPECT_EQ("subdir", fs_.directories_made_[0]);
589 #ifdef _WIN32
590   EXPECT_EQ("subdir\\dir2", fs_.directories_made_[1]);
591 #else
592   EXPECT_EQ("subdir/dir2", fs_.directories_made_[1]);
593 #endif
594 }
595
596 TEST_F(BuildTest, DepFileMissing) {
597   string err;
598   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
599 "rule cc\n  command = cc $in\n  depfile = $out.d\n"
600 "build foo.o: cc foo.c\n"));
601   fs_.Create("foo.c", now_, "");
602
603   EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
604   ASSERT_EQ("", err);
605   ASSERT_EQ(1u, fs_.files_read_.size());
606   EXPECT_EQ("foo.o.d", fs_.files_read_[0]);
607 }
608
609 TEST_F(BuildTest, DepFileOK) {
610   string err;
611   int orig_edges = state_.edges_.size();
612   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
613 "rule cc\n  command = cc $in\n  depfile = $out.d\n"
614 "build foo.o: cc foo.c\n"));
615   Edge* edge = state_.edges_.back();
616
617   fs_.Create("foo.c", now_, "");
618   GetNode("bar.h")->MarkDirty();  // Mark bar.h as missing.
619   fs_.Create("foo.o.d", now_, "foo.o: blah.h bar.h\n");
620   EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
621   ASSERT_EQ("", err);
622   ASSERT_EQ(1u, fs_.files_read_.size());
623   EXPECT_EQ("foo.o.d", fs_.files_read_[0]);
624
625   // Expect three new edges: one generating foo.o, and two more from
626   // loading the depfile.
627   ASSERT_EQ(orig_edges + 3, (int)state_.edges_.size());
628   // Expect our edge to now have three inputs: foo.c and two headers.
629   ASSERT_EQ(3u, edge->inputs_.size());
630
631   // Expect the command line we generate to only use the original input.
632   ASSERT_EQ("cc foo.c", edge->EvaluateCommand());
633 }
634
635 TEST_F(BuildTest, DepFileParseError) {
636   string err;
637   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
638 "rule cc\n  command = cc $in\n  depfile = $out.d\n"
639 "build foo.o: cc foo.c\n"));
640   fs_.Create("foo.c", now_, "");
641   fs_.Create("foo.o.d", now_, "randomtext\n");
642   EXPECT_FALSE(builder_.AddTarget("foo.o", &err));
643   EXPECT_EQ("expected depfile 'foo.o.d' to mention 'foo.o', got 'randomtext'",
644             err);
645 }
646
647 TEST_F(BuildTest, OrderOnlyDeps) {
648   string err;
649   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
650 "rule cc\n  command = cc $in\n  depfile = $out.d\n"
651 "build foo.o: cc foo.c || otherfile\n"));
652   Edge* edge = state_.edges_.back();
653
654   fs_.Create("foo.c", now_, "");
655   fs_.Create("otherfile", now_, "");
656   fs_.Create("foo.o.d", now_, "foo.o: blah.h bar.h\n");
657   EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
658   ASSERT_EQ("", err);
659
660   // One explicit, two implicit, one order only.
661   ASSERT_EQ(4u, edge->inputs_.size());
662   EXPECT_EQ(2, edge->implicit_deps_);
663   EXPECT_EQ(1, edge->order_only_deps_);
664   // Verify the inputs are in the order we expect
665   // (explicit then implicit then orderonly).
666   EXPECT_EQ("foo.c", edge->inputs_[0]->path());
667   EXPECT_EQ("blah.h", edge->inputs_[1]->path());
668   EXPECT_EQ("bar.h", edge->inputs_[2]->path());
669   EXPECT_EQ("otherfile", edge->inputs_[3]->path());
670
671   // Expect the command line we generate to only use the original input.
672   ASSERT_EQ("cc foo.c", edge->EvaluateCommand());
673
674   // explicit dep dirty, expect a rebuild.
675   EXPECT_TRUE(builder_.Build(&err));
676   ASSERT_EQ("", err);
677   ASSERT_EQ(1u, commands_ran_.size());
678
679   now_++;
680
681   // implicit dep dirty, expect a rebuild.
682   fs_.Create("blah.h", now_, "");
683   fs_.Create("bar.h", now_, "");
684   commands_ran_.clear();
685   state_.Reset();
686   EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
687   EXPECT_TRUE(builder_.Build(&err));
688   ASSERT_EQ("", err);
689   ASSERT_EQ(1u, commands_ran_.size());
690
691   now_++;
692
693   // order only dep dirty, no rebuild.
694   fs_.Create("otherfile", now_, "");
695   commands_ran_.clear();
696   state_.Reset();
697   EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
698   EXPECT_EQ("", err);
699   EXPECT_TRUE(builder_.AlreadyUpToDate());
700
701   // implicit dep missing, expect rebuild.
702   fs_.RemoveFile("bar.h");
703   commands_ran_.clear();
704   state_.Reset();
705   EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
706   EXPECT_TRUE(builder_.Build(&err));
707   ASSERT_EQ("", err);
708   ASSERT_EQ(1u, commands_ran_.size());
709 }
710
711 TEST_F(BuildTest, RebuildOrderOnlyDeps) {
712   string err;
713   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
714 "rule cc\n  command = cc $in\n"
715 "rule true\n  command = true\n"
716 "build oo.h: cc oo.h.in\n"
717 "build foo.o: cc foo.c || oo.h\n"));
718
719   fs_.Create("foo.c", now_, "");
720   fs_.Create("oo.h.in", now_, "");
721
722   // foo.o and order-only dep dirty, build both.
723   EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
724   EXPECT_TRUE(builder_.Build(&err));
725   ASSERT_EQ("", err);
726   ASSERT_EQ(2u, commands_ran_.size());
727
728   // all clean, no rebuild.
729   commands_ran_.clear();
730   state_.Reset();
731   EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
732   EXPECT_EQ("", err);
733   EXPECT_TRUE(builder_.AlreadyUpToDate());
734
735   // order-only dep missing, build it only.
736   fs_.RemoveFile("oo.h");
737   commands_ran_.clear();
738   state_.Reset();
739   EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
740   EXPECT_TRUE(builder_.Build(&err));
741   ASSERT_EQ("", err);
742   ASSERT_EQ(1u, commands_ran_.size());
743   ASSERT_EQ("cc oo.h.in", commands_ran_[0]);
744
745   now_++;
746
747   // order-only dep dirty, build it only.
748   fs_.Create("oo.h.in", now_, "");
749   commands_ran_.clear();
750   state_.Reset();
751   EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
752   EXPECT_TRUE(builder_.Build(&err));
753   ASSERT_EQ("", err);
754   ASSERT_EQ(1u, commands_ran_.size());
755   ASSERT_EQ("cc oo.h.in", commands_ran_[0]);
756 }
757
758 TEST_F(BuildTest, Phony) {
759   string err;
760   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
761 "build out: cat bar.cc\n"
762 "build all: phony out\n"));
763   fs_.Create("bar.cc", now_, "");
764
765   EXPECT_TRUE(builder_.AddTarget("all", &err));
766   ASSERT_EQ("", err);
767
768   // Only one command to run, because phony runs no command.
769   EXPECT_FALSE(builder_.AlreadyUpToDate());
770   EXPECT_TRUE(builder_.Build(&err));
771   ASSERT_EQ("", err);
772   ASSERT_EQ(1u, commands_ran_.size());
773 }
774
775 TEST_F(BuildTest, PhonyNoWork) {
776   string err;
777   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
778 "build out: cat bar.cc\n"
779 "build all: phony out\n"));
780   fs_.Create("bar.cc", now_, "");
781   fs_.Create("out", now_, "");
782
783   EXPECT_TRUE(builder_.AddTarget("all", &err));
784   ASSERT_EQ("", err);
785   EXPECT_TRUE(builder_.AlreadyUpToDate());
786 }
787
788 TEST_F(BuildTest, Fail) {
789   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
790 "rule fail\n"
791 "  command = fail\n"
792 "build out1: fail\n"));
793
794   string err;
795   EXPECT_TRUE(builder_.AddTarget("out1", &err));
796   ASSERT_EQ("", err);
797
798   EXPECT_FALSE(builder_.Build(&err));
799   ASSERT_EQ(1u, commands_ran_.size());
800   ASSERT_EQ("subcommand failed", err);
801 }
802
803 TEST_F(BuildTest, SwallowFailures) {
804   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
805 "rule fail\n"
806 "  command = fail\n"
807 "build out1: fail\n"
808 "build out2: fail\n"
809 "build out3: fail\n"
810 "build all: phony out1 out2 out3\n"));
811
812   // Swallow two failures, die on the third.
813   config_.failures_allowed = 3;
814
815   string err;
816   EXPECT_TRUE(builder_.AddTarget("all", &err));
817   ASSERT_EQ("", err);
818
819   EXPECT_FALSE(builder_.Build(&err));
820   ASSERT_EQ(3u, commands_ran_.size());
821   ASSERT_EQ("subcommands failed", err);
822 }
823
824 TEST_F(BuildTest, SwallowFailuresLimit) {
825   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
826 "rule fail\n"
827 "  command = fail\n"
828 "build out1: fail\n"
829 "build out2: fail\n"
830 "build out3: fail\n"
831 "build final: cat out1 out2 out3\n"));
832
833   // Swallow ten failures; we should stop before building final.
834   config_.failures_allowed = 11;
835
836   string err;
837   EXPECT_TRUE(builder_.AddTarget("final", &err));
838   ASSERT_EQ("", err);
839
840   EXPECT_FALSE(builder_.Build(&err));
841   ASSERT_EQ(3u, commands_ran_.size());
842   ASSERT_EQ("cannot make progress due to previous errors", err);
843 }
844
845 struct BuildWithLogTest : public BuildTest {
846   BuildWithLogTest() {
847     builder_.SetBuildLog(&build_log_);
848   }
849
850   BuildLog build_log_;
851 };
852
853 TEST_F(BuildWithLogTest, NotInLogButOnDisk) {
854   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
855 "rule cc\n"
856 "  command = cc\n"
857 "build out1: cc in\n"));
858
859   // Create input/output that would be considered up to date when
860   // not considering the command line hash.
861   fs_.Create("in", now_, "");
862   fs_.Create("out1", now_, "");
863   string err;
864
865   // Because it's not in the log, it should not be up-to-date until
866   // we build again.
867   EXPECT_TRUE(builder_.AddTarget("out1", &err));
868   EXPECT_FALSE(builder_.AlreadyUpToDate());
869
870   commands_ran_.clear();
871   state_.Reset();
872
873   EXPECT_TRUE(builder_.AddTarget("out1", &err));
874   EXPECT_TRUE(builder_.Build(&err));
875   EXPECT_TRUE(builder_.AlreadyUpToDate());
876 }
877
878 TEST_F(BuildWithLogTest, RestatTest) {
879   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
880 "rule true\n"
881 "  command = true\n"
882 "  restat = 1\n"
883 "rule cc\n"
884 "  command = cc\n"
885 "  restat = 1\n"
886 "build out1: cc in\n"
887 "build out2: true out1\n"
888 "build out3: cat out2\n"));
889
890   fs_.Create("out1", now_, "");
891   fs_.Create("out2", now_, "");
892   fs_.Create("out3", now_, "");
893
894   now_++;
895
896   fs_.Create("in", now_, "");
897
898   // Do a pre-build so that there's commands in the log for the outputs,
899   // otherwise, the lack of an entry in the build log will cause out3 to rebuild
900   // regardless of restat.
901   string err;
902   EXPECT_TRUE(builder_.AddTarget("out3", &err));
903   ASSERT_EQ("", err);
904   EXPECT_TRUE(builder_.Build(&err));
905   ASSERT_EQ("", err);
906   commands_ran_.clear();
907   state_.Reset();
908
909   now_++;
910
911   fs_.Create("in", now_, "");
912   // "cc" touches out1, so we should build out2.  But because "true" does not
913   // touch out2, we should cancel the build of out3.
914   EXPECT_TRUE(builder_.AddTarget("out3", &err));
915   ASSERT_EQ("", err);
916   EXPECT_TRUE(builder_.Build(&err));
917   ASSERT_EQ(2u, commands_ran_.size());
918
919   // If we run again, it should be a no-op, because the build log has recorded
920   // that we've already built out2 with an input timestamp of 2 (from out1).
921   commands_ran_.clear();
922   state_.Reset();
923   EXPECT_TRUE(builder_.AddTarget("out3", &err));
924   ASSERT_EQ("", err);
925   EXPECT_TRUE(builder_.AlreadyUpToDate());
926
927   now_++;
928
929   fs_.Create("in", now_, "");
930
931   // The build log entry should not, however, prevent us from rebuilding out2
932   // if out1 changes.
933   commands_ran_.clear();
934   state_.Reset();
935   EXPECT_TRUE(builder_.AddTarget("out3", &err));
936   ASSERT_EQ("", err);
937   EXPECT_TRUE(builder_.Build(&err));
938   ASSERT_EQ(2u, commands_ran_.size());
939 }
940
941 TEST_F(BuildWithLogTest, RestatMissingFile) {
942   // If a restat rule doesn't create its output, and the output didn't
943   // exist before the rule was run, consider that behavior equivalent
944   // to a rule that doesn't modify its existent output file.
945
946   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
947 "rule true\n"
948 "  command = true\n"
949 "  restat = 1\n"
950 "rule cc\n"
951 "  command = cc\n"
952 "build out1: true in\n"
953 "build out2: cc out1\n"));
954
955   fs_.Create("in", now_, "");
956   fs_.Create("out2", now_, "");
957
958   // Do a pre-build so that there's commands in the log for the outputs,
959   // otherwise, the lack of an entry in the build log will cause out2 to rebuild
960   // regardless of restat.
961   string err;
962   EXPECT_TRUE(builder_.AddTarget("out2", &err));
963   ASSERT_EQ("", err);
964   EXPECT_TRUE(builder_.Build(&err));
965   ASSERT_EQ("", err);
966   commands_ran_.clear();
967   state_.Reset();
968
969   now_++;
970   fs_.Create("in", now_, "");
971   fs_.Create("out2", now_, "");
972
973   // Run a build, expect only the first command to run.
974   // It doesn't touch its output (due to being the "true" command), so
975   // we shouldn't run the dependent build.
976   EXPECT_TRUE(builder_.AddTarget("out2", &err));
977   ASSERT_EQ("", err);
978   EXPECT_TRUE(builder_.Build(&err));
979   ASSERT_EQ(1u, commands_ran_.size());
980 }
981
982 // Test scenario, in which an input file is removed, but output isn't changed
983 // https://github.com/martine/ninja/issues/295
984 TEST_F(BuildWithLogTest, RestatMissingInput) {
985   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
986     "rule true\n"
987     "  command = true\n"
988     "  depfile = $out.d\n"
989     "  restat = 1\n"
990     "rule cc\n"
991     "  command = cc\n"
992     "build out1: true in\n"
993     "build out2: cc out1\n"));
994
995   // Create all necessary files
996   fs_.Create("in", now_, "");
997
998   // The implicit dependencies and the depfile itself
999   // are newer than the output
1000   TimeStamp restat_mtime = ++now_;
1001   fs_.Create("out1.d", now_, "out1: will.be.deleted restat.file\n");
1002   fs_.Create("will.be.deleted", now_, "");
1003   fs_.Create("restat.file", now_, "");
1004
1005   // Run the build, out1 and out2 get built
1006   string err;
1007   EXPECT_TRUE(builder_.AddTarget("out2", &err));
1008   ASSERT_EQ("", err);
1009   EXPECT_TRUE(builder_.Build(&err));
1010   ASSERT_EQ(2u, commands_ran_.size());
1011
1012   // See that an entry in the logfile is created, capturing
1013   // the right mtime
1014   BuildLog::LogEntry * log_entry = build_log_.LookupByOutput("out1");
1015   ASSERT_TRUE(NULL != log_entry);
1016   ASSERT_EQ(restat_mtime, log_entry->restat_mtime);
1017
1018   // Now remove a file, referenced from depfile, so that target becomes
1019   // dirty, but the output does not change
1020   fs_.RemoveFile("will.be.deleted");
1021
1022   // Trigger the build again - only out1 gets built
1023   commands_ran_.clear();
1024   state_.Reset();
1025   EXPECT_TRUE(builder_.AddTarget("out2", &err));
1026   ASSERT_EQ("", err);
1027   EXPECT_TRUE(builder_.Build(&err));
1028   ASSERT_EQ(1u, commands_ran_.size());
1029
1030   // Check that the logfile entry remains correctly set
1031   log_entry = build_log_.LookupByOutput("out1");
1032   ASSERT_TRUE(NULL != log_entry);
1033   ASSERT_EQ(restat_mtime, log_entry->restat_mtime);
1034 }
1035
1036 struct BuildDryRun : public BuildWithLogTest {
1037   BuildDryRun() {
1038     config_.dry_run = true;
1039   }
1040 };
1041
1042 TEST_F(BuildDryRun, AllCommandsShown) {
1043   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1044 "rule true\n"
1045 "  command = true\n"
1046 "  restat = 1\n"
1047 "rule cc\n"
1048 "  command = cc\n"
1049 "  restat = 1\n"
1050 "build out1: cc in\n"
1051 "build out2: true out1\n"
1052 "build out3: cat out2\n"));
1053
1054   fs_.Create("out1", now_, "");
1055   fs_.Create("out2", now_, "");
1056   fs_.Create("out3", now_, "");
1057
1058   now_++;
1059
1060   fs_.Create("in", now_, "");
1061
1062   // "cc" touches out1, so we should build out2.  But because "true" does not
1063   // touch out2, we should cancel the build of out3.
1064   string err;
1065   EXPECT_TRUE(builder_.AddTarget("out3", &err));
1066   ASSERT_EQ("", err);
1067   EXPECT_TRUE(builder_.Build(&err));
1068   ASSERT_EQ(3u, commands_ran_.size());
1069 }
1070
1071 // Test that RSP files are created when & where appropriate and deleted after
1072 // successful execution.
1073 TEST_F(BuildTest, RspFileSuccess)
1074 {
1075   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1076     "rule cat_rsp\n"
1077     "  command = cat $rspfile > $out\n"
1078     "  rspfile = $rspfile\n"
1079     "  rspfile_content = $long_command\n"
1080     "build out1: cat in\n"
1081     "build out2: cat_rsp in\n"
1082     "  rspfile = out2.rsp\n"
1083     "  long_command = Some very long command\n"));
1084
1085   fs_.Create("out1", now_, "");
1086   fs_.Create("out2", now_, "");
1087   fs_.Create("out3", now_, "");
1088
1089   now_++;
1090
1091   fs_.Create("in", now_, "");
1092
1093   string err;
1094   EXPECT_TRUE(builder_.AddTarget("out1", &err));
1095   ASSERT_EQ("", err);
1096   EXPECT_TRUE(builder_.AddTarget("out2", &err));
1097   ASSERT_EQ("", err);
1098
1099   size_t files_created = fs_.files_created_.size();
1100   size_t files_removed = fs_.files_removed_.size();
1101
1102   EXPECT_TRUE(builder_.Build(&err));
1103   ASSERT_EQ(2u, commands_ran_.size()); // cat + cat_rsp
1104
1105   // The RSP file was created
1106   ASSERT_EQ(files_created + 1, fs_.files_created_.size());
1107   ASSERT_EQ(1u, fs_.files_created_.count("out2.rsp"));
1108
1109   // The RSP file was removed
1110   ASSERT_EQ(files_removed + 1, fs_.files_removed_.size());
1111   ASSERT_EQ(1u, fs_.files_removed_.count("out2.rsp"));
1112 }
1113
1114 // Test that RSP file is created but not removed for commands, which fail
1115 TEST_F(BuildTest, RspFileFailure) {
1116   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1117     "rule fail\n"
1118     "  command = fail\n"
1119     "  rspfile = $rspfile\n"
1120     "  rspfile_content = $long_command\n"
1121     "build out: fail in\n"
1122     "  rspfile = out.rsp\n"
1123     "  long_command = Another very long command\n"));
1124
1125   fs_.Create("out", now_, "");
1126   now_++;
1127   fs_.Create("in", now_, "");
1128
1129   string err;
1130   EXPECT_TRUE(builder_.AddTarget("out", &err));
1131   ASSERT_EQ("", err);
1132
1133   size_t files_created = fs_.files_created_.size();
1134   size_t files_removed = fs_.files_removed_.size();
1135
1136   EXPECT_FALSE(builder_.Build(&err));
1137   ASSERT_EQ("subcommand failed", err);
1138   ASSERT_EQ(1u, commands_ran_.size());
1139
1140   // The RSP file was created
1141   ASSERT_EQ(files_created + 1, fs_.files_created_.size());
1142   ASSERT_EQ(1u, fs_.files_created_.count("out.rsp"));
1143
1144   // The RSP file was NOT removed
1145   ASSERT_EQ(files_removed, fs_.files_removed_.size());
1146   ASSERT_EQ(0u, fs_.files_removed_.count("out.rsp"));
1147
1148   // The RSP file contains what it should
1149   ASSERT_EQ("Another very long command", fs_.files_["out.rsp"].contents);
1150 }
1151
1152 // Test that contens of the RSP file behaves like a regular part of
1153 // command line, i.e. triggers a rebuild if changed
1154 TEST_F(BuildWithLogTest, RspFileCmdLineChange) {
1155   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1156     "rule cat_rsp\n"
1157     "  command = cat $rspfile > $out\n"
1158     "  rspfile = $rspfile\n"
1159     "  rspfile_content = $long_command\n"
1160     "build out: cat_rsp in\n"
1161     "  rspfile = out.rsp\n"
1162     "  long_command = Original very long command\n"));
1163
1164   fs_.Create("out", now_, "");
1165   now_++;
1166   fs_.Create("in", now_, "");
1167
1168   string err;
1169   EXPECT_TRUE(builder_.AddTarget("out", &err));
1170   ASSERT_EQ("", err);
1171
1172   // 1. Build for the 1st time (-> populate log)
1173   EXPECT_TRUE(builder_.Build(&err));
1174   ASSERT_EQ(1u, commands_ran_.size());
1175
1176   // 2. Build again (no change)
1177   commands_ran_.clear();
1178   state_.Reset();
1179   EXPECT_TRUE(builder_.AddTarget("out", &err));
1180   EXPECT_EQ("", err);
1181   ASSERT_TRUE(builder_.AlreadyUpToDate());
1182
1183   // 3. Alter the entry in the logfile
1184   // (to simulate a change in the command line between 2 builds)
1185   BuildLog::LogEntry * log_entry = build_log_.LookupByOutput("out");
1186   ASSERT_TRUE(NULL != log_entry);
1187   ASSERT_NO_FATAL_FAILURE(AssertHash(
1188         "cat out.rsp > out;rspfile=Original very long command",
1189         log_entry->command_hash));
1190   log_entry->command_hash++;  // Change the command hash to something else.
1191   // Now expect the target to be rebuilt
1192   commands_ran_.clear();
1193   state_.Reset();
1194   EXPECT_TRUE(builder_.AddTarget("out", &err));
1195   EXPECT_EQ("", err);
1196   EXPECT_TRUE(builder_.Build(&err));
1197   EXPECT_EQ(1u, commands_ran_.size());
1198 }
1199
1200 TEST_F(BuildTest, InterruptCleanup) {
1201   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1202 "rule interrupt\n"
1203 "  command = interrupt\n"
1204 "rule touch-interrupt\n"
1205 "  command = touch-interrupt\n"
1206 "build out1: interrupt in1\n"
1207 "build out2: touch-interrupt in2\n"));
1208
1209   fs_.Create("out1", now_, "");
1210   fs_.Create("out2", now_, "");
1211   now_++;
1212   fs_.Create("in1", now_, "");
1213   fs_.Create("in2", now_, "");
1214
1215   // An untouched output of an interrupted command should be retained.
1216   string err;
1217   EXPECT_TRUE(builder_.AddTarget("out1", &err));
1218   EXPECT_EQ("", err);
1219   EXPECT_FALSE(builder_.Build(&err));
1220   EXPECT_EQ("interrupted by user", err);
1221   builder_.Cleanup();
1222   EXPECT_EQ(now_-1, fs_.Stat("out1"));
1223   err = "";
1224
1225   // A touched output of an interrupted command should be deleted.
1226   EXPECT_TRUE(builder_.AddTarget("out2", &err));
1227   EXPECT_EQ("", err);
1228   EXPECT_FALSE(builder_.Build(&err));
1229   EXPECT_EQ("interrupted by user", err);
1230   builder_.Cleanup();
1231   EXPECT_EQ(0, fs_.Stat("out2"));
1232 }
1233
1234 TEST_F(BuildTest, PhonyWithNoInputs) {
1235   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1236 "build nonexistent: phony\n"
1237 "build out1: cat || nonexistent\n"
1238 "build out2: cat nonexistent\n"));
1239   fs_.Create("out1", now_, "");
1240   fs_.Create("out2", now_, "");
1241
1242   // out1 should be up to date even though its input is dirty, because its
1243   // order-only dependency has nothing to do.
1244   string err;
1245   EXPECT_TRUE(builder_.AddTarget("out1", &err));
1246   ASSERT_EQ("", err);
1247   EXPECT_TRUE(builder_.AlreadyUpToDate());
1248
1249   // out2 should still be out of date though, because its input is dirty.
1250   err.clear();
1251   commands_ran_.clear();
1252   state_.Reset();
1253   EXPECT_TRUE(builder_.AddTarget("out2", &err));
1254   ASSERT_EQ("", err);
1255   EXPECT_TRUE(builder_.Build(&err));
1256   EXPECT_EQ("", err);
1257   ASSERT_EQ(1u, commands_ran_.size());
1258 }
1259
1260 TEST_F(BuildTest, StatusFormatReplacePlaceholder) {
1261   EXPECT_EQ("[%/s0/t0/r0/u0/f0]",
1262             status_.FormatProgressStatus("[%%/s%s/t%t/r%r/u%u/f%f]"));
1263 }
1264