blob: f046f1cf70c13085a5c5bb14c3249f47e7cb9287 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// Copyright (c) 2026 Progmasoft.
// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0
#pragma once
#include <cstddef>
#include <filesystem>
#include <string>
#include <string_view>
namespace Progmasoft::Catch3 {
/// Updates are deliberately explicit so normal test runs never rewrite
/// files.
enum class SnapshotUpdateMode : unsigned char {
kNever,
kCreateMissing,
kAlways,
};
enum class SnapshotStatus : unsigned char {
kMatched,
kCreated,
kUpdated,
kMismatched,
kInvalidName,
kInvalidOptions,
kIoError,
};
struct SnapshotOptions final {
std::filesystem::path Directory;
SnapshotUpdateMode UpdateMode = SnapshotUpdateMode::kNever;
bool NormalizeLineEndings = true;
};
/// Structured comparison result; DifferenceLine/Column are one-based.
struct SnapshotResult final {
SnapshotStatus Status = SnapshotStatus::kInvalidOptions;
std::filesystem::path File;
std::string Expected;
std::string Actual;
std::string Message;
std::size_t DifferenceLine = 0;
std::size_t DifferenceColumn = 0;
[[nodiscard]] bool Succeeded() const noexcept;
};
/// Compare against `<Directory>/<name>.snap`; names cannot contain paths.
[[nodiscard]] SnapshotResult
CompareSnapshot( std::string_view name,
std::string_view actual,
const SnapshotOptions& options );
} // namespace Progmasoft::Catch3
|