From e75fabbe7fe6756d43160ee60be9fba7aa442427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Harald=20J=C3=B8rgensen?= <58829763+adamjoer@users.noreply.github.com> Date: Tue, 10 Sep 2024 21:50:22 +0200 Subject: [PATCH] Move StatusPrinter tests to their own file --- CMakeLists.txt | 1 + src/build_test.cc | 41 ----------------------- src/status_printer_test.cc | 67 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 41 deletions(-) create mode 100644 src/status_printer_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 47b1f9c117..33544bf9ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/build_test.cc b/src/build_test.cc index f4d8a4f999..69568955cc 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -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" diff --git a/src/status_printer_test.cc b/src/status_printer_test.cc new file mode 100644 index 0000000000..a26c6540cb --- /dev/null +++ b/src/status_printer_test.cc @@ -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)); +}