Skip to content

Commit 034dcaa

Browse files
authored
fix
* overhaul * review fixes * Update CMDTests.kt
1 parent 202d2ac commit 034dcaa

1 file changed

Lines changed: 131 additions & 132 deletions

File tree

src/test/kotlin/CMDTests.kt

Lines changed: 131 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
import file.ExitHandler
2-
import kotlin.system.exitProcess
3-
import file.CLICommand
4-
import file.DependencyManager
5-
import file.SetupApp
6-
import file.SetupMain
7-
import global.InstallationManager
8-
import net.ConnectionManager
9-
import org.eclipse.jgit.internal.storage.file.FileRepository
10-
import org.testng.Assert
1+
import file.ExitHandler
2+
import file.CLICommand
3+
import file.DependencyManager
4+
import file.SetupApp
5+
import file.SetupMain
6+
import global.InstallationManager
7+
import net.ConnectionManager
8+
import org.eclipse.jgit.internal.storage.file.FileRepository
9+
import org.testng.Assert
1110
import org.testng.annotations.Test
1211
import java.nio.file.Files
1312
import java.nio.file.Path
1413
import java.util.Comparator
15-
16-
17-
private class ExitException(val code: Int) : RuntimeException("exit $code")
18-
14+
15+
16+
private class ExitException(val code: Int) : RuntimeException("exit $code")
17+
1918
private fun catchExit(block: () -> Unit): Int {
20-
val prev = ExitHandler.handler
21-
var code = -1
22-
try {
23-
ExitHandler.handler = { throw ExitException(it) }
24-
block()
25-
} catch (e: ExitException) {
26-
code = e.code
27-
} finally {
28-
ExitHandler.handler = prev
29-
}
30-
return code
19+
val prev = ExitHandler.handler
20+
var code = -1
21+
try {
22+
ExitHandler.handler = { throw ExitException(it) }
23+
block()
24+
} catch (e: ExitException) {
25+
code = e.code
26+
} finally {
27+
ExitHandler.handler = prev
28+
}
29+
return code
3130
}
3231

