Skip to content

Commit

Permalink
test runtime.env moustaches
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Apr 13, 2023
1 parent 906007f commit c80bcfd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePantry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/package.yml.test.ts
Original file line number Diff line number Diff line change
@@ -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")
})

0 comments on commit c80bcfd

Please sign in to comment.