mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-15 21:00:47 +00: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
79 lines
2.6 KiB
C++
79 lines
2.6 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <ATen/core/qualified_name.h>
|
|
#include <c10/util/Exception.h>
|
|
|
|
using c10::QualifiedName;
|
|
|
|
namespace torch {
|
|
namespace jit {
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
TEST(QualifiedNameTest, PrefixConstruction) {
|
|
// Test prefix construction
|
|
auto foo = QualifiedName("foo");
|
|
auto bar = QualifiedName(foo, "bar");
|
|
auto baz = QualifiedName(bar, "baz");
|
|
ASSERT_EQ(baz.qualifiedName(), "foo.bar.baz");
|
|
ASSERT_EQ(baz.prefix(), "foo.bar");
|
|
ASSERT_EQ(baz.name(), "baz");
|
|
auto nullstate = QualifiedName();
|
|
ASSERT_EQ(nullstate.qualifiedName(), "");
|
|
ASSERT_EQ(nullstate.prefix(), "");
|
|
ASSERT_EQ(nullstate.name(), "");
|
|
}
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
TEST(QualifiedNameTest, DottedConstruction) {
|
|
// Test dotted construction
|
|
auto foo = QualifiedName("foo.bar.baz");
|
|
ASSERT_EQ(foo.qualifiedName(), "foo.bar.baz");
|
|
ASSERT_EQ(foo.prefix(), "foo.bar");
|
|
ASSERT_EQ(foo.name(), "baz");
|
|
|
|
auto bar = QualifiedName("bar");
|
|
ASSERT_EQ(bar.qualifiedName(), "bar");
|
|
ASSERT_EQ(bar.prefix(), "");
|
|
ASSERT_EQ(bar.name(), "bar");
|
|
}
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
TEST(QualifiedNameTest, BadInputRaises) {
|
|
// throw some bad inputs at it
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-goto,hicpp-avoid-goto)
|
|
ASSERT_ANY_THROW(QualifiedName("foo..bar"));
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-goto,hicpp-avoid-goto)
|
|
ASSERT_ANY_THROW(QualifiedName(".foo.bar"));
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-goto,hicpp-avoid-goto)
|
|
ASSERT_ANY_THROW(QualifiedName("foo.bar."));
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-goto,hicpp-avoid-goto)
|
|
ASSERT_ANY_THROW(QualifiedName(""));
|
|
}
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
TEST(QualifiedNameTest, Equality) {
|
|
// test equality api
|
|
auto foo1 = QualifiedName("foo.bar.baz");
|
|
auto foo2 = QualifiedName("foo.bar.baz");
|
|
auto foo3 = QualifiedName("bar.bar.baz");
|
|
ASSERT_EQ(foo1, foo2);
|
|
ASSERT_NE(foo1, foo3);
|
|
auto bar1 = QualifiedName("sup");
|
|
auto bar2 = QualifiedName("sup");
|
|
ASSERT_EQ(foo1, foo2);
|
|
}
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
TEST(QualifiedNameTest, IsPrefixOf) {
|
|
// test prefix api
|
|
auto foo1 = QualifiedName("foo.bar.baz");
|
|
auto foo2 = QualifiedName("foo.bar");
|
|
auto foo3 = QualifiedName("bar.bar.baz");
|
|
auto foo4 = QualifiedName("foo.bar");
|
|
ASSERT_TRUE(foo2.isPrefixOf(foo1));
|
|
ASSERT_TRUE(foo2.isPrefixOf(foo4));
|
|
ASSERT_TRUE(foo4.isPrefixOf(foo2));
|
|
ASSERT_FALSE(foo1.isPrefixOf(foo2));
|
|
ASSERT_FALSE(foo2.isPrefixOf(foo3));
|
|
}
|
|
} // namespace jit
|
|
} // namespace torch
|