3332
private fun deleteRecursively(path: Path) {
@@ -38,9 +37,9 @@ private fun deleteRecursively(path: Path) {
3837
Files.deleteIfExists(it)
3938
}
4039
}
41-
42-
class CMDTests {
43-
40+
41+
class CMDTests {
42+
4443
companion object {
4544
private const val INSTALL = "install"
4645
private const val REMOVE = "remove"
@@ -58,57 +57,57 @@ class CMDTests {
5857
SetupMain.main(listOf(GENERATE, generatedProjectName).toTypedArray())
5958
}
6059
}
61-
62-
63-
@Test(priority = 1)
64-
fun testUnInstallCmd() {
65-
SetupMain.main(listOf(INSTALL, WURSTSCRIPT).toTypedArray())
66-
ConnectionManager.checkConnectivity("http://google.com")
67-
ConnectionManager.checkWurstBuild()
68-
InstallationManager.verifyInstallation()
69-
Assert.assertNotEquals(InstallationManager.status, InstallationManager.InstallationStatus.NOT_INSTALLED)
70-
71-
try {
72-
SetupMain.main(listOf(REMOVE, WURSTSCRIPT).toTypedArray())
73-
InstallationManager.verifyInstallation()
74-
Assert.assertEquals(
75-
InstallationManager.status,
76-
InstallationManager.InstallationStatus.NOT_INSTALLED,
77-
"Remove failed — compiler jar may be locked by VSCode or another process"
78-
)
79-
} finally {
80-
// Always restore so subsequent tests have a working compiler
81-
SetupMain.main(listOf(INSTALL, WURSTSCRIPT).toTypedArray())
82-
InstallationManager.verifyInstallation()
83-
Assert.assertNotEquals(
84-
InstallationManager.status,
85-
InstallationManager.InstallationStatus.NOT_INSTALLED,
86-
"Reinstall after remove must succeed for subsequent tests to work"
87-
)
88-
}
89-
}
90-
91-
@Test(priority = 2)
92-
fun testCreateHelpCmd() {
93-
Assert.assertNotEquals(InstallationManager.status, InstallationManager.InstallationStatus.NOT_INSTALLED)
94-
val setupMain = SetupMain()
95-
setupMain.doMain(listOf(HELP).toTypedArray())
96-
97-
Assert.assertEquals(setupMain.command, CLICommand.HELP)
98-
}
99-
100-
@Test(priority = 2)
60+
61+
62+
@Test(priority = 1)
63+
fun testUnInstallCmd() {
64+
SetupMain.main(listOf(INSTALL, WURSTSCRIPT).toTypedArray())
65+
ConnectionManager.checkConnectivity("http://google.com")
66+
ConnectionManager.checkWurstBuild()
67+
InstallationManager.verifyInstallation()
68+
Assert.assertNotEquals(InstallationManager.status, InstallationManager.InstallationStatus.NOT_INSTALLED)
69+
70+
try {
71+
SetupMain.main(listOf(REMOVE, WURSTSCRIPT).toTypedArray())
72+
InstallationManager.verifyInstallation()
73+
Assert.assertEquals(
74+
InstallationManager.status,
75+
InstallationManager.InstallationStatus.NOT_INSTALLED,
76+
"Remove failed — compiler jar may be locked by VSCode or another process"
77+
)
78+
} finally {
79+
// Always restore so subsequent tests have a working compiler
80+
SetupMain.main(listOf(INSTALL, WURSTSCRIPT).toTypedArray())
81+
InstallationManager.verifyInstallation()
82+
Assert.assertNotEquals(
83+
InstallationManager.status,
84+
InstallationManager.InstallationStatus.NOT_INSTALLED,
85+
"Reinstall after remove must succeed for subsequent tests to work"
86+
)
87+
}
88+
}
89+
90+
@Test(priority = 2)
91+
fun testCreateHelpCmd() {
92+
Assert.assertNotEquals(InstallationManager.status, InstallationManager.InstallationStatus.NOT_INSTALLED)
93+
val setupMain = SetupMain()
94+
setupMain.doMain(listOf(HELP).toTypedArray())
95+
96+
Assert.assertEquals(setupMain.command, CLICommand.HELP)
97+
}
98+
99+
@Test(priority = 2)
101100
fun testCreateProjectCmd() {
102-
Assert.assertNotEquals(InstallationManager.status, InstallationManager.InstallationStatus.NOT_INSTALLED)
101+
Assert.assertNotEquals(InstallationManager.status, InstallationManager.InstallationStatus.NOT_INSTALLED)
103102
deleteRecursively(SetupApp.DEFAULT_DIR.resolve(generatedProjectName))
104103
SetupMain.main(listOf(GENERATE, generatedProjectName).toTypedArray())
105104

106105
Assert.assertTrue(Files.exists(SetupApp.DEFAULT_DIR.resolve(generatedProjectName)))
107106

108107
SetupMain.main(listOf(INSTALL, "-projectDir", "./$generatedProjectName/").toTypedArray())
109108
}
110-
111-
@Test(priority = 3)
109+
110+
@Test(priority = 3)
112111
fun testAddDependency() {
113112
ensureGeneratedProjectExists()
114113
Assert.assertTrue(Files.exists(SetupApp.DEFAULT_DIR.resolve("$generatedProjectName/wurst.build")))
@@ -118,8 +117,8 @@ class CMDTests {
118117
val buildfile = String(Files.readAllBytes(SetupApp.DEFAULT_DIR.resolve("./$generatedProjectName/wurst.build")))
119118
Assert.assertTrue(buildfile.contains("https://github.com/Frotty/Frentity"))
120119
}
121-
122-
@Test(priority = 3)
120+
121+
@Test(priority = 3)
123122
fun testAddDependencyBranched() {
124123
ensureGeneratedProjectExists()
125124
Assert.assertTrue(Files.exists(SetupApp.DEFAULT_DIR.resolve("$generatedProjectName/wurst.build")))
@@ -129,9 +128,9 @@ class CMDTests {
129128
val buildfile = String(Files.readAllBytes(SetupApp.DEFAULT_DIR.resolve("./$generatedProjectName/wurst.build")))
130129
Assert.assertTrue(buildfile.contains("https://github.com/Frotty/wurst-item-recipes:main"))
131130
}
132-
133-
134-
@Test(priority = 3)
131+
132+
133+
@Test(priority = 3)
135134
fun testProjectTest() {
136135
val testproject = Files.createTempDirectory("wurst-stdlib-test")
137136
DependencyManager.cloneRepo("https://github.com/wurstscript/WurstStdlib2.git", testproject)
@@ -141,76 +140,76 @@ class CMDTests {
141140

142141
val setupMain = SetupMain()
143142
setupMain.projectRoot = testproject
144-
val code = catchExit { setupMain.doMain(arrayOf(TEST)) }
145-
Assert.assertEquals(code, 0, "grill test should succeed on WurstStdlib2")
146-
}
147-
148-
@Test(priority = 3)
143+
val code = catchExit { setupMain.doMain(arrayOf(TEST)) }
144+
Assert.assertEquals(code, 0, "grill test should succeed on WurstStdlib2")
145+
}
146+
147+
@Test(priority = 3)
149148
fun testBranchPull() {
150149
val testproject = Files.createTempDirectory("wurst-ptr-test")
151150
DependencyManager.cloneRepo("https://github.com/wurstscript/WurstStdlib2:ptr", testproject)
152-
153-
Assert.assertTrue(Files.exists(testproject))
154-
FileRepository(testproject.resolve(".git").toFile()).use { repository ->
155-
Assert.assertEquals(repository.branch, "ptr")
156-
157-
}
158-
}
159-
160-
@Test(priority = 3)
151+
152+
Assert.assertTrue(Files.exists(testproject))
153+
FileRepository(testproject.resolve(".git").toFile()).use { repository ->
154+
Assert.assertEquals(repository.branch, "ptr")
155+
156+
}
157+
}
158+
159+
@Test(priority = 3)
161160
fun testProjectBuild() {
162161
val testproject = Files.createTempDirectory("wurst-build-test")
163162
DependencyManager.cloneRepo("https://github.com/Frotty/ConflagrationSpell.git", testproject)
164-
Assert.assertTrue(Files.exists(testproject.resolve("wurst.build")))
165-
163+
Assert.assertTrue(Files.exists(testproject.resolve("wurst.build")))
164+
166165
SetupMain.main(listOf(INSTALL, "-projectDir", testproject.toString()).toTypedArray())
167-
Assert.assertTrue(
168-
Files.exists(testproject.resolve("_build/dependencies")),
169-
"grill install must have pulled dependencies before building"
170-
)
171-
172-
val setupMain = SetupMain()
173-
setupMain.projectRoot = testproject
174-
val code = catchExit { setupMain.doMain(arrayOf(BUILD, "ExampleMap.w3x")) }
175-
Assert.assertEquals(code, 0, "grill build should succeed on ConflagrationSpell")
176-
}
177-
166+
Assert.assertTrue(
167+
Files.exists(testproject.resolve("_build/dependencies")),
168+
"grill install must have pulled dependencies before building"
169+
)
170+
171+
val setupMain = SetupMain()
172+
setupMain.projectRoot = testproject
173+
val code = catchExit { setupMain.doMain(arrayOf(BUILD, "ExampleMap.w3x", "--noPJass")) }
174+
Assert.assertEquals(code, 0, "grill build should succeed on ConflagrationSpell")
175+
}
176+
178177
@Test(priority = 4)
179178
fun testTypecheckCreatedProject() {
180179
ensureGeneratedProjectExists()
181180
val projectDir = SetupApp.DEFAULT_DIR.resolve(generatedProjectName)
182-
Assert.assertTrue(Files.exists(projectDir.resolve("wurst.build")), "generated project must exist")
183-
Assert.assertTrue(
184-
Files.exists(projectDir.resolve("_build/dependencies")),
185-
"grill install must have run on the generated project"
186-
)
187-
188-
val setupMain = SetupMain()
189-
setupMain.projectRoot = projectDir
190-
val code = catchExit { setupMain.doMain(arrayOf("typecheck")) }
191-
Assert.assertEquals(code, 0, "grill typecheck must succeed on a freshly generated project with stdlib installed")
192-
}
193-
194-
195-
@Test(priority = 4)
196-
fun testInvalid() {
197-
val status = catchExit {
198-
SetupMain.main(listOf("-someInvalidCommand").toTypedArray())
199-
}
200-
Assert.assertEquals(status, 1)
201-
}
202-
203-
@Test(priority = 5)
181+
Assert.assertTrue(Files.exists(projectDir.resolve("wurst.build")), "generated project must exist")
182+
Assert.assertTrue(
183+
Files.exists(projectDir.resolve("_build/dependencies")),
184+
"grill install must have run on the generated project"
185+
)
186+
187+
val setupMain = SetupMain()
188+
setupMain.projectRoot = projectDir
189+
val code = catchExit { setupMain.doMain(arrayOf("typecheck")) }
190+
Assert.assertEquals(code, 0, "grill typecheck must succeed on a freshly generated project with stdlib installed")
191+
}
192+
193+
194+
@Test(priority = 4)
195+
fun testInvalid() {
196+
val status = catchExit {
197+
SetupMain.main(listOf("-someInvalidCommand").toTypedArray())
198+
}
199+
Assert.assertEquals(status, 1)
200+
}
201+
202+
@Test(priority = 5)
204203
fun testInvalidInstall() {
205204
val invalid = Files.createTempDirectory("wurst-invalid-test")
206205
DependencyManager.cloneRepo("https://github.com/Frotty/ConflagrationSpell.git", invalid)
207-
Assert.assertTrue(Files.exists(invalid.resolve("wurst.build")))
208-
206+
Assert.assertTrue(Files.exists(invalid.resolve("wurst.build")))
207+
209208
val status = catchExit {
210209
SetupMain.main(listOf(INSTALL, "someInvalid", "-projectDir", invalid.toString()).toTypedArray())
211210
}
212-
Assert.assertEquals(status, 1)
213-
214-
}
215-
216-
}
211+
Assert.assertEquals(status, 1)
212+
213+
}
214+
215+
}

0 commit comments

Comments
 (0)