mirror of
https://github.com/dtolnay/rust-toolchain.git
synced 2025-06-08 03:36:37 +00:00
Allow to override toolchain from rust-toolchain file (#35)
This commit is contained in:
parent
e2aeba25b2
commit
6a1db6369e
10 changed files with 168 additions and 34 deletions
|
@ -1,22 +1,57 @@
|
|||
import * as args from '../src/args'
|
||||
|
||||
const testEnvVars = {
|
||||
INPUT_TOOLCHAIN: 'nightly-2019-04-20',
|
||||
INPUT_DEFAULT: 'false',
|
||||
INPUT_OVERRIDE: 'true'
|
||||
}
|
||||
import {toolchain_args} from "../src/args";
|
||||
import {morph} from "mock-env"
|
||||
import {sync as tempWriteSync} from "temp-write"
|
||||
|
||||
describe('actions-rs/toolchain', () => {
|
||||
beforeEach(() => {
|
||||
for (const key in testEnvVars)
|
||||
process.env[key] = testEnvVars[key as keyof typeof testEnvVars]
|
||||
})
|
||||
|
||||
it('Parses action input into toolchain options', async () => {
|
||||
const result = args.toolchain_args();
|
||||
let args = morph(() => {
|
||||
return toolchain_args("./rust-toolchain");
|
||||
}, {
|
||||
'INPUT_TOOLCHAIN': 'nightly-2019-04-20',
|
||||
'INPUT_DEFAULT': 'false',
|
||||
'INPUT_OVERRIDE': 'true'
|
||||
});
|
||||
|
||||
expect(result.name).toBe('nightly-2019-04-20');
|
||||
expect(result.default).toBe(false);
|
||||
expect(result.override).toBe(true);
|
||||
expect(args.name).toBe('nightly-2019-04-20');
|
||||
expect(args.default).toBe(false);
|
||||
expect(args.override).toBe(true);
|
||||
});
|
||||
|
||||
it('uses input variable if rust-toolchain file does not exist', function () {
|
||||
let args = morph(() => {
|
||||
return toolchain_args("./rust-toolchain");
|
||||
}, {
|
||||
'INPUT_TOOLCHAIN': 'nightly',
|
||||
});
|
||||
|
||||
expect(args.name).toBe("nightly")
|
||||
});
|
||||
|
||||
it('toolchain input is required if rust-toolchain does not exist', function () {
|
||||
expect(() => toolchain_args("./rust-toolchain")).toThrowError()
|
||||
});
|
||||
|
||||
it('prioritizes rust-toolchain file over input variable', function () {
|
||||
let rustToolchainFile = tempWriteSync("1.39.0");
|
||||
|
||||
let args = morph(() => {
|
||||
return toolchain_args(rustToolchainFile);
|
||||
}, {
|
||||
'INPUT_TOOLCHAIN': 'nightly',
|
||||
});
|
||||
|
||||
expect(args.name).toBe("1.39.0")
|
||||
});
|
||||
|
||||
it('trims content of the override file', function () {
|
||||
let rustToolchainFile = tempWriteSync("\n 1.39.0\n\n\n\n");
|
||||
|
||||
let args = morph(() => {
|
||||
return toolchain_args(rustToolchainFile);
|
||||
}, {
|
||||
'INPUT_TOOLCHAIN': 'nightly',
|
||||
});
|
||||
|
||||
expect(args.name).toBe("1.39.0")
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue