ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
RootCoreUtils
Root
UnitTestDir.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
//
8
// includes
9
//
10
11
#include <
RootCoreUtils/UnitTestDir.h
>
12
13
#include <cstdlib>
14
#include <filesystem>
15
#include <stdexcept>
16
#include <vector>
17
#include <
RootCoreUtils/Assert.h
>
18
#include <
RootCoreUtils/MessageCheck.h
>
19
20
//
21
// method implementations
22
//
23
24
namespace
RCU
25
{
26
UnitTestDir ::
27
UnitTestDir (
const
std::string& package,
const
std::string& name)
28
:
m_cleanup
(getenv (
"ROOTCORE_AUTO_UT"
) != nullptr)
29
{
30
std::string tmpdir =
"/tmp"
;
31
if
(
const
char
*env = getenv (
"TMPDIR"
))
32
tmpdir = env;
33
34
// use mkdtemp to create a unique, collision-proof directory
35
const
std::string templ = tmpdir +
"/ut-"
+
package
+ "-" + name + "-XXXXXX";
36
std::vector<char> buffer (templ.begin(), templ.end());
37
buffer.push_back (
'\0'
);
38
if
(mkdtemp (buffer.data()) ==
nullptr
)
39
throw
std::runtime_error (
"could not create output directory from template "
+ templ);
40
m_path
= buffer.data();
41
}
42
43
44
45
UnitTestDir ::
46
~UnitTestDir ()
47
{
48
using namespace
msgRootCoreUtils;
49
50
if
(
m_cleanup
)
51
{
52
std::error_code ec;
53
std::filesystem::remove_all (
m_path
, ec);
54
}
55
else
56
ANA_MSG_INFO
(
"unit test data located at "
<<
m_path
);
57
}
58
59
60
61
const
std::string& UnitTestDir ::
62
path ()
const
63
{
64
return
m_path
;
65
}
66
67
68
69
bool
UnitTestDir ::
70
cleanup ()
const
71
{
72
return
m_cleanup
;
73
}
74
75
76
77
void
UnitTestDir ::
78
cleanup (
bool
val_cleanup)
79
{
80
m_cleanup
= val_cleanup;
81
}
82
}
Assert.h
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
MessageCheck.h
UnitTestDir.h
RCU::UnitTestDir::m_cleanup
bool m_cleanup
Definition
UnitTestDir.h:67
RCU::UnitTestDir::m_path
std::string m_path
description: members directly corresponding to accessors
Definition
UnitTestDir.h:65
RCU
This module defines a variety of assert style macros.
Definition
Assert.cxx:23
Generated on
for ATLAS Offline Software by
1.17.0