Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 72 lines (60 sloc) 1.953 kb
d52238f Evan Martin add copyrights
authored
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
9a6fd1a Evan Martin add a class for logging builds (commands + timing)
authored
15 #include "build_log.h"
16
17 #include "test.h"
18
667f48b Evan Martin remove tempnam
authored
19 static const char kTestFilename[] = "BuildLogTest-tempfile";
20
9a6fd1a Evan Martin add a class for logging builds (commands + timing)
authored
21 struct BuildLogTest : public StateTestWithBuiltinRules {
22 virtual void SetUp() {
23 }
24 virtual void TearDown() {
667f48b Evan Martin remove tempnam
authored
25 unlink(kTestFilename);
9a6fd1a Evan Martin add a class for logging builds (commands + timing)
authored
26 }
27 };
28
29 TEST_F(BuildLogTest, WriteRead) {
30 AssertParse(&state_,
31 "build out: cat mid\n"
32 "build mid: cat in\n");
33
34 BuildLog log1;
35 string err;
667f48b Evan Martin remove tempnam
authored
36 EXPECT_TRUE(log1.OpenForWrite(kTestFilename, &err));
9a6fd1a Evan Martin add a class for logging builds (commands + timing)
authored
37 ASSERT_EQ("", err);
38 log1.RecordCommand(state_.edges_[0], 15);
39 log1.RecordCommand(state_.edges_[1], 20);
40 log1.Close();
41
42 BuildLog log2;
667f48b Evan Martin remove tempnam
authored
43 EXPECT_TRUE(log2.Load(kTestFilename, &err));
9a6fd1a Evan Martin add a class for logging builds (commands + timing)
authored
44 ASSERT_EQ("", err);
45
46 ASSERT_EQ(2, log1.log_.size());
47 ASSERT_EQ(2, log2.log_.size());
48 BuildLog::LogEntry* e1 = log1.LookupByOutput("out");
49 ASSERT_TRUE(e1);
50 BuildLog::LogEntry* e2 = log2.LookupByOutput("out");
51 ASSERT_TRUE(e2);
52 ASSERT_TRUE(*e1 == *e2);
53 ASSERT_EQ(15, e1->time_ms);
54 ASSERT_EQ("out", e1->output);
55 }
681de18 Evan Martin later entry in build log should overwrite earlier one
authored
56
57 TEST_F(BuildLogTest, DoubleEntry) {
667f48b Evan Martin remove tempnam
authored
58 FILE* f = fopen(kTestFilename, "wb");
681de18 Evan Martin later entry in build log should overwrite earlier one
authored
59 fprintf(f, "0 out command abc\n");
60 fprintf(f, "0 out command def\n");
61 fclose(f);
62
63 string err;
64 BuildLog log;
667f48b Evan Martin remove tempnam
authored
65 EXPECT_TRUE(log.Load(kTestFilename, &err));
681de18 Evan Martin later entry in build log should overwrite earlier one
authored
66 ASSERT_EQ("", err);
67
68 BuildLog::LogEntry* e = log.LookupByOutput("out");
69 ASSERT_TRUE(e);
70 ASSERT_EQ("command def", e->command);
71 }
Something went wrong with that request. Please try again.