-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
82 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.