pytorch/test/cpp/jit/test_inliner.cpp
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

52 lines
1.0 KiB
C++

#include <gtest/gtest.h>
#include <torch/csrc/jit/api/compilation_unit.h>
#include <torch/csrc/jit/api/module.h>
#include <torch/csrc/jit/passes/inliner.h>
#include <torch/csrc/jit/testing/file_check.h>
const auto testSource = R"JIT(
def foo1(x):
print("one")
return x
def foo2(x):
print("two")
return foo1(x)
def foo3(x):
print("three")
return foo2(x)
)JIT";
namespace torch {
namespace jit {
using namespace testing;
struct InlinerGuard {
explicit InlinerGuard(bool shouldInline)
: oldState_(getInlineEverythingMode()) {
getInlineEverythingMode() = shouldInline;
}
~InlinerGuard() {
getInlineEverythingMode() = oldState_;
}
bool oldState_;
};
TEST(InlinerTest, Basic) {
// disable automatic inlining so we can test it manually
InlinerGuard guard(/*shouldInline=*/false);
CompilationUnit cu(testSource);
auto& fn = cu.get_function("foo3");
auto g = fn.graph();
Inline(*g);
FileCheck().check_count("prim::Print", 3)->run(*g);
}
} // namespace jit
} // namespace torch