mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
big cpp test reorg (#24801)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/24801 This is to fix the ODR-violations in fbcode static builds, which have been broken for several months. This PR is unfortunately quite large, but the changes are only mechanical: 1. Tests defined in header files -> tests defined in cpp files 2. Remove the `torch::jit::testing` namespace -> `torch::jit`. 3. Single `test.h` file that aggregates all tests. 4. Separate out files for gtest and python versions of the tests instead of using a build flag 5. Add a readme for how to add a new test, and explaining a bit about why the cpp tests are the way they are. Test Plan: Imported from OSS Differential Revision: D16878605 Pulled By: suo fbshipit-source-id: 27b5c077dadd990a5f74e25d01731f9c1f491603
This commit is contained in:
committed by
Facebook Github Bot
parent
85564c1456
commit
dfdb86a595
@@ -0,0 +1,64 @@
|
||||
#include "test/cpp/jit/test_base.h"
|
||||
#include "test/cpp/jit/test_utils.h"
|
||||
|
||||
#include "torch/csrc/jit/code_template.h"
|
||||
|
||||
namespace torch {
|
||||
namespace jit {
|
||||
|
||||
static const auto ct = CodeTemplate(R"(
|
||||
int foo($args) {
|
||||
|
||||
$bar
|
||||
$bar
|
||||
$a+$b
|
||||
}
|
||||
int commatest(int a${,stuff})
|
||||
int notest(int a${,empty,})
|
||||
)");
|
||||
static const auto ct_expect = R"(
|
||||
int foo(hi, 8) {
|
||||
|
||||
what
|
||||
on many
|
||||
lines...
|
||||
7
|
||||
what
|
||||
on many
|
||||
lines...
|
||||
7
|
||||
3+4
|
||||
}
|
||||
int commatest(int a, things..., others)
|
||||
int notest(int a)
|
||||
)";
|
||||
|
||||
void testCodeTemplate() {
|
||||
{
|
||||
TemplateEnv e;
|
||||
e.s("hi", "foo");
|
||||
e.v("what", {"is", "this"});
|
||||
TemplateEnv c(e);
|
||||
c.s("hi", "foo2");
|
||||
ASSERT_EQ(e.s("hi"), "foo");
|
||||
ASSERT_EQ(c.s("hi"), "foo2");
|
||||
ASSERT_EQ(e.v("what")[0], "is");
|
||||
}
|
||||
|
||||
{
|
||||
TemplateEnv e;
|
||||
e.v("args", {"hi", "8"});
|
||||
e.v("bar", {"what\non many\nlines...", "7"});
|
||||
e.s("a", "3");
|
||||
e.s("b", "4");
|
||||
e.v("stuff", {"things...", "others"});
|
||||
e.v("empty", {});
|
||||
auto s = ct.format(e);
|
||||
// std::cout << "'" << s << "'\n";
|
||||
// std::cout << "'" << ct_expect << "'\n";
|
||||
ASSERT_EQ(s, ct_expect);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace jit
|
||||
} // namespace torch
|
||||
Reference in New Issue
Block a user