mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary:
This is an automatic change generated by the following script:
```
#!/usr/bin/env python3
from subprocess import check_output, check_call
import os
def get_compiled_files_list():
import json
with open("build/compile_commands.json") as f:
data = json.load(f)
files = [os.path.relpath(node['file']) for node in data]
for idx, fname in enumerate(files):
if fname.startswith('build/') and fname.endswith('.DEFAULT.cpp'):
files[idx] = fname[len('build/'):-len('.DEFAULT.cpp')]
return files
def run_clang_tidy(fname):
check_call(["python3", "tools/clang_tidy.py", "-c", "build", "-x", fname,"-s"])
changes = check_output(["git", "ls-files", "-m"])
if len(changes) == 0:
return
check_call(["git", "commit","--all", "-m", f"NOLINT stubs for {fname}"])
def main():
git_files = check_output(["git", "ls-files"]).decode("ascii").split("\n")
compiled_files = get_compiled_files_list()
for idx, fname in enumerate(git_files):
if fname not in compiled_files:
continue
if fname.startswith("caffe2/contrib/aten/"):
continue
print(f"[{idx}/{len(git_files)}] Processing {fname}")
run_clang_tidy(fname)
if __name__ == "__main__":
main()
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56892
Reviewed By: H-Huang
Differential Revision: D27991944
Pulled By: malfet
fbshipit-source-id: 5415e1eb2c1b34319a4f03024bfaa087007d7179
65 lines
1.3 KiB
C++
65 lines
1.3 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include "test/cpp/jit/test_utils.h"
|
|
#include "torch/csrc/jit/frontend/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)
|
|
)";
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
TEST(TestCodeTemplate, Copying) {
|
|
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");
|
|
}
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
TEST(TestCodeTemplate, Formatting) {
|
|
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
|