Skip to content

Commit a598559

Browse files
committed
test: add direct unit tests for formatCliOutput
Closes #36 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent 5bc58ce commit a598559

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

test/unit/initializeProject.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MINIMUM_SUPPORTED_PATCHLOOM_VERSION } from "../../src/binary/patchloom.
44
import { classifyAgentsFile } from "../../src/commands/initializeProject.js";
55
import { buildStatusDetails, preferredStatusAction } from "../../src/commands/showStatus.js";
66
import { buildPatchloomMcpEntry, configureMcpTargets, inspectMcpTargets } from "../../src/mcp/config.js";
7-
import { formatError } from "../../src/util.js";
7+
import { formatCliOutput, formatError } from "../../src/util.js";
88

99
test("formatError extracts message from Error instances", () => {
1010
assert.equal(formatError(new Error("disk full")), "disk full");
@@ -22,6 +22,23 @@ test("formatError falls back to String for Error with empty message", () => {
2222
assert.equal(formatError(err), String(err));
2323
});
2424

25+
// --- #36: direct unit tests for formatCliOutput ---
26+
27+
test("formatCliOutput merges stderr and stdout into a single line", () => {
28+
const result = formatCliOutput({ exitCode: 0, stdout: "hello world", stderr: "warn: something" });
29+
assert.equal(result, "warn: something hello world");
30+
});
31+
32+
test("formatCliOutput returns exit code when both streams are empty", () => {
33+
assert.equal(formatCliOutput({ exitCode: 1, stdout: "", stderr: "" }), "exit code 1");
34+
assert.equal(formatCliOutput({ exitCode: 0, stdout: " \n ", stderr: " " }), "exit code 0");
35+
});
36+
37+
test("formatCliOutput normalizes CRLF line endings", () => {
38+
const result = formatCliOutput({ exitCode: 0, stdout: "line1\r\nline2\r\n", stderr: "" });
39+
assert.equal(result, "line1 line2");
40+
});
41+
2542
test("classifyAgentsFile returns missing when AGENTS.md does not exist", () => {
2643
assert.equal(classifyAgentsFile(undefined, "# Rules\n"), "missing");
2744
});

0 commit comments

Comments
 (0)