diff options
Diffstat (limited to 'src/build_test.cc')
-rw-r--r-- | src/build_test.cc | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/build_test.cc b/src/build_test.cc index 467a908..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_, @@ -219,6 +219,7 @@ struct BuildTest : public StateTestWithBuiltinRules, vector<string> commands_ran_; Edge* last_command_; + BuildStatus status_; }; void BuildTest::Dirty(const string& path) { @@ -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); +} |