Skip to content

Commit

Permalink
a go-runnable version
Browse files Browse the repository at this point in the history
Signed-off-by: you06 <[email protected]>
  • Loading branch information
you06 committed Aug 6, 2021
1 parent cdc36e6 commit f5fb453
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const color = new chalk.Instance({level: 1})

export type TestComparison = 'exact' | 'included' | 'regex'

const INHERITED_ENVS: string[] = ['GOPATH', 'GOROOT', 'HOME']

export interface Test {
readonly name: string
readonly setup: string
Expand Down Expand Up @@ -48,6 +50,25 @@ export class TestOutputError extends TestError {
}
}

const getInheritEnv = (): {
[key: string]: string | undefined;
} => {
const env: {
[key: string]: string | undefined;
} = {
PATH: process.env['PATH'],
FORCE_COLOR: 'true',
}

for (const e of INHERITED_ENVS) {
if (process.env[e]) {
env[e] = process.env[e]
}
}

return env
}

const log = (text: string): void => {
process.stdout.write(text + os.EOL)
}
Expand Down Expand Up @@ -94,25 +115,12 @@ const waitForExit = async (child: ChildProcess, timeout: number): Promise<void>
})
}

const INHERITED_ENVS: string[] = ['GOPATH', 'GOROOT']

const runSetup = async (test: Test, cwd: string, timeout: number): Promise<void> => {
if (!test.setup || test.setup === '') {
return
}

const env: {
[key: string]: string | undefined;
} = {
PATH: process.env['PATH'],
FORCE_COLOR: 'true',
}

for (const e of INHERITED_ENVS) {
if (process.env[e]) {
env[e] = process.env[e]
}
}
const env = getInheritEnv();

const setup = spawn(test.setup, {
cwd,
Expand All @@ -137,13 +145,12 @@ const runSetup = async (test: Test, cwd: string, timeout: number): Promise<void>
}

const runCommand = async (test: Test, cwd: string, timeout: number): Promise<void> => {
const env = getInheritEnv();

const child = spawn(test.run, {
cwd,
shell: true,
env: {
PATH: process.env['PATH'],
FORCE_COLOR: 'true',
},
env: env,
})

let output = ''
Expand Down

0 comments on commit f5fb453

Please sign in to comment.