Skip to content

Commit c123411

Browse files
committed
B #146 ClipboardReporter can handle filenames with spaces for linux
1 parent 0dedd1f commit c123411

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[with spaces.txt, with spaces.txt, true] => move /Y "with spaces.txt" "with spaces.txt"
2+
[with spaces.txt, with spaces.txt, false] => mv "with spaces.txt" "with spaces.txt"
3+
[with spaces.txt, withoutSpaces.txt, true] => move /Y "with spaces.txt" "withoutSpaces.txt"
4+
[with spaces.txt, withoutSpaces.txt, false] => mv "with spaces.txt" withoutSpaces.txt
5+
[withoutSpaces.txt, with spaces.txt, true] => move /Y "withoutSpaces.txt" "with spaces.txt"
6+
[withoutSpaces.txt, with spaces.txt, false] => mv withoutSpaces.txt "with spaces.txt"
7+
[withoutSpaces.txt, withoutSpaces.txt, true] => move /Y "withoutSpaces.txt" "withoutSpaces.txt"
8+
[withoutSpaces.txt, withoutSpaces.txt, false] => mv withoutSpaces.txt withoutSpaces.txt
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.approvaltests.reporters;
2+
3+
import org.approvaltests.combinations.CombinationApprovals;
4+
import org.junit.jupiter.api.Test;
5+
6+
class ClipboardReporterTest
7+
{
8+
@Test
9+
void commandLineMoves()
10+
{
11+
String[] files = {"with spaces.txt", "withoutSpaces.txt"};
12+
Boolean[] systems = {true, false};
13+
CombinationApprovals.verifyAllCombinations(ClipboardReporter::getAcceptApprovalText, files, files, systems);
14+
}
15+
}

approvaltests/src/main/java/org/approvaltests/reporters/ClipboardReporter.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,24 @@ public boolean isWorkingInThisEnvironment(String forFile)
3535
}
3636
public static String getAcceptApprovalText(String received, String approved)
3737
{
38-
if (SystemUtils.isWindowsEnviroment())
38+
return getAcceptApprovalText(received, approved, SystemUtils.isWindowsEnviroment());
39+
}
40+
public static String getAcceptApprovalText(String received, String approved, boolean windowsEnviroment)
41+
{
42+
if (windowsEnviroment)
3943
{
4044
return String.format("move /Y \"%s\" \"%s\"", received, approved);
4145
}
4246
else
4347
{
44-
return String.format("mv %s %s", received, approved);
48+
return String.format("mv %s %s", formatFilePathForCommandLine(received),
49+
formatFilePathForCommandLine(approved));
4550
}
4651
}
52+
private static String formatFilePathForCommandLine(String filePath)
53+
{
54+
if (filePath.contains(" "))
55+
{ return '"' + filePath + '"'; }
56+
return filePath;
57+
}
4758
}

0 commit comments

Comments
 (0)