Skip to content

Commit

Permalink
Move StatusPrinter tests to their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjoer committed Sep 10, 2024
1 parent 9a76dce commit e75fabb
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 41 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ if(BUILD_TESTING)
src/missing_deps_test.cc
src/ninja_test.cc
src/state_test.cc
src/status_printer_test.cc
src/string_piece_util_test.cc
src/subprocess_test.cc
src/test.cc
Expand Down
41 changes: 0 additions & 41 deletions src/build_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2258,47 +2258,6 @@ TEST_F(BuildTest, DepsGccWithEmptyDepfileErrorsOut) {
ASSERT_EQ(1u, command_runner_.commands_ran_.size());
}

TEST_F(BuildTest, StatusFormatElapsed_e) {
status_.BuildStarted();
// Before any task is done, the elapsed time must be zero.
EXPECT_EQ("[%/e0.000]", status_.FormatProgressStatus("[%%/e%e]", 0));
}

TEST_F(BuildTest, StatusFormatElapsed_w) {
status_.BuildStarted();
// Before any task is done, the elapsed time must be zero.
EXPECT_EQ("[%/e00:00]", status_.FormatProgressStatus("[%%/e%w]", 0));
}

TEST_F(BuildTest, StatusFormatETA) {
status_.BuildStarted();
// Before any task is done, the ETA time must be unknown.
EXPECT_EQ("[%/E?]", status_.FormatProgressStatus("[%%/E%E]", 0));
}

TEST_F(BuildTest, StatusFormatTimeProgress) {
status_.BuildStarted();
// Before any task is done, the percentage of elapsed time must be zero.
EXPECT_EQ("[%/p 0%]", status_.FormatProgressStatus("[%%/p%p]", 0));
}

TEST_F(BuildTest, StatusFormatReplacePlaceholder) {
EXPECT_EQ("[%/s0/t0/r0/u0/f0]",
status_.FormatProgressStatus("[%%/s%s/t%t/r%r/u%u/f%f]", 0));
}

TEST_F(BuildTest, StatusFormatValidator) {
EXPECT_TRUE(StatusPrinter::IsValidProgressStatus("[%f/%t] "));
{
std::string error_output;
EXPECT_FALSE(
StatusPrinter::IsValidProgressStatus("[%f/%X] ", &error_output));
EXPECT_EQ("unknown placeholder '%X' in $NINJA_STATUS", error_output);
}

EXPECT_EQ("", status_.FormatProgressStatus("[%f/%X] ", 0));
}

TEST_F(BuildTest, FailedDepsParse) {
ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
"build bad_deps.o: cat in1\n"
Expand Down
67 changes: 67 additions & 0 deletions src/status_printer_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2024 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "status_printer.h"

#include "build.h"
#include "test.h"

struct StatusPrinterTest : public testing::Test {
StatusPrinterTest() : config_(MakeConfig()), status_(config_) {
}

virtual void SetUp() {
status_.BuildStarted();
}

static BuildConfig MakeConfig() {
BuildConfig config;
config.verbosity = BuildConfig::QUIET;
return config;
}

BuildConfig config_;
StatusPrinter status_;
};

TEST_F(StatusPrinterTest, StatusFormatElapsed_e) {
// Before any task is done, the elapsed time must be zero.
EXPECT_EQ("[%/e0.000]", status_.FormatProgressStatus("[%%/e%e]", 0));
}

TEST_F(StatusPrinterTest, StatusFormatElapsed_w) {
// Before any task is done, the elapsed time must be zero.
EXPECT_EQ("[%/e00:00]", status_.FormatProgressStatus("[%%/e%w]", 0));
}

TEST_F(StatusPrinterTest, StatusFormatETA) {
// Before any task is done, the ETA time must be unknown.
EXPECT_EQ("[%/E?]", status_.FormatProgressStatus("[%%/E%E]", 0));
}

TEST_F(StatusPrinterTest, StatusFormatTimeProgress) {
// Before any task is done, the percentage of elapsed time must be zero.
EXPECT_EQ("[%/p 0%]", status_.FormatProgressStatus("[%%/p%p]", 0));
}

TEST_F(StatusPrinterTest, StatusFormatReplacePlaceholder) {
EXPECT_EQ("[%/s0/t0/r0/u0/f0]",
status_.FormatProgressStatus("[%%/s%s/t%t/r%r/u%u/f%f]", 0));
}

TEST_F(StatusPrinterTest, StatusFormatValidator) {
EXPECT_TRUE(status_.IsValidProgressStatus("[%f/%t] "));
EXPECT_FALSE(status_.IsValidProgressStatus("[%f/%X] "));
EXPECT_EQ("", status_.FormatProgressStatus("[%f/%X] ", 0));
}

0 comments on commit e75fabb

Please sign in to comment.