14
14
15
15
#include " verible/verilog/analysis/dependencies.h"
16
16
17
+ #include < filesystem>
17
18
#include < ostream>
18
19
#include < string>
19
20
#include < string_view>
@@ -32,14 +33,24 @@ namespace {
32
33
33
34
using testing::ElementsAre;
34
35
using verible::file::Basename;
35
- using verible::file::CreateDir;
36
- using verible::file::JoinPath;
37
36
using verible::file::testing::ScopedTestFile;
38
37
39
- TEST (FileDependenciesTest, EmptyData) {
40
- const auto tempdir = ::testing::TempDir ();
41
- const std::string sources_dir = JoinPath (tempdir, __FUNCTION__);
42
- ASSERT_TRUE (CreateDir (sources_dir).ok ());
38
+ class FileDependenciesTest : public ::testing::Test {
39
+ protected:
40
+ void SetUp () final {
41
+ sources_dir = verible::file::JoinPath (
42
+ ::testing::TempDir (),
43
+ ::testing::UnitTest::GetInstance()->current_test_info()->name());
44
+ const absl::Status status = verible::file::CreateDir (sources_dir);
45
+ ASSERT_TRUE (status.ok ()) << status;
46
+ }
47
+
48
+ void TearDown () final { std::filesystem::remove (sources_dir); }
49
+
50
+ std::string sources_dir;
51
+ };
52
+
53
+ TEST_F (FileDependenciesTest, EmptyData) {
43
54
VerilogProject project (sources_dir, {/* no include paths */ });
44
55
45
56
// no files
@@ -60,11 +71,7 @@ TEST(FileDependenciesTest, EmptyData) {
60
71
}
61
72
}
62
73
63
- TEST (FileDependenciesTest, OneFileNoDeps) {
64
- const auto tempdir = ::testing::TempDir ();
65
- const std::string sources_dir = JoinPath (tempdir, __FUNCTION__);
66
- ASSERT_TRUE (CreateDir (sources_dir).ok ());
67
-
74
+ TEST_F (FileDependenciesTest, OneFileNoDeps) {
68
75
// None of these test cases will yield any inter-file deps.
69
76
constexpr std::string_view kTestCases [] = {
70
77
" " ,
@@ -104,11 +111,7 @@ TEST(FileDependenciesTest, OneFileNoDeps) {
104
111
}
105
112
}
106
113
107
- TEST (FileDependenciesTest, TwoFilesNoDeps) {
108
- const auto tempdir = ::testing::TempDir ();
109
- const std::string sources_dir = JoinPath (tempdir, __FUNCTION__);
110
- ASSERT_TRUE (CreateDir (sources_dir).ok ());
111
-
114
+ TEST_F (FileDependenciesTest, TwoFilesNoDeps) {
112
115
VerilogProject project (sources_dir, {/* no include paths */ });
113
116
114
117
ScopedTestFile tf1 (sources_dir, " localparam int foo = 0;" );
@@ -141,11 +144,7 @@ static std::ostream &operator<<(std::ostream &stream,
141
144
return p.symbol_table .PrintSymbolReferences (stream) << std::endl;
142
145
}
143
146
144
- TEST (FileDependenciesTest, TwoFilesWithParamDepAtRootScope) {
145
- const auto tempdir = ::testing::TempDir ();
146
- const std::string sources_dir = JoinPath (tempdir, __FUNCTION__);
147
- ASSERT_TRUE (CreateDir (sources_dir).ok ());
148
-
147
+ TEST_F (FileDependenciesTest, TwoFilesWithParamDepAtRootScope) {
149
148
VerilogProject project (sources_dir, {/* no include paths */ });
150
149
151
150
ScopedTestFile tf1 (sources_dir, " localparam int zzz = 0;\n " );
@@ -178,11 +177,7 @@ TEST(FileDependenciesTest, TwoFilesWithParamDepAtRootScope) {
178
177
EXPECT_THAT (found_def->second , ElementsAre (" zzz" ));
179
178
}
180
179
181
- TEST (FileDependenciesTest, TwoFilesWithParamDep) {
182
- const auto tempdir = ::testing::TempDir ();
183
- const std::string sources_dir = JoinPath (tempdir, __FUNCTION__);
184
- ASSERT_TRUE (CreateDir (sources_dir).ok ());
185
-
180
+ TEST_F (FileDependenciesTest, TwoFilesWithParamDep) {
186
181
VerilogProject project (sources_dir, {/* no include paths */ });
187
182
188
183
ScopedTestFile tf1 (sources_dir,
@@ -219,11 +214,7 @@ TEST(FileDependenciesTest, TwoFilesWithParamDep) {
219
214
EXPECT_THAT (found_def->second , ElementsAre (" foo" , " p_pkg" ));
220
215
}
221
216
222
- TEST (FileDependenciesTest, TwoFilesWithCyclicDep) {
223
- const auto tempdir = ::testing::TempDir ();
224
- const std::string sources_dir = JoinPath (tempdir, __FUNCTION__);
225
- ASSERT_TRUE (CreateDir (sources_dir).ok ());
226
-
217
+ TEST_F (FileDependenciesTest, TwoFilesWithCyclicDep) {
227
218
VerilogProject project (sources_dir, {/* no include paths */ });
228
219
229
220
ScopedTestFile tf1 (sources_dir,
@@ -270,11 +261,7 @@ TEST(FileDependenciesTest, TwoFilesWithCyclicDep) {
270
261
}
271
262
}
272
263
273
- TEST (FileDependenciesTest, ModuleDiamondDependencies) {
274
- const auto tempdir = ::testing::TempDir ();
275
- const std::string sources_dir = JoinPath (tempdir, __FUNCTION__);
276
- ASSERT_TRUE (CreateDir (sources_dir).ok ());
277
-
264
+ TEST_F (FileDependenciesTest, ModuleDiamondDependencies) {
278
265
VerilogProject project (sources_dir, {/* no include paths */ });
279
266
280
267
// 4 files: with a diamond dependency relationship
0 commit comments