Skip to content
  • Igor Sugak's avatar
    rocksdb: switch to gtest · b4b69e4f
    Igor Sugak authored
    Summary:
    Our existing test notation is very similar to what is used in gtest. It makes it easy to adopt what is different.
    In this diff I modify existing [[ https://code.google.com/p/googletest/wiki/Primer#Test_Fixtures:_Using_the_Same_Data_Configuration_for_Multiple_Te | test fixture ]] classes to inherit from `testing::Test`. Also for unit tests that use fixture class, `TEST` is replaced with `TEST_F` as required in gtest.
    
    There are several custom `main` functions in our existing tests. To make this transition easier, I modify all `main` functions to fallow gtest notation. But eventually we can remove them and use implementation of `main` that gtest provides.
    
    ```lang=bash
    % cat ~/transform
    #!/bin/sh
    files=$(git ls-files '*test\.cc')
    for file in $files
    do
      if grep -q "rocksdb::test::RunAllTests()" $file
      then
        if grep -Eq '^class \w+Test {' $file
        then
          perl -pi -e 's/^(class \w+Test) {/${1}: public testing::Test {/g' $file
          perl -pi -e 's/^(TEST)/${1}_F/g' $file
        fi
        perl -pi -e 's/(int main.*\{)/${1}::testing::InitGoogleTest(&argc, argv);/g' $file
        perl -pi -e 's/rocksdb::test::RunAllTests/RUN_ALL_TESTS/g' $file
      fi
    done
    % sh ~/transform
    % make format
    ```
    
    Second iteration of this diff contains only scripted changes.
    
    Third iteration contains manual changes to fix last errors and make it compilable.
    
    Test Plan:
    Build and notice no errors.
    ```lang=bash
    % USE_CLANG=1 make check -j55
    ```
    Tests are still testing.
    
    Reviewers: meyering, sdong, rven, igor
    
    Reviewed By: igor
    
    Subscribers: dhruba, leveldb
    
    Differential Revision: https://reviews.facebook.net/D35157
    b4b69e4f