Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 30270b1

Browse files
committed
Fix Windows path-based test failures
1 parent d166cd8 commit 30270b1

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
*/
77

8+
import java.io.File;
89
import java.io.IOException;
910
import java.io.InputStream;
1011
import java.io.OutputStream;
@@ -36,7 +37,10 @@ public MatlabCommandRunner(MatlabActionParameters params) throws IOException, In
3637
this.additionalEnvVars = new HashMap<String,String>();
3738

3839
// Create MATLAB folder
39-
FilePath matlabFolder = new FilePath(params.getLauncher().getChannel(), params.getWorkspace().getRemote() + "/.matlab");
40+
FilePath matlabFolder = new FilePath(
41+
params.getLauncher().getChannel(), params.getWorkspace().getRemote()
42+
+ File.separator
43+
+ ".matlab");
4044
matlabFolder.mkdirs();
4145

4246
// Create temp folder

src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void verifyMATLABlaunchedfromWorkspace() throws Exception {
149149
project.getBuildersList().add(this.scriptBuilder);
150150
FreeStyleBuild build = project.scheduleBuild2(0).get();
151151
String workspace = build.getWorkspace().getName();
152-
jenkins.assertLogContains(File.separator + workspace + File.separator, build);
152+
jenkins.assertLogContains("[" + workspace + "]", build);
153153
}
154154

155155
/*

src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void verifyMATLABlaunchedfromWorkspace() throws Exception {
156156
project.getBuildersList().add(this.scriptBuilder);
157157
FreeStyleBuild build = project.scheduleBuild2(0).get();
158158
String workspace = build.getWorkspace().getName();
159-
jenkins.assertLogContains(File.separator + workspace + File.separator, build);
159+
jenkins.assertLogContains(File.separator + workspace, build);
160160
}
161161

162162
/*

src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTest.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ public void constructorUsesParamsForTempFolder() throws IOException, Interrupted
9595
public void correctTempFolderLocation() throws IOException, InterruptedException {
9696
runner = new MatlabCommandRunner(params);
9797
FilePath tmp = runner.getTempFolder();
98+
FilePath expected = new FilePath(new File(tempDir.getRoot(), ".matlab"));
9899

99100
Assert.assertThat(
100101
tmp.getRemote(),
101-
startsWith(new File(tempDir.getRoot(), ".matlab").getAbsolutePath()));
102+
startsWith(expected.getRemote()));
102103
}
103104

104105
@Test
@@ -123,7 +124,8 @@ public Object answer(InvocationOnMock invocation) throws IOException {
123124
Assert.assertTrue(f.exists());
124125
Assert.assertEquals(
125126
runner.getTempFolder().getRemote()
126-
+ "/run-matlab-command",
127+
+ File.separator
128+
+ "run-matlab-command",
127129
f.getRemote());
128130
}
129131

@@ -138,7 +140,8 @@ public void prepareRunnerExecutableMac() throws IOException, InterruptedExceptio
138140
Assert.assertTrue(f.exists());
139141
Assert.assertEquals(
140142
runner.getTempFolder().getRemote()
141-
+ "/run-matlab-command",
143+
+ File.separator
144+
+ "run-matlab-command",
142145
f.getRemote());
143146
}
144147

@@ -151,7 +154,8 @@ public void prepareRunnerExecutableWindows() throws IOException, InterruptedExce
151154
Assert.assertTrue(f.exists());
152155
Assert.assertEquals(
153156
runner.getTempFolder().getRemote()
154-
+ "/run-matlab-command.exe",
157+
+ File.separator
158+
+ "run-matlab-command.exe",
155159
f.getRemote());
156160
}
157161

@@ -178,7 +182,7 @@ public void copyFileFromResourcePathWorks() throws IOException, InterruptedExcep
178182
FilePath f = runner.copyFileToTempFolder("testcontent.txt", "target.txt");
179183

180184
Assert.assertTrue(f.exists());
181-
Assert.assertEquals("This has text!\n", f.readToString());
185+
Assert.assertThat(f.readToString(), startsWith("This has text!"));
182186
}
183187

184188
@Test
@@ -189,7 +193,8 @@ public void runWorksInBasicCase() throws IOException, InterruptedException, Matl
189193
runner.runMatlabCommand(myCommand);
190194

191195
String exe = runner.getTempFolder().getRemote()
192-
+ "/run-matlab-command.exe";
196+
+ File.separator
197+
+ "run-matlab-command.exe";
193198
String cmd = "setenv('MW_ORIG_WORKING_FOLDER', cd('"
194199
+ runner.getTempFolder().getRemote()
195200
+ "'));script_";

0 commit comments

Comments
 (0)