diff options
author | Evan Martin <martine@danga.com> | 2012-04-26 03:23:26 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-04-26 03:23:26 (GMT) |
commit | 496f7729009c46691a3210fcb67c418aa102da96 (patch) | |
tree | 7cbbb34ada96929eb2af1af0be266375445a9000 /src/build_test.cc | |
parent | 3fda08c34d4c91a4d16855ce40a2d0ab13a4d768 (diff) | |
parent | eeb572aa84564768311b70e14c5b5354a31bfd29 (diff) | |
download | Ninja-496f7729009c46691a3210fcb67c418aa102da96.zip Ninja-496f7729009c46691a3210fcb67c418aa102da96.tar.gz Ninja-496f7729009c46691a3210fcb67c418aa102da96.tar.bz2 |
Merge branch 'custom_ninja_status' of git://github.com/polrop/ninja
Diffstat (limited to 'src/build_test.cc')
-rw-r--r-- | src/build_test.cc | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/src/build_test.cc b/src/build_test.cc index c015bc9..f3f5472 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -179,7 +179,7 @@ TEST_F(PlanTest, DependencyCycle) { struct BuildTest : public StateTestWithBuiltinRules, public CommandRunner { BuildTest() : config_(MakeConfig()), builder_(&state_, config_), now_(1), - last_command_(NULL) { + last_command_(NULL), status_(config_) { builder_.disk_interface_ = &fs_; builder_.command_runner_.reset(this); AssertParse(&state_, @@ -202,8 +202,8 @@ struct BuildTest : public StateTestWithBuiltinRules, virtual bool CanRunMore(); virtual bool StartCommand(Edge* edge); virtual Edge* WaitForCommand(ExitStatus* status, string* output); - virtual vector<Edge*> GetActiveEdges(); - virtual void Abort(); + virtual vector<Edge*> GetActiveEdges(); + virtual void Abort(); BuildConfig MakeConfig() { BuildConfig config; @@ -219,6 +219,7 @@ struct BuildTest : public StateTestWithBuiltinRules, vector<string> commands_ran_; Edge* last_command_; + BuildStatus status_; }; void BuildTest::Dirty(const string& path) { @@ -853,7 +854,7 @@ TEST_F(BuildTest, RspFileSuccess) fs_.Create("out1", now_, ""); fs_.Create("out2", now_, ""); fs_.Create("out3", now_, ""); - + now_++; fs_.Create("in", now_, ""); @@ -869,11 +870,11 @@ TEST_F(BuildTest, RspFileSuccess) EXPECT_TRUE(builder_.Build(&err)); ASSERT_EQ(2u, commands_ran_.size()); // cat + cat_rsp - + // The RSP file was created ASSERT_EQ(files_created + 1, fs_.files_created_.size()); ASSERT_EQ(1u, fs_.files_created_.count("out2.rsp")); - + // The RSP file was removed ASSERT_EQ(files_removed + 1, fs_.files_removed_.size()); ASSERT_EQ(1u, fs_.files_removed_.count("out2.rsp")); @@ -917,7 +918,7 @@ TEST_F(BuildTest, RspFileFailure) { ASSERT_EQ("Another very long command", fs_.files_["out.rsp"].contents); } -// Test that contens of the RSP file behaves like a regular part of +// Test that contens of the RSP file behaves like a regular part of // command line, i.e. triggers a rebuild if changed TEST_F(BuildWithLogTest, RspFileCmdLineChange) { ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, @@ -948,7 +949,7 @@ TEST_F(BuildWithLogTest, RspFileCmdLineChange) { EXPECT_EQ("", err); ASSERT_TRUE(builder_.AlreadyUpToDate()); - // 3. Alter the entry in the logfile + // 3. Alter the entry in the logfile // (to simulate a change in the command line between 2 builds) BuildLog::LogEntry * log_entry = build_log_.LookupByOutput("out"); ASSERT_TRUE(NULL != log_entry); @@ -1022,3 +1023,37 @@ TEST_F(BuildTest, PhonyWithNoInputs) { EXPECT_EQ("", err); ASSERT_EQ(1u, commands_ran_.size()); } + +TEST_F(BuildTest, StatusFormatBufferTooSmall) { + const int kBUFF_SIZE = 5; + char buff[kBUFF_SIZE] = { '\0' }; + string err; + + EXPECT_EQ(-1, status_.FormatProgressStatus("0123456789", + buff, kBUFF_SIZE, + &err)); + EXPECT_EQ("custom NINJA_STATUS exceed buffer size 5", err); +} + +TEST_F(BuildTest, StatusFormatWrongPlaceholder) { + const int kBUFF_SIZE = 1024; + char buff[kBUFF_SIZE] = { '\0' }; + string err; + + EXPECT_EQ(-1, status_.FormatProgressStatus("[%r/%X]", + buff, kBUFF_SIZE, + &err)); + EXPECT_EQ("unknown placeholders '%X' in NINJA_STATUS", err); +} + +TEST_F(BuildTest, StatusFormatReplacePlaceholder) { + const int kBUFF_SIZE = 1024; + char buff[kBUFF_SIZE] = { '\0' }; + string err; + + EXPECT_EQ(18, status_.FormatProgressStatus("[%%/s%s/t%t/r%r/u%u/f%f]", + buff, kBUFF_SIZE, + &err)); + EXPECT_EQ("", err); + EXPECT_STREQ("[%/s0/t0/r0/u0/f0]", buff); +} |