Skip to content

Commit

Permalink
Advance with coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
placintaalexandru committed Oct 28, 2023
1 parent 46f8461 commit 06b1a58
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions tests/output.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Outputs } from "../src/output";
import * as mockedExecUtils from "../src/utils/exec";

jest.mock("@actions/core", () => ({
info: jest.fn(),
debug: jest.fn(),
}));
describe("Outputs tests", () => {
afterEach(() => {
jest.clearAllMocks();
});

test("Rustc version", async () => {
for (const stdout of [
"rustc 1.75.0-nightly (aa1a71e9e 2023-10-26)",
"rustc 1.75.0 (aa1a71e9e 2023-10-26)",
]) {
jest.spyOn(mockedExecUtils, "execStdout").mockReturnValue(
Promise.resolve(stdout),
);
const output = await Outputs.rustc();
expect(output.value).toBe(stdout.split(" ")[1]);
}
});

test("Rustc hash", async () => {
for (const stdout of [
"rustc 1.75.0-nightly (aa1a71e9e 2023-10-26)",
"rustc 1.75.0 (aa1a71e9e 2023-10-26)",
]) {
jest.spyOn(mockedExecUtils, "execStdout").mockReturnValue(
Promise.resolve(stdout),
);
const output = await Outputs.rustcHash();
expect(output.value).toBe(
stdout.split(" ")[2].split(" ")[0].substring(1),
);
}
});

test("Cargo version", async () => {
for (const stdout of [
"cargo 1.75.0-nightly (df3509237 2023-10-24)",
"cargo 1.75.0 (df3509237 2023-10-24)",
]) {
jest.spyOn(mockedExecUtils, "execStdout").mockReturnValue(
Promise.resolve(stdout),
);
const output = await Outputs.cargo();
expect(output.value).toBe(stdout.split(" ")[1]);
}
});

test("Rustup version", async () => {
for (const stdout of [
"rustup 1.26.0 (5af9b9484 2023-04-05)\n" +
"info: This is the version for the rustup toolchain manager, not the rustc compiler.\n" +
"info: The currently active `rustc` version is `rustc 1.75.0-nightly (aa1a71e9e 2023-10-26)`",
]) {
jest.spyOn(mockedExecUtils, "execStdout").mockReturnValue(
Promise.resolve(stdout),
);
const output = await Outputs.rustUp();
expect(output.value).toBe(stdout.split(" ")[1]);
}
});

test("All", async () => {
jest.spyOn(Outputs, "rustc").mockReturnValue(
Promise.resolve({
name: "rustc",
value: "rustc",
}),
);
jest.spyOn(Outputs, "rustcHash").mockReturnValue(
Promise.resolve({
name: "rustc_hash",
value: "rustcHash",
}),
);
jest.spyOn(Outputs, "cargo").mockReturnValue(
Promise.resolve({
name: "cargo",
value: "cargo",
}),
);
jest.spyOn(Outputs, "rustUp").mockReturnValue(
Promise.resolve({
name: "rustup",
value: "rustup",
}),
);

expect(
(await new Outputs().outputs())
.map((output) => {
return output.value;
})
.toString(),
).toBe(["rustc", "rustcHash", "cargo", "rustup"].toString());
});
});

0 comments on commit 06b1a58

Please sign in to comment.