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
This commit is contained in:
Mike Fleetwood 2019-08-04 11:31:57 +01:00 committed by Curtis Gedak
parent 0a23b631c3
commit 7b92e9343b
1 changed files with 28 additions and 2 deletions

View File

@ -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<FSType>& 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