Skip to content

Commit

Permalink
cxx-tests: upgrade to execa 9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed May 12, 2024
1 parent 724e510 commit 8029cb0
Show file tree
Hide file tree
Showing 29 changed files with 82 additions and 60 deletions.
4 changes: 2 additions & 2 deletions integ/browser-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"@types/webpack": "^5.28.5",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"html-webpack-plugin": "^5.6.0",
"puppeteer": "^22.7.1",
"puppeteer": "^22.8.0",
"ts-loader": "^9.5.1",
"tslib": "^2.6.2",
"type-fest": "^4.18.1",
"type-fest": "^4.18.2",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
Expand Down
3 changes: 2 additions & 1 deletion integ/cxx-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"execa": "^8.0.1"
"execa": "^9.0.2",
"streaming-iterables": "^8.0.1"
}
}
54 changes: 34 additions & 20 deletions integ/cxx-tests/test-fixture/cxxprogram.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
import path from "node:path";
import { fileURLToPath } from "node:url";

import { execa, type ExecaChildProcess, execaSync, type Options as ExecaOptions } from "execa";
import { execa, type Options } from "execa";

const pathOfMakefile = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");

function compile(dir: string) {
const rel = path.relative(pathOfMakefile, dir);
execaSync("make", [`${rel}/a.out`], { cwd: pathOfMakefile, stderr: "inherit" });
}
const pathOfMakefile = path.resolve(import.meta.dirname, "..");

