Skip to content

Commit e8fe3c3

Browse files
committed
Create directory name based on test name.
1 parent 786edf0 commit e8fe3c3

File tree

1 file changed

+23
-36
lines changed

1 file changed

+23
-36
lines changed

verible/verilog/analysis/dependencies_test.cc

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "verible/verilog/analysis/dependencies.h"
1616

17+
#include <filesystem>
1718
#include <ostream>
1819
#include <string>
1920
#include <string_view>
@@ -32,14 +33,24 @@ namespace {
3233

3334
using testing::ElementsAre;
3435
using verible::file::Basename;
35-
using verible::file::CreateDir;
36-
using verible::file::JoinPath;
3736
using verible::file::testing::ScopedTestFile;
3837

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) {
4354
VerilogProject project(sources_dir, {/* no include paths */});
4455

4556
// no files
@@ -60,11 +71,7 @@ TEST(FileDependenciesTest, EmptyData) {
6071
}
6172
}
6273

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) {
6875
// None of these test cases will yield any inter-file deps.
6976
constexpr std::string_view kTestCases[] = {
7077
"",
@@ -104,11 +111,7 @@ TEST(FileDependenciesTest, OneFileNoDeps) {
104111
}
105112
}
106113

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) {
112115
VerilogProject project(sources_dir, {/* no include paths */});
113116

114117
ScopedTestFile tf1(sources_dir, "localparam int foo = 0;");
@@ -141,11 +144,7 @@ static std::ostream &operator<<(std::ostream &stream,
141144
return p.symbol_table.PrintSymbolReferences(stream) << std::endl;
142145
}
143146

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) {
149148
VerilogProject project(sources_dir, {/* no include paths */});
150149

151150
ScopedTestFile tf1(sources_dir, "localparam int zzz = 0;\n");
@@ -178,11 +177,7 @@ TEST(FileDependenciesTest, TwoFilesWithParamDepAtRootScope) {
178177
EXPECT_THAT(found_def->second, ElementsAre("zzz"));
179178
}
180179

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) {
186181
VerilogProject project(sources_dir, {/* no include paths */});
187182

188183
ScopedTestFile tf1(sources_dir,
@@ -219,11 +214,7 @@ TEST(FileDependenciesTest, TwoFilesWithParamDep) {
219214
EXPECT_THAT(found_def->second, ElementsAre("foo", "p_pkg"));
220215
}
221216

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) {
227218
VerilogProject project(sources_dir, {/* no include paths */});
228219

229220
ScopedTestFile tf1(sources_dir,
@@ -270,11 +261,7 @@ TEST(FileDependenciesTest, TwoFilesWithCyclicDep) {
270261
}
271262
}
272263

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) {
278265
VerilogProject project(sources_dir, {/* no include paths */});
279266

280267
// 4 files: with a diamond dependency relationship

0 commit comments

Comments
 (0)