Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
TestLogger.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* TestLogger.cc (C) 2000-2022 */
9/* */
10/* Classe utilitaire pour enregistrer les informations de tests. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/TestLogger.h"
15
16#include "arcane/utils/String.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/FatalErrorException.h"
20
21#include <sstream>
22#include <iostream>
23#include <string>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
32{
33 public:
34
35 std::ostringstream m_stream;
36};
37
38namespace
39{
40 TestLoggerImpl& _impl()
41 {
42 static thread_local TestLoggerImpl logger;
43 return logger;
44 }
45} // namespace
46
47/*---------------------------------------------------------------------------*/
48/*---------------------------------------------------------------------------*/
49
50std::ostream&
51TestLogger::stream()
52{
53 return _impl().m_stream;
54}
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
59void TestLogger::
60dump(std::ostream& o)
61{
62 std::string str = _impl().m_stream.str();
63 o << str;
64}
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68
69int TestLogger::
70compare()
71{
72 String result_file = platform::getEnvironmentVariable("ARCANE_TEST_RESULT_FILE");
73 if (result_file.null())
74 return 0;
75
76 UniqueArray<std::byte> bytes;
77 if (platform::readAllFile(result_file, false, bytes))
78 ARCANE_FATAL("Can not read test result file '{0}'", result_file);
79
80 std::string expected_str(reinterpret_cast<const char*>(bytes.data()), bytes.length());
81 std::string str = _impl().m_stream.str();
82
83 if (expected_str != str) {
84 std::cout << "TestLogger: ERROR during test comparison:\n";
85 std::cout << "Current:\n";
86 std::cout << "\n'''" << str << "'''\n";
87 std::cout << "\nExpected:\n";
88 std::cout << "\n'''" << expected_str << "'''\n";
89 return 1;
90 }
91
92 return 0;
93}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
98} // namespace Arcane
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
bool readAllFile(StringView filename, bool is_binary, ByteArray &out_bytes)
Lit le contenu d'un fichier et le conserve dans out_bytes.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-