@@ -11,29 +11,38 @@ import java.nio.file.attribute.PosixFilePermission
11
11
12
12
class CrossPlatformExecTest extends GroovyTestCase {
13
13
14
+ private static String separator = File . separator;
15
+
14
16
private Project project;
17
+ private Path testDir;
15
18
private Path [] commandFiles;
16
19
17
20
@Override
18
21
void setUp () {
19
22
project = ProjectBuilder . builder(). build()
20
23
21
- project. apply plugin : ' com.github.jlouns.cpe'
24
+ project. apply plugin : " com.github.jlouns.cpe"
25
+
26
+ testDir = Paths . get(" testdir" );
22
27
23
28
commandFiles = [
24
- Paths . get(' one' ),
25
- Paths . get(' one.cmd' ),
26
- Paths . get(' two.bat' ),
27
- Paths . get(' two.sh' ),
28
- Paths . get(' three' ),
29
- Paths . get(' three.exe' )
29
+ Paths . get(" one" ),
30
+ Paths . get(" one.cmd" ),
31
+ Paths . get(" two.bat" ),
32
+ Paths . get(" two.sh" ),
33
+ Paths . get(" three" ),
34
+ Paths . get(" three.exe" ),
35
+ testDir. resolve(" four.sh" ),
36
+ testDir. resolve(" four.exe" )
30
37
];
31
38
39
+ Files . createDirectory(testDir);
40
+
32
41
commandFiles. each {
33
42
Files . createFile(it)
34
43
try {
35
- Files . setPosixFilePermissions(it, EnumSet . allOf(PosixFilePermission ));
36
- } catch (Exception ex ) {
44
+ Files . setPosixFilePermissions(it, EnumSet . allOf(PosixFilePermission ))
45
+ } catch (Exception ignore ) {
37
46
// Ignore it, probably on windows
38
47
}
39
48
}
@@ -44,81 +53,98 @@ class CrossPlatformExecTest extends GroovyTestCase {
44
53
commandFiles. each {
45
54
Files . delete(it)
46
55
}
56
+ Files . delete(testDir);
47
57
}
48
58
49
59
Task createTask (String executable ) {
50
- Task task = project. task([ ' type' : CrossPlatformExec ], ' testCpe' ) {
51
- commandLine executable, ' foo'
60
+ Task task = project. task([ " type" : CrossPlatformExec ], " testCpe" ) {
61
+ commandLine executable, " foo"
52
62
}
53
63
54
64
try {
55
65
task. exec()
56
- } catch (Exception ex) {
57
- println (ex. stackTrace)
58
- // Ignore it
66
+ } catch (Exception ignore) {
67
+ ignore. printStackTrace()
59
68
}
60
69
61
70
task
62
71
}
63
72
64
73
static void asOs (String os ) {
65
- System . setProperty(' os.name' , os)
74
+ System . setProperty(" os.name" , os)
66
75
}
67
76
68
77
void testFormsLinuxExecCallForCommand () {
69
- asOs(' linux' )
78
+ asOs(" linux" )
70
79
71
- Task task = createTask(' echo' )
80
+ Task task = createTask(" echo" )
72
81
73
- assertArrayEquals ([' echo' , ' foo' ]. toArray(), task. commandLine. toArray());
82
+ assertArrayEquals ([" echo" , " foo" ]. toArray(), task. commandLine. toArray());
74
83
}
75
84
76
85
void testFormsLinuxExecCallForFile () {
77
- asOs(' linux' )
86
+ asOs(" linux" )
78
87
79
- Task task = createTask(' one' )
88
+ Task task = createTask(" one" )
80
89
81
- assertArrayEquals ([' ./ one' , ' foo' ]. toArray(), task. commandLine. toArray());
90
+ assertArrayEquals ([" . ${ separator } one" , " foo" ]. toArray(), task. commandLine. toArray());
82
91
}
83
92
84
93
void testFormsLinuxExecCallForShFile () {
85
- asOs(' linux' )
94
+ asOs(" linux" )
86
95
87
- Task task = createTask(' two' )
96
+ Task task = createTask(" two" )
88
97
89
- assertArrayEquals ([' ./ two.sh' , ' foo' ]. toArray(), task. commandLine. toArray());
98
+ assertArrayEquals ([" . ${ separator } two.sh" , " foo" ]. toArray(), task. commandLine. toArray());
90
99
}
91
100
92
101
void testFormsWindowsExecCallForCommand () {
93
- asOs(' windows' )
102
+ asOs(" windows" )
94
103
95
- Task task = createTask(' echo' )
104
+ Task task = createTask(" echo" )
96
105
97
- assertArrayEquals ([' cmd' , ' /c ' , ' echo' , ' foo' ]. toArray(), task. commandLine. toArray());
106
+ assertArrayEquals ([" cmd" , " /c " , " echo" , " foo" ]. toArray(), task. commandLine. toArray());
98
107
}
99
108
100
109
void testFormsWindowsExecCallForCmdFile () {
101
- asOs(' windows' )
110
+ asOs(" windows" )
102
111
103
- Task task = createTask(' one' )
112
+ Task task = createTask(" one" )
104
113
105
- assertArrayEquals ([' cmd' , ' /c ' , ' one.cmd' , ' foo' ]. toArray(), task. commandLine. toArray());
114
+ assertArrayEquals ([" cmd" , " /c " , " . ${ separator } one.cmd" , " foo" ]. toArray(), task. commandLine. toArray());
106
115
}
107
116
108
117
void testFormsWindowsExecCallForBatFile () {
109
- asOs(' windows' )
118
+ asOs(" windows" )
110
119
111
- Task task = createTask(' two' )
120
+ Task task = createTask(" two" )
112
121
113
- assertArrayEquals ([' cmd' , ' /c ' , ' two.bat' , ' foo' ]. toArray(), task. commandLine. toArray());
122
+ assertArrayEquals ([" cmd" , " /c " , " . ${ separator } two.bat" , " foo" ]. toArray(), task. commandLine. toArray());
114
123
}
115
124
116
125
void testFormsWindowsExecCallForExeFile () {
117
- asOs(' windows' )
126
+ asOs(" windows" )
127
+
128
+ Task task = createTask(" three" )
129
+
130
+ assertArrayEquals ([" cmd" , " /c" , " .${ separator} three.exe" , " foo" ]. toArray(), task. commandLine. toArray());
131
+ }
132
+
133
+ void testFixesPathSeparatorsOnLinux () {
134
+ asOs(" linux" )
135
+
136
+ Task task = createTask(" .\\ testdir\\ four" )
137
+
138
+ assertArrayEquals ([" .${ separator} testdir${ separator} four.sh" , " foo" ]. toArray(), task. commandLine. toArray());
139
+ }
140
+
141
+ void testFixesPathSeparatorsOnWindows () {
142
+ asOs(" windows" )
118
143
119
- Task task = createTask(' three ' )
144
+ Task task = createTask(" ./testdir/four " )
120
145
121
- assertArrayEquals ([' cmd' , ' /c' , ' three.exe' , ' foo' ]. toArray(), task. commandLine. toArray());
146
+ assertArrayEquals ([" cmd" , " /c" , " .${ separator} testdir${ separator} four.exe" , " foo" ]. toArray(),
147
+ task. commandLine. toArray());
122
148
}
123
149
124
150
}
0 commit comments