@@ -3,6 +3,22 @@ const child_process = require("child_process");
33
44const 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+
622test ( '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+ } ) ) ;
0 commit comments