From 96fc1243968c75cc43eb9ee99cf49d937f6c2f6e Mon Sep 17 00:00:00 2001 From: tsukimizake Date: Sat, 12 Oct 2024 23:05:28 +0900 Subject: [PATCH 1/2] show buffers on assertion failure --- tests/assertions.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/assertions.ts b/tests/assertions.ts index 11bf8da..7582ad4 100644 --- a/tests/assertions.ts +++ b/tests/assertions.ts @@ -10,8 +10,8 @@ export const sleep = (msec: number) => new Promise((resolve) => setTimeout(resol */ export async function assertAiderBufferShown(denops: Denops): Promise { const buf = await buffer.getAiderBuffer(denops); - assert(buf !== undefined); - assert(buf.winnr !== undefined); + assert(buf !== undefined, `Aider buffer is not defined.\n${await bufferStateMessage(denops)}`); + assert(buf.winnr !== undefined, `Aider buffer is not shown in any window.\n${await bufferStateMessage(denops)}`); } /** @@ -19,8 +19,11 @@ export async function assertAiderBufferShown(denops: Denops): Promise { */ export async function assertAiderBufferHidden(denops: Denops): Promise { const buf = await buffer.getAiderBuffer(denops); - assert(buf !== undefined); - assert(buf.winnr === undefined); + assert(buf !== undefined, `Aider buffer is not defined.\n${await bufferStateMessage(denops)}`); + assert( + buf.winnr === undefined, + `Aider buffer is shown in a window when it should be hidden.\n${await bufferStateMessage(denops)}`, + ); } /** @@ -28,7 +31,7 @@ export async function assertAiderBufferHidden(denops: Denops): Promise { */ export async function assertAiderBufferAlive(denops: Denops): Promise { const buf = await buffer.getAiderBuffer(denops); - assert(buf !== undefined); + assert(buf !== undefined, `Aider buffer is not alive.\n${await bufferStateMessage(denops)}`); } /** @@ -42,5 +45,17 @@ export async function assertAiderBufferString(denops: Denops, expected: string): assert(buf !== undefined); const lines = ensure(await denops.call("getbufline", buf.bufnr, 1, "$"), is.ArrayOf(is.String)); const actual = lines.join("\n"); - assert(actual === expected, `Buffer content mismatch.\nExpected:\n${expected}\nActual:\n${actual}`); + assert(actual === expected, `Buffer content mismatch.\nExpected:\n${expected}\nActual:\n${actual}\n`); +} + +async function bufferStateMessage(denops: Denops): Promise { + const bufCount = ensure(await denops.call("bufnr", "$"), is.Number); + let message = ""; + for (let i = 1; i <= bufCount; i++) { + const bufnr = ensure(await denops.call("bufnr", i), is.Number); + const bufname = ensure(await denops.call("bufname", bufnr), is.String); + const bufwinnr = ensure(await denops.call("bufwinnr", bufnr), is.Number); + message += `${JSON.stringify({ bufnr, bufname, bufwinnr })}\n`; + } + return message; } From a018bf8cb6744b570c28aca69c348212737ad680 Mon Sep 17 00:00:00 2001 From: tsukimizake Date: Sat, 12 Oct 2024 23:16:06 +0900 Subject: [PATCH 2/2] chore: bufwinnr first --- tests/assertions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/assertions.ts b/tests/assertions.ts index 7582ad4..873df2c 100644 --- a/tests/assertions.ts +++ b/tests/assertions.ts @@ -55,7 +55,7 @@ async function bufferStateMessage(denops: Denops): Promise { const bufnr = ensure(await denops.call("bufnr", i), is.Number); const bufname = ensure(await denops.call("bufname", bufnr), is.String); const bufwinnr = ensure(await denops.call("bufwinnr", bufnr), is.Number); - message += `${JSON.stringify({ bufnr, bufname, bufwinnr })}\n`; + message += `${JSON.stringify({ bufwinnr, bufnr, bufname })}\n`; } return message; }