https://mooseframework.inl.gov
MooseUnitUtils.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "MooseUnitUtils.h"
11 
12 #include <random>
13 
14 namespace Moose::UnitUtils
15 {
16 TempFile::TempFile() : _path(generatePath()) {}
17 
19 {
20  std::error_code ec;
21  std::filesystem::remove(path(), ec);
22 }
23 
24 std::filesystem::path
26 {
27  static const std::string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
28  static thread_local std::mt19937 generator{std::random_device{}()};
29  std::uniform_int_distribution<std::size_t> distribution(0, chars.size() - 1);
30  std::string result;
31  const std::size_t len = 10;
32  result.reserve(len);
33  for (std::size_t i = 0; i < len; ++i)
34  result += chars[distribution(generator)];
35  return std::filesystem::temp_directory_path() / std::filesystem::path("mooseunit." + result);
36 }
37 
38 }
const std::filesystem::path & path() const
static std::filesystem::path generatePath()