aboutsummaryrefslogtreecommitdiff
path: root/backend/unittests/Support/ErrorTest.cpp
blob: de75aa38e10c8ddb6f40f63e1db1ca2e898b3e8d (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
// SPDX-License-Identifier: GPL-3.0-or-later

#include "rcc/Support/Error.h"

#include <iostream>
#include <string>

namespace {

int fail(const char *Message) {
  std::cerr << Message << '\n';
  return 1;
}

} // namespace

int main() {
  rcc::Expected<int> Value = 42;
  if (!Value || *Value != 42)
    return fail("Expected must preserve a successful value");

  rcc::Expected<int> Failure = rcc::makeUnexpected(rcc::ErrorCode::ParseError, "bad MIR");
  if (Failure)
    return fail("Expected must preserve an error");
  if (Failure.error().code() != rcc::ErrorCode::ParseError)
    return fail("Error must preserve its code");
  if (Failure.error().message() != "bad MIR")
    return fail("Error must preserve its message");
  if (rcc::getErrorCodeName(Failure.error().code()) != "parse error")
    return fail("Error code must have a stable name");
  if (rcc::getErrorCodeName(rcc::ErrorCode::FrameLayoutFailed) != "frame layout failed")
    return fail("frame-layout errors must have a stable name");
  if (rcc::getErrorCodeName(rcc::ErrorCode::SchedulingFailed) != "scheduling failed")
    return fail("scheduling errors must have a stable name");
  if (rcc::getErrorCodeName(rcc::ErrorCode::BranchRelaxationFailed) != "branch relaxation failed")
    return fail("branch-relaxation errors must have a stable name");
  if (rcc::getErrorCodeName(rcc::ErrorCode::PseudoExpansionFailed) != "pseudo expansion failed")
    return fail("pseudo-expansion errors must have a stable name");
  if (rcc::getErrorCodeName(rcc::ErrorCode::FinalEncodabilityFailed) != "final encodability failed")
    return fail("final-encodability errors must have a stable name");
  if (rcc::getErrorCodeName(rcc::ErrorCode::CFGOptimizationFailed) != "CFG optimization failed")
    return fail("CFG-optimization errors must have a stable name");

  return 0;
}