Skip to content

Commit 09cc506

Browse files
committed
test/lua-cli.test.js: Add some tests for -e and -E
1 parent cbee658 commit 09cc506

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

test/lua-cli.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ const child_process = require("child_process");
33

44
const lua_path = require.resolve("../src/lua-cli.js");
55

6+
test('Ignores env var when using -E', () => new Promise((resolve) => {
7+
const child = child_process.fork(lua_path, ["-E"], {
8+
env: { LUA_INIT: 'print("failed")' },
9+
silent: true
10+
});
11+
let output = ''
12+
child.stdout.on('data', (data) => {
13+
output += data;
14+
});
15+
child.on('close', (code) => {
16+
expect(code).toBe(0);
17+
expect(output).toBe('');
18+
resolve();
19+
});
20+
}));
21+
622
test('Has correct -v output', () => new Promise((resolve) => {
723
const child = child_process.fork(lua_path, ["-E", "-v"], {
824
silent: true
@@ -17,3 +33,34 @@ test('Has correct -v output', () => new Promise((resolve) => {
1733
resolve();
1834
});
1935
}));
36+
37+
test('Runs empty script', () => new Promise((resolve) => {
38+
const child = child_process.fork(lua_path, ["-E", "-e", ""], {
39+
silent: true
40+
});
41+
let output = ''
42+
child.stdout.on('data', (data) => {
43+
output += data;
44+
});
45+
child.on('close', (code) => {
46+
expect(code).toBe(0);
47+
expect(output).toBe('');
48+
resolve();
49+
});
50+
}));
51+
52+
test('Runs LUA_INIT when -E is not present', () => new Promise((resolve) => {
53+
const child = child_process.fork(lua_path, ["-e", ""], {
54+
env: { LUA_INIT: 'print("success")' },
55+
silent: true
56+
});
57+
let output = ''
58+
child.stdout.on('data', (data) => {
59+
output += data;
60+
});
61+
child.on('close', (code) => {
62+
expect(code).toBe(0);
63+
expect(output).toBe('success\n');
64+
resolve();
65+
});
66+
}));

test/luac-cli.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const child_process = require("child_process");
33

44
const luac_path = require.resolve("../src/luac-cli.js");
55

6+
67
test('Has correct -v output', () => new Promise((resolve) => {
78
const child = child_process.fork(luac_path, ["-v"], {
89
silent: true

0 commit comments

Comments
 (0)