22
33import static org .junit .Assert .*;
44
5+ import java .io .File ;
56import java .nio .charset .Charset ;
67import java .util .List ;
78
@@ -40,42 +41,54 @@ public TestJob(String script, String scriptType, boolean hideEnvironmentVariable
4041 }
4142
4243 final static String UNIX_SCRIPT = "unixScript" ;
43- final static String POWER_SHELL = "powerShell " ;
44+ final static String BATCH_SCRIPT = "batchScript " ;
4445
4546 final static String SCRIPT_SIMPLE_VARIABLES = "echo var1=one\n "
4647 + "echo var2=two\n "
4748 + "echo var3=three" ;
4849
49- final static String SCRIPT_DEPENDENT_VARIABLES = "echo var1=one\n "
50+ final static String SCRIPT_DEPENDENT_VARIABLES_UNIX = "echo var1=one\n "
5051 + "echo var2='$var1 two'\n "
5152 + "echo var3='yo $var4'\n "
5253 + "echo var4='three ${var2}'" ;
5354
54- final static String SCRIPT_OVERRIDDEN_VARIABLES = "echo var1=one\n "
55+ final static String SCRIPT_DEPENDENT_VARIABLES_BATCH = "echo var1=one\n "
56+ + "echo var2=$var1 two\n "
57+ + "echo var3=yo $var4\n "
58+ + "echo var4=three ${var2}" ;
59+
60+ final static String SCRIPT_OVERRIDDEN_VARIABLES_UNIX = "echo var1=one\n "
5561 + "echo var1+something='not one'\n "
5662 + "echo var2+something='two'" ;
5763
64+ final static String SCRIPT_OVERRIDDEN_VARIABLES_BATCH = "echo var1=one\n "
65+ + "echo var1+something=not one\n "
66+ + "echo var2+something=two" ;
67+
5868 final static String SCRIPT_UTF8 = "echo UTFstr=mąż" ;
5969
60- final static String SCRIPT_SHEBANG = "#!/bin/cat\n "
70+ final static String SCRIPT_SHEBANG_UNIX = "#!/bin/cat\n "
6171 + "hello=world" ;
6272
73+ // batch script does not have shebang
74+ final static String SCRIPT_SHEBANG_BATCH = "echo hello=world" ;
75+
6376 public void testWithEmptyScript () throws Exception {
64- String script = UNIX_SCRIPT ;
77+ String scriptType = UNIX_SCRIPT ;
6578 if (Functions .isWindows ()) {
66- script = POWER_SHELL ;
79+ scriptType = BATCH_SCRIPT ;
6780 }
68- TestJob job = new TestJob ("" , script , true );
81+ TestJob job = new TestJob ("" , scriptType , true );
6982 assertEquals (Result .SUCCESS , job .build .getResult ());
7083 }
7184
7285 @ Test
7386 public void testWithSimpleVariables () throws Exception {
74- String script = UNIX_SCRIPT ;
87+ String scriptType = UNIX_SCRIPT ;
7588 if (Functions .isWindows ()) {
76- script = POWER_SHELL ;
89+ scriptType = BATCH_SCRIPT ;
7790 }
78- TestJob job = new TestJob (SCRIPT_SIMPLE_VARIABLES , script , true );
91+ TestJob job = new TestJob (SCRIPT_SIMPLE_VARIABLES , scriptType , true );
7992 assertEquals (Result .SUCCESS , job .build .getResult ());
8093
8194 EnvVars vars = job .build .getEnvironment (job .listener );
@@ -86,11 +99,13 @@ public void testWithSimpleVariables() throws Exception {
8699
87100 @ Test
88101 public void testWithDependentVariables () throws Exception {
89- String script = UNIX_SCRIPT ;
102+ String scriptType = UNIX_SCRIPT ;
103+ String script = SCRIPT_DEPENDENT_VARIABLES_UNIX ;
90104 if (Functions .isWindows ()) {
91- script = POWER_SHELL ;
105+ scriptType = BATCH_SCRIPT ;
106+ script = SCRIPT_DEPENDENT_VARIABLES_BATCH ;
92107 }
93- TestJob job = new TestJob (SCRIPT_DEPENDENT_VARIABLES , script , true );
108+ TestJob job = new TestJob (script , scriptType , true );
94109 assertEquals (Result .SUCCESS , job .build .getResult ());
95110
96111 EnvVars vars = job .build .getEnvironment (job .listener );
@@ -101,61 +116,67 @@ public void testWithDependentVariables() throws Exception {
101116 }
102117
103118 @ Test
104- public void testWithOverridenVariables () throws Exception {
105- String script = UNIX_SCRIPT ;
119+ public void testWithOverriddenVariables () throws Exception {
120+ String scriptType = UNIX_SCRIPT ;
121+ String script = SCRIPT_OVERRIDDEN_VARIABLES_UNIX ;
106122 if (Functions .isWindows ()) {
107- script = POWER_SHELL ;
123+ scriptType = BATCH_SCRIPT ;
124+ script = SCRIPT_OVERRIDDEN_VARIABLES_BATCH ;
108125 }
109- TestJob job = new TestJob (SCRIPT_OVERRIDDEN_VARIABLES , script , true );
126+ TestJob job = new TestJob (script , scriptType , true );
110127 assertEquals (Result .SUCCESS , job .build .getResult ());
111128
112129 EnvVars vars = job .build .getEnvironment (job .listener );
113- assertEquals ("not one: one" , vars .get ("var1" ));
130+ assertEquals ("not one" + File . pathSeparatorChar + " one" , vars .get ("var1" ));
114131 assertEquals ("two" , vars .get ("var2" ));
115132 }
116133
117134 @ Test
118135 public void testReadingFileFromSCM () throws Exception {
119- String script = UNIX_SCRIPT ;
136+ String scriptType = UNIX_SCRIPT ;
137+ String script = "cat envs" ;
120138 if (Functions .isWindows ()) {
121- script = POWER_SHELL ;
139+ scriptType = BATCH_SCRIPT ;
140+ script = "type envs" ;
122141 }
123- TestJob job = new TestJob ("cat envs" , script , true );
142+ TestJob job = new TestJob (script , scriptType , true );
124143 assertEquals (Result .SUCCESS , job .build .getResult ());
125144 assertEquals ("bar" , job .build .getEnvironment (job .listener ).get ("foo_var" ));
126145 }
127146
128147 @ Test
129148 public void testWorkingDirectory () throws Exception {
130- String script = UNIX_SCRIPT ;
149+ String scriptType = UNIX_SCRIPT ;
131150 if (Functions .isWindows ()) {
132- script = POWER_SHELL ;
151+ scriptType = BATCH_SCRIPT ;
133152 }
134- TestJob job = new TestJob ("echo hi >was_run" , script , true );
153+ TestJob job = new TestJob ("echo hi >was_run" , scriptType , true );
135154
136155 // Make sure that the $PWD of the script is $WORKSPACE.
137156 assertTrue (job .build .getWorkspace ().child ("was_run" ).exists ());
138157 }
139158
140159 @ Test
141160 public void testWithShebang () throws Exception {
142- String script = UNIX_SCRIPT ;
161+ String scriptType = UNIX_SCRIPT ;
162+ String script = SCRIPT_SHEBANG_UNIX ;
143163 if (Functions .isWindows ()) {
144- script = POWER_SHELL ;
164+ scriptType = BATCH_SCRIPT ;
165+ script = SCRIPT_SHEBANG_BATCH ;
145166 }
146- TestJob job = new TestJob (SCRIPT_SHEBANG , script , true );
167+ TestJob job = new TestJob (script , scriptType , true );
147168
148169 assertEquals (Result .SUCCESS , job .build .getResult ());
149170 EnvVars vars = job .build .getEnvironment (job .listener );
150171 assertEquals ("world" , vars .get ("hello" ));
151172 }
152173
153174 public void testUTFHandling () throws Exception {
154- String script = UNIX_SCRIPT ;
175+ String scriptType = UNIX_SCRIPT ;
155176 if (Functions .isWindows ()) {
156- script = POWER_SHELL ;
177+ scriptType = BATCH_SCRIPT ;
157178 }
158- TestJob job = new TestJob (SCRIPT_UTF8 , script , true );
179+ TestJob job = new TestJob (SCRIPT_UTF8 , scriptType , true );
159180 assertEquals (Result .SUCCESS , job .build .getResult ());
160181
161182 EnvVars vars = job .build .getEnvironment (job .listener );
@@ -164,11 +185,11 @@ public void testUTFHandling() throws Exception {
164185
165186 @ Test
166187 public void testHideEnvironmentVariablesValues () throws Exception {
167- String script = UNIX_SCRIPT ;
188+ String scriptType = UNIX_SCRIPT ;
168189 if (Functions .isWindows ()) {
169- script = POWER_SHELL ;
190+ scriptType = BATCH_SCRIPT ;
170191 }
171- TestJob job = new TestJob (SCRIPT_SIMPLE_VARIABLES , script , true );
192+ TestJob job = new TestJob (SCRIPT_SIMPLE_VARIABLES , scriptType , true );
172193 assertEquals (Result .SUCCESS , job .build .getResult ());
173194 List <String > logs = job .build .getLog (10 );
174195
@@ -179,11 +200,11 @@ public void testHideEnvironmentVariablesValues() throws Exception {
179200
180201 @ Test
181202 public void testShowEnvironmentVariablesValues () throws Exception {
182- String script = UNIX_SCRIPT ;
203+ String scriptType = UNIX_SCRIPT ;
183204 if (Functions .isWindows ()) {
184- script = POWER_SHELL ;
205+ scriptType = BATCH_SCRIPT ;
185206 }
186- TestJob job = new TestJob (SCRIPT_SIMPLE_VARIABLES , script , false );
207+ TestJob job = new TestJob (SCRIPT_SIMPLE_VARIABLES , scriptType , false );
187208 assertEquals (Result .SUCCESS , job .build .getResult ());
188209 List <String > logs = job .build .getLog (10 );
189210
0 commit comments