Skip to content

Commit

Permalink
Merge pull request #11 from vim-denops/env-verbose
Browse files Browse the repository at this point in the history
👍 Add `DENOPS_TEST_VERBOSE` environment variable
  • Loading branch information
lambdalisue committed Jan 6, 2024
2 parents da5e8b0 + 119e742 commit 37f91fb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ used in the unit tests of denops plugins.
> - `DENOPS_TEST_VIM_EXECUTABLE`: Path to the Vim executable (default: "vim")
> - `DENOPS_TEST_NVIM_EXECUTABLE`: Path to the Neovim executable (default:
> "nvim")
> - `DENOPS_TEST_VERBOSE`: `1` or `true` to print Vim messages (echomsg)
If you want to test denops plugins with a real Vim and/or Neovim process, use
the `test` function to define a test case, as shown below:
Expand Down
9 changes: 9 additions & 0 deletions conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export interface Config {
* It refers to the environment variable 'DENOPS_TEST_NVIM_EXECUTABLE'.
*/
nvimExecutable: string;

/**
* Print Vim messages (echomsg).
* It refers to the environment variable 'DENOPS_TEST_VERBOSE'.
*/
verbose: boolean;
}

/**
Expand All @@ -36,6 +42,7 @@ export interface Config {
* - `DENOPS_TEST_DENOPS_PATH`: Local path to the denops.vim repository (required)
* - `DENOPS_TEST_VIM_EXECUTABLE`: Path to the Vim executable (default: "vim")
* - `DENOPS_TEST_NVIM_EXECUTABLE`: Path to the Neovim executable (default: "nvim")
* - `DENOPS_TEST_VERBOSE`: `1` or `true` to print Vim messages (echomsg)
*
* It throws an error if the environment variable 'DENOPS_TEST_DENOPS_PATH' is
* not set.
Expand All @@ -50,10 +57,12 @@ export function getConfig(): Config {
"Environment variable 'DENOPS_TEST_DENOPS_PATH' is required",
);
}
const verbose = Deno.env.get("DENOPS_TEST_VERBOSE");
conf = {
denopsPath: resolve(denopsPath),
vimExecutable: Deno.env.get("DENOPS_TEST_VIM_EXECUTABLE") ?? "vim",
nvimExecutable: Deno.env.get("DENOPS_TEST_NVIM_EXECUTABLE") ?? "nvim",
verbose: verbose === "1" || verbose === "true",
};
return conf;
}
1 change: 1 addition & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* > - `DENOPS_TEST_VIM_EXECUTABLE`: Path to the Vim executable (default: "vim")
* > - `DENOPS_TEST_NVIM_EXECUTABLE`: Path to the Neovim executable (default:
* > "nvim")
* > - `DENOPS_TEST_VERBOSE`: `1` or `true` to print Vim messages (echomsg)
*
* If you want to test denops plugins with a real Vim and/or Neovim process, use
* the `test` function to define a test case, as shown below:
Expand Down
15 changes: 8 additions & 7 deletions runner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { is } from "https://deno.land/x/[email protected]/mod.ts";
import { unreachable } from "https://deno.land/x/[email protected]/mod.ts";
import { getConfig } from "./conf.ts";
import { Config, getConfig } from "./conf.ts";

/**
* Represents the mode in which the runner operates.
Expand Down Expand Up @@ -35,23 +35,24 @@ export function run(
cmds: string[],
options: RunOptions = {},
): Deno.ChildProcess {
const [cmd, args] = buildArgs(mode);
const conf = getConfig();
const verbose = options.verbose ?? conf.verbose;
const [cmd, args] = buildArgs(conf, mode);
args.unshift(...cmds.flatMap((c) => ["-c", c]));
if (options.verbose) {
if (verbose) {
args.unshift("--cmd", "redir >> /dev/stdout");
}
const command = new Deno.Command(cmd, {
args,
env: options.env,
stdin: "piped",
stdout: options.verbose ? "inherit" : "null",
stderr: options.verbose ? "inherit" : "null",
stdout: verbose ? "inherit" : "null",
stderr: verbose ? "inherit" : "null",
});
return command.spawn();
}

function buildArgs(mode: RunMode): [string, string[]] {
const conf = getConfig();
function buildArgs(conf: Config, mode: RunMode): [string, string[]] {
switch (mode) {
case "vim":
return [
Expand Down

0 comments on commit 37f91fb

Please sign in to comment.