Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gtest instructions #76

Open
awf opened this issue Jun 5, 2023 · 1 comment · May be fixed by #123
Open

Add gtest instructions #76

awf opened this issue Jun 5, 2023 · 1 comment · May be fixed by #123

Comments

@awf
Copy link

awf commented Jun 5, 2023

The README has instructions on running pytest...

pip install absl-py pytest
pytest --pyargs ml_dtypes

It would also be useful for contributors to indicate how to correctly run ./ml_dtypes/tests/float8_test.cc

@awf
Copy link
Author

awf commented Jul 17, 2023

In case useful for others, this is a lightly-tested and hacky, but functional solution:

Clone abseil in ml_dtypes/tests

$ cd ml_dtypes/tests
$ git clone https://github.com/abseil/abseil-cpp.git 

Temporarily edit float8_test.cc

  #include <gmock/gmock.h>
  #include <gtest/gtest.h>
- #include "third_party/absl/strings/str_cat.h"
+ #include "absl/strings/str_cat.h"
  #include "unsupported/Eigen/CXX11/Tensor"

Create CMakeLists.txt

cmake_minimum_required(VERSION 3.14)
project(my_project)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(GOOGLETEST_DOWNLOAD_URL https://github.com/google/googletest/archive/refs/tags/v1.12.0.zip)

include(FetchContent)
FetchContent_Declare(
  googletest
  URL ${GOOGLETEST_DOWNLOAD_URL}
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

set(ABSL_PROPAGATE_CXX_STD ON)
set(ABSL_GOOGLETEST_DOWNLOAD_URL ${GOOGLETEST_DOWNLOAD_URL})
add_subdirectory(abseil-cpp)

enable_testing()

add_executable(
  float8_test
  float8_test.cc
)
target_include_directories(float8_test PUBLIC
  ..
  ../../third_party/eigen
)

target_link_libraries(
  float8_test
  GTest::gtest_main
  GTest::gmock_main
  absl::strings
)

include(GoogleTest)
gtest_discover_tests(float8_test)

Build and test

cmake -S . -B build
cmake --build build 
(cd build && ctest)

@awf awf linked a pull request Nov 10, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant