import type { ExpectationResult } from "../../expect/types";

import { mismatchFailure } from "../../expect/failure";

export function checkExitCode(exitCode: number, allowed: number[]): ExpectationResult {
  if (!allowed.includes(exitCode)) {
    return {
      failure: mismatchFailure(
        "exitCode",
        "exitCode",
        allowed,
        exitCode,
        `exitCode ${exitCode} not in [${allowed.join(", ")}]`,
      ),
      matched: false,
    };
  }
  return { failure: null, matched: true };
}
