|
1 | 1 | /// <reference path="./types.d.ts" />
|
2 | 2 |
|
3 |
| -import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; |
| 3 | +import { |
| 4 | + assert, |
| 5 | + assertEquals, |
| 6 | + assertThrowsAsync, |
| 7 | +} from "https://deno.land/[email protected]/testing/asserts.ts"; |
4 | 8 |
|
5 |
| -import { $ } from "./mod.ts"; |
| 9 | +import { $, cd, path, ProcessError } from "./mod.ts"; |
6 | 10 |
|
7 | 11 | Deno.test("$ works", async () => {
|
8 | 12 | const result = await $`echo hello`;
|
9 | 13 |
|
10 | 14 | assertEquals(result.stdout, "hello\n");
|
11 | 15 | });
|
| 16 | + |
| 17 | +Deno.test("passing environment variables to the child process", async () => { |
| 18 | + Deno.env.set("IS_THIS_THING_ON", "yes"); |
| 19 | + const result = await $`echo $IS_THIS_THING_ON`; |
| 20 | + |
| 21 | + assertEquals(result.stdout, "yes\n"); |
| 22 | +}); |
| 23 | + |
| 24 | +Deno.test("escape and quote arguments", async () => { |
| 25 | + const complexArg = 'bar"";baz!$#^$\'&*~*%)({}||\\/'; |
| 26 | + const result = (await $`echo ${complexArg}`); |
| 27 | + |
| 28 | + assertEquals(result.stdout.trim(), complexArg); |
| 29 | +}); |
| 30 | + |
| 31 | +Deno.test("create a directory with a space in the name", async () => { |
| 32 | + const now = Date.now(); |
| 33 | + const path = `./.tmp/test_${now}/foo bar`; |
| 34 | + |
| 35 | + try { |
| 36 | + await $`mkdir -p ${path}`; |
| 37 | + assert((await Deno.stat(path)).isDirectory); |
| 38 | + } finally { |
| 39 | + await Deno.remove(`./.tmp`, { recursive: true }); |
| 40 | + } |
| 41 | +}); |
| 42 | + |
| 43 | +Deno.test("subprocess command failure throws a ProcessError", async () => { |
| 44 | + await assertThrowsAsync(async () => await $`somefakebinary`, ProcessError); |
| 45 | +}); |
| 46 | + |
| 47 | +Deno.test("cwd of the parent process is always the starting point for calls to cd", async () => { |
| 48 | + const parentPwd = Deno.cwd(); |
| 49 | + |
| 50 | + try { |
| 51 | + const testStartingDir = path.dirname(path.fromFileUrl(import.meta.url)); |
| 52 | + Deno.chdir(testStartingDir); |
| 53 | + |
| 54 | + cd("src"); |
| 55 | + const pwd1 = await $`pwd`; |
| 56 | + assertEquals(pwd1.stdout.trim(), path.join(testStartingDir, "src")); |
| 57 | + |
| 58 | + cd(".github"); |
| 59 | + const pwd2 = await $`pwd`; |
| 60 | + assertEquals(pwd2.stdout.trim(), path.join(testStartingDir, ".github")); |
| 61 | + } finally { |
| 62 | + Deno.chdir(parentPwd); |
| 63 | + } |
| 64 | +}); |
0 commit comments