Files
pytorch/caffe2/core/common_test.cc
Nikita Shulga a9b0a921d5 Disable avoid-non-const-global-variables lint check (#62008)
Summary:
As GoogleTest `TEST` macro is non-compliant with it as well as `DEFINE_DISPATCH`

All changes but the ones to `.clang-tidy` are generated using following script:
```
for i in `find . -type f -iname "*.c*" -or -iname "*.h"|xargs grep cppcoreguidelines-avoid-non-const-global-variables|cut -f1 -d:|sort|uniq`;  do sed -i "/\/\/ NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)/d" $i; done
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/62008

Reviewed By: driazati, r-barnes

Differential Revision: D29838584

Pulled By: malfet

fbshipit-source-id: 1b2f8602c945bd4ce50a9bfdd204755556e31d13
2021-07-22 18:04:40 -07:00

44 lines
1.1 KiB
C++

#include <iostream>
#include <memory>
#define CAFFE2_TESTONLY_FORCE_STD_STRING_TEST
#include "caffe2/core/common.h"
#include <gtest/gtest.h>
namespace caffe2 {
#ifndef __ANDROID__
// Simple tests to make sure that our stoi and stod implementations are
// matching the std implementations, but not testing it very extensively
// as one should be using the std version most of the time.
TEST(CommonTest, TestStoi) {
EXPECT_TRUE(CAFFE2_TESTONLY_WE_ARE_USING_CUSTOM_STRING_FUNCTIONS);
string s = "1234";
int i_std = std::stoi(s);
int i_caffe2 = ::c10::stoi(s);
EXPECT_EQ(i_std, i_caffe2);
}
TEST(CommonTest, TestStod) {
// Full string is parsed.
string s = "1.234";
std::size_t p_std = 0, p_caffe2 = 0;
double d_std = std::stod(s, &p_std);
double d_caffe2 = ::c10::stod(s, &p_caffe2);
EXPECT_EQ(d_std, d_caffe2);
EXPECT_EQ(p_std, p_caffe2);
// Only part of the string is parsed.
s = "1.234 5.678";
d_std = std::stod(s, &p_std);
d_caffe2 = ::c10::stod(s, &p_caffe2);
EXPECT_EQ(d_std, d_caffe2);
EXPECT_EQ(p_std, p_caffe2);
}
#endif // __ANDROID__
} // namespace caffe2