mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
test(ar): share regular archive fixture construction (#16138)
This commit is contained in:
1 parent
56f9215346
commit
c4ec9e4828
1 file changed
+18
-30
@@ -14,6 +14,9 @@ import type {
|
||||
import { arMember } from "./ar.fixture.js";
|
||||
import { ArArtifactReader } from "./ArArtifactReader.js";
|
||||
|
||||
const arFile = (...members: Buffer[]): Buffer =>
|
||||
Buffer.concat([AR_MAGIC, ...members]);
|
||||
|
||||
const inspect = async (bytes: Buffer, limits?: ArReaderLimits) => {
|
||||
const path = await createTestTempFile("rea-ar-", "archive.bin", bytes);
|
||||
const reader = new ArArtifactReader(path, undefined, limits);
|
||||
@@ -56,14 +59,13 @@ const inspect = async (bytes: Buffer, limits?: ArReaderLimits) => {
|
||||
|
||||
it("reads GNU and BSD long names and aligns stored member ranges", async () => {
|
||||
const result = await inspect(
|
||||
Buffer.concat([
|
||||
AR_MAGIC,
|
||||
arFile(
|
||||
arMember("/", "index"),
|
||||
arMember("//", "very-long-gnu-name.o/\n"),
|
||||
arMember("/0", "one"),
|
||||
arMember("#1/20", "very-long-bsd-name.otwo"),
|
||||
arMember("last.o/", "three"),
|
||||
]),
|
||||
),
|
||||
);
|
||||
expect([...result.contents]).toEqual([
|
||||
["very-long-gnu-name.o", "one"],
|
||||
@@ -92,8 +94,7 @@ it("reads Microsoft COFF long names from a NUL-terminated name table", async ()
|
||||
// lib.exe writes two "/" linker members, then a "//" longnames member
|
||||
// whose entries are NUL-terminated (PE/COFF specification, section 7).
|
||||
const result = await inspect(
|
||||
Buffer.concat([
|
||||
AR_MAGIC,
|
||||
arFile(
|
||||
arMember("/", "first-linker"),
|
||||
arMember("/", "second-linker"),
|
||||
arMember(
|
||||
@@ -103,7 +104,7 @@ it("reads Microsoft COFF long names from a NUL-terminated name table", async ()
|
||||
arMember("/0", "one"),
|
||||
arMember("/33", "two"),
|
||||
arMember("aclui.dll/", "three"),
|
||||
]),
|
||||
),
|
||||
);
|
||||
expect([...result.contents]).toEqual([
|
||||
["api-ms-win-core-synch-l1-2-0.dll", "one"],
|
||||
@@ -118,8 +119,7 @@ it("lists absolute member names under their last component", async () => {
|
||||
// lib.exe records the absolute object path it was given; `llvm-ar t`
|
||||
// lists the recorded name and `llvm-ar x` writes its last component.
|
||||
const result = await inspect(
|
||||
Buffer.concat([
|
||||
AR_MAGIC,
|
||||
arFile(
|
||||
arMember("/", "first-linker"),
|
||||
arMember("/", "second-linker"),
|
||||
arMember(
|
||||
@@ -130,7 +130,7 @@ it("lists absolute member names under their last component", async () => {
|
||||
arMember("/28", "two"),
|
||||
arMember("/47", "unsafe"),
|
||||
arMember("/59", "three"),
|
||||
]),
|
||||
),
|
||||
);
|
||||
expect([...result.contents]).toEqual([
|
||||
["decode.obj", "one"],
|
||||
@@ -160,11 +160,7 @@ it("lists absolute member names under their last component", async () => {
|
||||
|
||||
it("preserves earlier entries when a later member is truncated", async () => {
|
||||
const result = await inspect(
|
||||
Buffer.concat([
|
||||
AR_MAGIC,
|
||||
arMember("first.o/", "ok"),
|
||||
arMember("truncated.o/", "x", 30),
|
||||
]),
|
||||
arFile(arMember("first.o/", "ok"), arMember("truncated.o/", "x", 30)),
|
||||
);
|
||||
expect([...result.contents]).toEqual([["first.o", "ok"]]);
|
||||
expect(result.coverage).toMatchObject([
|
||||
@@ -205,7 +201,7 @@ it("preserves Debian package recognition ahead of generic ar", async () => {
|
||||
const path = await createTestTempFile(
|
||||
"rea-ar-",
|
||||
"package.bin",
|
||||
Buffer.concat([AR_MAGIC, arMember("debian-binary", "2.0\n")]),
|
||||
arFile(arMember("debian-binary", "2.0\n")),
|
||||
);
|
||||
expect(await parseBinaryTarget(path)).toMatchObject({
|
||||
ok: true,
|
||||
@@ -215,15 +211,14 @@ it("preserves Debian package recognition ahead of generic ar", async () => {
|
||||
|
||||
it("preserves filename spaces and treats interior NULs as unreadable", async () => {
|
||||
const result = await inspect(
|
||||
Buffer.concat([
|
||||
AR_MAGIC,
|
||||
arFile(
|
||||
arMember(" leading.o/", "a"),
|
||||
arMember("space.o /", "b"),
|
||||
arMember("//", " long-name.o /\n"),
|
||||
arMember("/0", "c"),
|
||||
arMember("#1/10", "bsd.o \0\0\0\0d"),
|
||||
arMember("#1/3", "a\0be"),
|
||||
]),
|
||||
),
|
||||
);
|
||||
expect([...result.contents]).toEqual([
|
||||
[" leading.o", "a"],
|
||||
@@ -235,9 +230,7 @@ it("preserves filename spaces and treats interior NULs as unreadable", async ()
|
||||
});
|
||||
|
||||
it("does not classify a leading-space debian-binary as Debian", async () => {
|
||||
const result = await inspect(
|
||||
Buffer.concat([AR_MAGIC, arMember(" debian-binary/", "2.0\n")]),
|
||||
);
|
||||
const result = await inspect(arFile(arMember(" debian-binary/", "2.0\n")));
|
||||
expect(await parseBinaryTarget(result.path)).toMatchObject({
|
||||
ok: true,
|
||||
value: { format: "ar" },
|
||||
@@ -249,7 +242,7 @@ it.each(["", "garbage"])(
|
||||
async (mode) => {
|
||||
const bytes = arMember("file.o/", "data");
|
||||
bytes.write(mode.padEnd(8), 40, "ascii");
|
||||
const result = await inspect(Buffer.concat([AR_MAGIC, bytes]));
|
||||
const result = await inspect(arFile(bytes));
|
||||
expect(result.entries[0]).toMatchObject({
|
||||
executable: null,
|
||||
formatMetadata: { mode: null },
|
||||
@@ -375,11 +368,7 @@ it.each([false, true])(
|
||||
|
||||
it("reports the complete GNU name length so one suggested increase recovers", async () => {
|
||||
const name = "long-name".repeat(20);
|
||||
const archive = Buffer.concat([
|
||||
AR_MAGIC,
|
||||
arMember("//", `${name}/\n`),
|
||||
arMember("/0", "data"),
|
||||
]);
|
||||
const archive = arFile(arMember("//", `${name}/\n`), arMember("/0", "data"));
|
||||
const refused = await inspect(archive, {
|
||||
...DEFAULT_AR_READER_LIMITS,
|
||||
name_bytes: 8,
|
||||
@@ -397,15 +386,14 @@ it("reports the complete GNU name length so one suggested increase recovers", as
|
||||
|
||||
it("retains malformed-name coverage and replaces cached table facts with each new table", async () => {
|
||||
const result = await inspect(
|
||||
Buffer.concat([
|
||||
AR_MAGIC,
|
||||
arFile(
|
||||
arMember("//", "unterminated"),
|
||||
...Array.from({ length: 512 }, () => arMember("/0", "")),
|
||||
arMember("//", "first-name.o/\n"),
|
||||
arMember("/0", "one"),
|
||||
arMember("//", "other-name.o/\n"),
|
||||
arMember("/0", "two"),
|
||||
]),
|
||||
),
|
||||
);
|
||||
expect([...result.contents]).toEqual([
|
||||
["first-name.o", "one"],
|
||||
|
||||
Reference in new issue
Block a user