@@ -47,55 +47,98 @@ class ClearDanglingUnityFilesIntegrationSpec extends IntegrationSpec {
47
47
assert tempFolder. exists()
48
48
assert fakeProcess ? fakeProcess. alive : true
49
49
assert editorInstanceFile. exists() == hasEditorInstanceFile
50
- runTasksSuccessfully(" testTask" )
50
+ def result = runTasksSuccessfully(" testTask" )
51
51
52
52
then :
53
+ println result. standardOutput
53
54
tempFolder. exists() == ! shouldCleanup
54
55
55
56
cleanup :
56
- fakeProcess?. destroy ()
57
+ fakeProcess?. destroyForcibly ()
57
58
editorInstanceFile. delete()
58
59
59
60
60
61
where :
61
62
hasOpenProcess | hasEditorInstanceFile | terminateProcess | shouldCleanup | prefix | suffix
62
- false | false | false | true | " should delete" | " no running Unity process with the project [0 ]"
63
- false | false | true | true | " should delete" | " no running Unity process with the project [1 ]"
64
- true | true | true | true | " should delete" | " running process with the project [1 ]"
65
- true | false | false | true | " should delete" | " running process with the project [2 ]"
66
- true | true | false | false | " shouldnt delete" | " running process with the project"
63
+ false | false | false | true | " should delete" | " no running Unity process with the project [terminate=false ]"
64
+ false | false | true | true | " should delete" | " no running Unity process with the project [terminate=true ]"
65
+ true | true | true | true | " should delete" | " running process with the project [terminate=true, EditorInstance.json ]"
66
+ true | false | false | true | " should delete" | " running process with the project [terminate=false, no EditorInstance.json ]"
67
+ true | true | false | false | " shouldnt delete" | " running process with the project [terminate=false, EditorInstance.json] "
67
68
}
68
69
69
- def createFakeFrozenUnityExecutable () {
70
+ @IgnoreIf ({ os.windows })
71
+ def " #prefix terminate Unity process if there is a #suffix" () {
72
+ given :
73
+ def tempFolder = new File (projectDir, " Temp" ). with {
74
+ it. mkdir()
75
+ new File (it, " UnityLockfile" ). createNewFile()
76
+ return it
77
+ }
78
+ and :
79
+ def fakeUnityExec = createFakeFrozenUnityExecutable(processIgnoring)
80
+ def fakeProcess = " $fakeUnityExec . absolutePath -projectPath ${ projectDir.absolutePath} " . execute()
81
+ fakeProcess. waitFor(10 , TimeUnit . MILLISECONDS )
82
+ File editorInstanceFile = new File (projectDir, " Library/EditorInstance.json" )
83
+ editorInstanceFile. parentFile. mkdir()
84
+ editorInstanceFile << """
85
+ {
86
+ "process_id" : ${ wrapValueBasedOnType(fakeProcess.pid(), Integer)} ,
87
+ "version" : "any",
88
+ "app_path" : "any",
89
+ "app_contents_path" : "any"
90
+ }
91
+ """
92
+ and :
93
+ buildFile << """
94
+ tasks.register("testTask", wooga.gradle.unity.tasks.ClearDanglingUnityFiles) {
95
+ projectDirectory.set(${ wrapValueBasedOnType(projectDir, File)} )
96
+ terminateOpenProcess.set($terminateProcess )
97
+ }
98
+ """
99
+
100
+ when :
101
+ assert tempFolder. exists()
102
+ assert fakeProcess ? fakeProcess. alive : true
103
+ def result = runTasksSuccessfully(" testTask" )
104
+
105
+ then :
106
+ println result. standardOutput
107
+ terminateProcess == ! fakeProcess. alive
108
+
109
+ cleanup :
110
+ fakeProcess?. destroyForcibly()
111
+ editorInstanceFile. delete()
112
+
113
+
114
+ where :
115
+ terminateProcess | processIgnoring | prefix | suffix
116
+ false | [] | " shouldn't" | " normal running process"
117
+ false | [" SIGINT" , " SIGTERM" ] | " shouldn't" | " frozen process"
118
+ true | [] | " should" | " normal running process"
119
+ true | [" SIGINT" , " SIGTERM" ] | " should" | " frozen process"
120
+ }
121
+
122
+ def createFakeFrozenUnityExecutable (List<String > signalsToIgnore = []) {
70
123
def fakeFrozenUnity = new File (projectDir, " Unity" ). with {
71
124
it. createNewFile()
72
125
it. executable = true
73
126
return it
74
127
}
75
- if (PlatformUtils . windows) {
76
- fakeFrozenUnity <<
77
- """ @echo off
78
- echo 'started'
79
- :loop
80
- timeout /t 0.010 >nul
81
- goto loop
82
- """
83
- } else {
84
- fakeFrozenUnity <<
85
- """
86
- #!/bin/bash
87
-
88
- # Trap the SIGINT signal (Ctrl+C) and execute a function
89
- trap 'exit' SIGINT
90
-
91
- echo "started"
92
- # Infinite loop
93
- while true
94
- do
95
- sleep 0.010
96
- done
97
- """
98
- }
128
+ fakeFrozenUnity <<
129
+ """
130
+ #!/bin/bash
131
+
132
+ # Trap the SIGINT signal (Ctrl+C) and SIGTERM (kill)
133
+ trap -- '' ${ signalsToIgnore.join(" ")}
134
+
135
+ echo "started"
136
+ # Infinite loop
137
+ while true
138
+ do
139
+ sleep 0.010
140
+ done
141
+ """
99
142
return fakeFrozenUnity
100
143
}
101
144
}
0 commit comments