/**
* Compile and invoke the C++ program in test case directory.
* @param importMetaUrl - `import.meta.url` of calling test case.
* @param args - Arguments to the compiled program.
* @param opts - execa options.
* Compile the C++ program in test case directory.
* @param dir - `import.meta.dirname` of calling test case.
* @returns Executable full path.
*/
export function execute(importMetaUrl: string, args: readonly string[] = [],
opts: ExecaOptions = {}): ExecaChildProcess {
const dir = path.dirname(fileURLToPath(importMetaUrl));
compile(dir);
return execa("./a.out", args, {
cwd: dir,
export async function compile(dir: string): Promise<Executable> {
const rel = path.relative(pathOfMakefile, dir);
await execa("make", [`${rel}/a.out`], {
cwd: pathOfMakefile,
stderr: "inherit",
...opts,
env: { NDN_NAME_ALT_URI: "0", ...opts.env },
});
return new Executable(path.join(dir, "a.out"));
}

class Executable {
constructor(public readonly exe: string) {}

/**
* Invoke the executable.
* @param args - Command line arguments.
* @param opts - Execa options.
* @returns Execa subprocess.
*/
public run<Opts extends Options>(args: readonly string[], opts: Opts) {
return execa(this.exe, args, {
...baseOpts,
...opts,
env: { ...baseOpts.env, ...opts?.env },
});
}
}

const baseOpts = {
lines: true,
stderr: "inherit",
env: { NDN_NAME_ALT_URI: "0" },
} as const satisfies Options;
11 changes: 7 additions & 4 deletions integ/cxx-tests/tests/keychain/cert/test.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { Component, ValidityPeriod } from "@ndn/packet";
import { Encoder } from "@ndn/tlv";
import { expect, test } from "vitest";

import { execute } from "../../../test-fixture/cxxprogram";
import * as cxx from "../../../test-fixture/cxxprogram";

test("decode", async () => {
const exe = await cxx.compile(import.meta.dirname);

const [, publicKey] = await generateSigningKey("/A");
const [issuerPrivateKey] = await generateSigningKey("/B");

Expand All @@ -18,9 +20,10 @@ test("decode", async () => {
});
const certName = CertNaming.parseCertName(cert.name);

const { stdout } = await execute(import.meta.url, [], { input: Buffer.from(Encoder.encode(cert.data)) });
const [name, identity, keyId, issuerId, validityNotBefore, validityNotAfter] =
stdout.split("\n");
const { stdout } = await exe.run([], {
input: Buffer.from(Encoder.encode(cert.data)),
});
const [name, identity, keyId, issuerId, validityNotBefore, validityNotAfter] = stdout;
expect(name).toBe(cert.name.toString());
expect(identity).toBe(certName.subjectName.toString());
expect(keyId).toBe(certName.keyId.toString());
Expand Down
8 changes: 5 additions & 3 deletions integ/cxx-tests/tests/keychain/verify/test.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Encoder } from "@ndn/tlv";
import { makeTmpDir } from "@ndn/util/test-fixture/tmp";
import { expect, test } from "vitest";

import { execute } from "../../../test-fixture/cxxprogram";
import * as cxx from "../../../test-fixture/cxxprogram";

type Row<G> = [
desc: string,
Expand All @@ -18,6 +18,8 @@ const TABLE = ([] as Array<Row<any>>).concat(
);

test.each(TABLE)("%s", async (desc, algo, genParam) => {
const exe = await cxx.compile(import.meta.dirname);

void desc;
const [privateKey, publicKey] = await generateSigningKey("/A", algo, genParam);
const cert = await Certificate.selfSign({ privateKey, publicKey });
Expand All @@ -28,9 +30,9 @@ test.each(TABLE)("%s", async (desc, algo, genParam) => {
using tmpDir = makeTmpDir();
const certFile = tmpDir.createFile(Encoder.encode(cert.data));
const packetFile = tmpDir.createFile(Encoder.encode(packet));
const { stdout } = await execute(import.meta.url, [certFile, packetFile]);
const { stdout } = await exe.run([certFile, packetFile], {});

const [certOk, packetOk] = stdout.split("\n");
const [certOk, packetOk] = stdout;
expect(certOk).toBe("1");
expect(packetOk).toBe("1");
});
8 changes: 5 additions & 3 deletions integ/cxx-tests/tests/sync/psync-full/test.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FullSync, makePSyncCompatParam, type SyncUpdate } from "@ndn/psync";
import { Closers, delay } from "@ndn/util";
import { afterEach, expect, test, vi } from "vitest";

import { execute } from "../../../test-fixture/cxxprogram";
import * as cxx from "../../../test-fixture/cxxprogram";

const syncPrefix = new Name("/sync");
const userA = new Name("/userA");
Expand All @@ -15,9 +15,11 @@ const closers = new Closers();
afterEach(closers.close);

test("simple", async () => {
const exe = await cxx.compile(import.meta.dirname);

await using nfd = await new FakeNfd().open();

const p = execute(import.meta.url, [`${nfd.port}`, `${syncPrefix}`, `${userA}`]);
const p = exe.run([`${nfd.port}`, `${syncPrefix}`, `${userA}`], {});
await nfd.waitNFaces(1);

const sync = new FullSync({
Expand Down Expand Up @@ -48,7 +50,7 @@ test("simple", async () => {
p.kill("SIGINT");
const { stdout } = await p;
const hiSeqNums = new Map<string, number>();
for (const line of stdout.split("\n")) {
for (const line of stdout) {
const [user, , hiSeqNum] = line.split("\t") as [string, string, string];
hiSeqNums.set(user, Number.parseInt(hiSeqNum, 10));
}
Expand Down
2 changes: 1 addition & 1 deletion mk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"js-yaml": "^4.1.0",
"readlink": "^3.0.0",
"split2": "^4.2.0",
"type-fest": "^4.18.1"
"type-fest": "^4.18.2"
},
"dependencies": {
"compare-versions": "6.1.0"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"test": "vitest",
"typedoc": "bash mk/typedoc.sh"
},
"packageManager": "pnpm@9.1.0-0+sha256.c557b24d2298d9b5e3be7086ebf55a28253b008324d545f72645a6de89844102",
"packageManager": "pnpm@9.1.0+sha256.22e36fba7f4880ecf749a5ca128b8435da085ecd49575e7fb9e64d6bf4fad394",
"devDependencies": {
"@types/node": "^20.12.8",
"@types/node": "^20.12.11",
"@types/wtfnode": "^0.7.3",
"@typescript/lib-dom": "npm:@types/web@0.0.143",
"@typescript/lib-dom": "npm:@types/web@0.0.144",
"@vitest/coverage-v8": "^1.6.0",
"@yoursunny/xo-config": "0.58.0",
"codedown": "^3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion pkg/autoconfig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"@types/default-gateway": "^7.2.2",
"@types/koa": "^2.15.0",
"koa": "^2.15.3",
"type-fest": "^4.18.1"
"type-fest": "^4.18.2"
}
}
2 changes: 1 addition & 1 deletion pkg/cli-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@ndn/packet": "workspace:*",
"@ndn/util": "workspace:*",
"dotenv": "^16.4.5",
"env-var": "^7.4.1",
"env-var": "^7.4.2",
"tslib": "^2.6.2",
"wtfnode": "^0.9.2"
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dpdkmgmt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@ndn/node-transport": "workspace:*",
"@ndn/packet": "workspace:*",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"graphql-request": "^7.0.0",
"tslib": "^2.6.2"
},
"optionalDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/keychain-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@ndn/repo": "workspace:*",
"@ndn/tlv": "workspace:*",
"@ndn/util": "workspace:*",
"env-var": "^7.4.1",
"env-var": "^7.4.2",
"fast-chunk-string": "^1.0.1",
"get-stdin": "^9.0.0",
"nodemailer": "^6.9.13",
Expand Down
2 changes: 1 addition & 1 deletion pkg/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"idb-keyval": "^6.2.1",
"mnemonist": "^0.39.8",
"tslib": "^2.6.2",
"type-fest": "^4.18.1",
"type-fest": "^4.18.2",
"wait-your-turn": "^1.0.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/l3face/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"retry": "^0.13.1",
"streaming-iterables": "^8.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.18.1",
"type-fest": "^4.18.2",
"typescript-event-target": "^1.1.1"
}
}
2 changes: 1 addition & 1 deletion pkg/nac/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@yoursunny/asn1": "0.0.20200718",
"mnemonist": "^0.39.8",
"tslib": "^2.6.2",
"type-fest": "^4.18.1"
"type-fest": "^4.18.2"
},
"devDependencies": {
"@ndn/l3face": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion pkg/ndncert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"nodemailer": "^6.9.13",
"p-timeout": "^6.1.2",
"tslib": "^2.6.2",
"type-fest": "^4.18.1",
"type-fest": "^4.18.2",
"typescript-event-target": "^1.1.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ndnsec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@ndn/tlv": "workspace:*",
"@ndn/util": "workspace:*",
"@yoursunny/asn1": "0.0.20200718",
"execa": "^8.0.1",
"execa": "^9.0.2",
"tslib": "^2.6.2"
}
}
2 changes: 1 addition & 1 deletion pkg/nfdmgmt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"@ndn/l3face": "workspace:*",
"@ndn/node-transport": "workspace:*",
"type-fest": "^4.18.1",
"type-fest": "^4.18.2",
"typescript-event-target": "^1.1.1"
}
}
2 changes: 1 addition & 1 deletion pkg/node-transport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"event-iterator": "^2.0.0",
"p-event": "^6.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.18.1",
"type-fest": "^4.18.2",
"url-format-lax": "^2.0.0",
"url-parse-lax": "^5.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/packet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"buffer-compare": "^1.1.1",
"mnemonist": "^0.39.8",
"tslib": "^2.6.2",
"type-fest": "^4.18.1"
"type-fest": "^4.18.2"
},
"devDependencies": {
"@types/buffer-compare": "^0.0.33"
Expand Down
4 changes: 2 additions & 2 deletions pkg/pyrepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"p-defer": "^4.0.1",
"streaming-iterables": "^8.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.18.1",
"type-fest": "^4.18.2",
"typescript-event-target": "^1.1.1"
},
"devDependencies": {
Expand All @@ -46,7 +46,7 @@
"@ndn/ndnsec": "workspace:^",
"@ndn/nfdmgmt": "workspace:^",
"@types/netmask": "^2.0.5",
"execa": "^8.0.1",
"execa": "^9.0.2",
"netmask": "^2.0.2"
}
}
4 changes: 2 additions & 2 deletions pkg/pyrepo/test-fixture/pyrepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NdnsecKeyChain } from "@ndn/ndnsec";
import { FakeNfd } from "@ndn/nfdmgmt/test-fixture/prefix-reg";
import { Name, type NameLike } from "@ndn/packet";
import { assert, Closers } from "@ndn/util";
import { execa, type ExecaChildProcess, execaSync } from "execa";
import { execa, execaSync, type ResultPromise } from "execa";
import { long2ip } from "netmask";

let pyrepoInstalled: boolean | undefined;
Expand Down Expand Up @@ -62,7 +62,7 @@ export class PyRepo implements AsyncDisposable {
}

private constructor(
private readonly p: ExecaChildProcess,
private readonly p: ResultPromise,
private readonly nfd: FakeNfd,
) {}

Expand Down
2 changes: 1 addition & 1 deletion pkg/repo-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
"devDependencies": {
"@ndn/node-transport": "workspace:*",
"stream-mock": "^2.0.5",
"type-fest": "^4.18.1"
"type-fest": "^4.18.2"
}
}
2 changes: 1 addition & 1 deletion pkg/repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"memory-level": "^1.0.0",
"streaming-iterables": "^8.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.18.1",
"type-fest": "^4.18.2",
"typescript-event-target": "^1.1.1",
"wait-your-turn": "^1.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/segmented-object/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"@ndn/l3face": "workspace:*",
"@ndn/repo-api": "workspace:*",
"stream-mock": "^2.0.5",
"type-fest": "^4.18.1"
"type-fest": "^4.18.2"
}
}
2 changes: 1 addition & 1 deletion pkg/svs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@ndn/util": "workspace:*",
"streaming-iterables": "^8.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.18.1",
"type-fest": "^4.18.2",
"typescript-event-target": "^1.1.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/tlv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"@ndn/util": "workspace:*",
"mnemonist": "^0.39.8",
"tslib": "^2.6.2",
"type-fest": "^4.18.1"
"type-fest": "^4.18.2"
}
}
2 changes: 1 addition & 1 deletion pkg/trust-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"mnemonist": "^0.39.8",
"obliterator": "^2.0.4",
"tslib": "^2.6.2",
"type-fest": "^4.18.1"
"type-fest": "^4.18.2"
},
"devDependencies": {
"@ndn/l3face": "workspace:^",
Expand Down
Loading

0 comments on commit 8029cb0

Please sign in to comment.