From c80bcfd599d889af35d59510f49fb1c9abcae24f Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 7 Apr 2023 07:35:36 -0400 Subject: [PATCH] test runtime.env moustaches --- src/hooks/useErrorHandler.ts | 2 +- src/hooks/usePantry.ts | 2 +- tests/integration.suite.ts | 2 +- tests/integration/package.yml.test.ts | 33 +++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 tests/integration/package.yml.test.ts diff --git a/src/hooks/useErrorHandler.ts b/src/hooks/useErrorHandler.ts index 8163e989..768a4d62 100644 --- a/src/hooks/useErrorHandler.ts +++ b/src/hooks/useErrorHandler.ts @@ -77,7 +77,7 @@ function msg(err: TeaError): string { // this yaml is being worked on by the user msg = `${ctx.filename.prettyLocalString()}: ${ctx.cause?.message ?? 'unknown cause'}` } else { - const attachment = `${ctx.project}: ${ctx.cause.message}` + const attachment = `${ctx.project}: ${ctx.cause?.message ?? 'unknown cause'}` msg = undent` pantry entry invalid. please report this bug! diff --git a/src/hooks/usePantry.ts b/src/hooks/usePantry.ts index 9219058f..f69aa1d5 100644 --- a/src/hooks/usePantry.ts +++ b/src/hooks/usePantry.ts @@ -187,7 +187,7 @@ function expand_env_obj(env_: PlainObject, pkg: Package, deps: Installation[]): const home = Path.home().string const obj = [ { from: 'env.HOME', to: home }, // historic, should be removed at v1 - { from: 'home', to: home } + { from: 'home', to: home } // remove, stick with just ~ ] obj.push(...mm.tokenize.all(pkg, deps)) return mm.apply(value, obj) diff --git a/tests/integration.suite.ts b/tests/integration.suite.ts index 0b590e5b..7f6ee675 100644 --- a/tests/integration.suite.ts +++ b/tests/integration.suite.ts @@ -70,7 +70,7 @@ const suite = describe({ if (value) env[key] = value } env['PATH'] = `${bin}:/usr/bin:/bin` // these systems are full of junk so we prune PATH - env['TEA_PREFIX'] = TEA_PREFIX.string + env['TEA_PREFIX'] ??= TEA_PREFIX.string env['CLICOLOR_FORCE'] = '1' let stdout: "piped" | undefined diff --git a/tests/integration/package.yml.test.ts b/tests/integration/package.yml.test.ts new file mode 100644 index 00000000..ebb96b6c --- /dev/null +++ b/tests/integration/package.yml.test.ts @@ -0,0 +1,33 @@ +import suite from "../integration.suite.ts" +import { it } from "deno/testing/bdd.ts" +import { assertEquals } from "deno/testing/asserts.ts" +import { undent } from "utils" +import Path from "path" + +it(suite, "runtime.env tildes", async function() { + const run = async (FOO: string) => { + this.sandbox.join("projects/tea.xyz/foo").mkpath().join("package.yml").write({ text: undent` + provides: [bin/foo] + runtime: + env: + FOO: "${FOO}" + `, force: true}) + + this.sandbox.join("tea.xyz/foo/v1.0.0/bin").mkpath().join("foo").write({ text: undent` + #!/bin/sh + echo "$FOO" + `, force: true}).chmod(0o755) + + const out = await this.run({ + args: ["foo"], + env: { + TEA_PANTRY_PATH: this.sandbox.string, + TEA_PREFIX: this.sandbox.string + } + }).stdout() + + assertEquals(out.trim(), FOO.replaceAll("{{home}}", Path.home().string)) + } + + await run("{{home}}/foo") +})