From 7b92e9343be6e5fb90829ae8edfea615902faf3a Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 4 Aug 2019 11:31:57 +0100 Subject: [PATCH] Print file system types in parameterised test names (!49) Until now the parameterised test values are printed as part of the test names as just 0, 1, etc. like this: $ ./test_SupportedFileSystems Running main() from test_SupportedFileSystems.cc [==========] Running 20 tests from 1 test case. [----------] Global test environment set-up. [----------] 20 tests from My/SupportedFileSystemsTest [ RUN ] My/SupportedFileSystemsTest.Create/0 [ OK ] My/SupportedFileSystemsTest.Create/0 (48 ms) [ RUN ] My/SupportedFileSystemsTest.Create/1 [ OK ] My/SupportedFileSystemsTest.Create/1 (11 ms) Provide the file system types as the names for the parameterised test values [1]. Now the test names are printed like this: $ ./test_SupportedFileSystems Running main() from test_SupportedFileSystems.cc [==========] Running 20 tests from 1 test case. [----------] Global test environment set-up. [----------] 20 tests from My/SupportedFileSystemsTest [ RUN ] My/SupportedFileSystemsTest.Create/ext2 [ OK ] My/SupportedFileSystemsTest.Create/ext2 (51 ms) [ RUN ] My/SupportedFileSystemsTest.Create/linuxswap [ OK ] My/SupportedFileSystemsTest.Create/linuxswap (11 ms) Also use these Google Test name friendly ASCII alphanumeric only names everywhere the file system type needs to be reported in this test program. [1] Specifying Names for Value-Parameterized Test Parameters https://github.com/google/googletest/blob/v1.8.x/googletest/docs/advanced.md#specifying-names-for-value-parameterized-test-parameters Closes !49 - Add file system interface tests --- tests/test_SupportedFileSystems.cc | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/test_SupportedFileSystems.cc b/tests/test_SupportedFileSystems.cc index 70e7b017..728592e6 100644 --- a/tests/test_SupportedFileSystems.cc +++ b/tests/test_SupportedFileSystems.cc @@ -163,6 +163,32 @@ std::ostream& operator<<(std::ostream& out, const OperationDetail& od) } +// Printable file system type which meets the requirements for a Google Test name. +// Use GParted's file system names except when they contains any non-alphabetic chars. +// Reference: +// * Specifying Names for Value-Parameterized Test Parameters +// https://github.com/google/googletest/blob/v1.8.x/googletest/docs/advanced.md#specifying-names-for-value-parameterized-test-parameters +// "NOTE: test names must be non-empty, unique, and may only contain ASCII +// alphanumeric characters. In particular, they should not contain underscores." +const std::string test_fsname(FSType fstype) +{ + switch (fstype) + { + case FS_LINUX_SWAP: return "linuxswap"; + default: break; + } + return std::string(Utils::get_filesystem_string(fstype)); +} + + +// Function callable by INSTANTIATE_TEST_CASE_P() to get the file system type for printing +// as part of the test name. +const std::string param_fsname(const ::testing::TestParamInfo& info) +{ + return test_fsname(info.param); +} + + // Google Test 1.8.1 (and earlier) doesn't implement run-time test skipping so implement // our own for GParted run-time detected of unsupported file system features. // Ref: @@ -228,7 +254,7 @@ void SupportedFileSystemsTest::SetUp() // Lookup file system interface object. m_fs_object = s_supported_filesystems->get_fs_object(m_fstype); ASSERT_TRUE(m_fs_object != NULL) << __func__ << "(): TEST_BUG: Interface object not found for file system " - << Utils::get_filesystem_string(m_fstype); + << test_fsname(m_fstype); } @@ -478,7 +504,7 @@ TEST_P(SupportedFileSystemsTest, CreateAndShrink) // Reference: // * Google Test, Advanced googletest Topics, How to Write Value-Parameterized Tests // https://github.com/google/googletest/blob/v1.8.x/googletest/docs/advanced.md#how-to-write-value-parameterized-tests -INSTANTIATE_TEST_CASE_P(My, SupportedFileSystemsTest, ::testing::Values(FS_EXT2, FS_LINUX_SWAP)); +INSTANTIATE_TEST_CASE_P(My, SupportedFileSystemsTest, ::testing::Values(FS_EXT2, FS_LINUX_SWAP), param_fsname); } // namespace GParted