Skip to content

Commit

Permalink
Fix :vgo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbrooks committed Oct 5, 2024
1 parent c6b5f7f commit 50668b4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.jzbrooks.vgo
package com.jzbrooks.vgo.cli

import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.doesNotContain
import assertk.assertions.isEqualTo
import assertk.assertions.matches
import assertk.assertions.startsWith
import com.jzbrooks.vgo.Vgo
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
Expand Down
39 changes: 30 additions & 9 deletions vgo/src/test/kotlin/com/jzbrooks/vgo/BaselineTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ class BaselineTests {
val inputFile = unoptimizedAsset.toFile()
val inputFileName = inputFile.name.substring(0, inputFile.name.lastIndexOf('.'))
val outputFilePath = "build/test-results/${inputFileName}_testOptimizationFinishes.${inputFile.extension}"
val arguments = arrayOf(unoptimizedAsset.toString(), "-o", outputFilePath, "--indent", "2")

val exitCode = Vgo().run(arguments)
val options =
Vgo.Options(
indent = 2,
input = listOf(unoptimizedAsset.toString()),
output = listOf(outputFilePath),
)

val exitCode = Vgo(options).run()

assertThat(exitCode).isEqualTo(0)
}
Expand All @@ -36,9 +42,14 @@ class BaselineTests {
val inputFile = unoptimizedAsset.toFile()
val inputFileName = inputFile.name.substring(0, inputFile.name.lastIndexOf('.'))
val outputFilePath = "build/test-results/${inputFileName}_testOptimizedAssetIsEquivalentToBaseline.${inputFile.extension}"
val arguments = arrayOf(unoptimizedAsset.toString(), "-o", outputFilePath, "--indent", "2")
val options =
Vgo.Options(
indent = 2,
input = listOf(unoptimizedAsset.toString()),
output = listOf(outputFilePath),
)

Vgo().run(arguments)
Vgo(options).run()

val content = File(outputFilePath)
val baselineContent = baselineAsset.toFile()
Expand All @@ -54,9 +65,14 @@ class BaselineTests {
val inputFile = unoptimizedAsset.toFile()
val inputFileName = inputFile.name.substring(0, inputFile.name.lastIndexOf('.'))
val outputFilePath = "build/test-results/${inputFileName}_testOptimizedAssetIsNotLargerThanBaseline.${inputFile.extension}"
val arguments = arrayOf(unoptimizedAsset.toString(), "-o", outputFilePath, "--indent", "2")
val options =
Vgo.Options(
indent = 2,
input = listOf(unoptimizedAsset.toString()),
output = listOf(outputFilePath),
)

Vgo().run(arguments)
Vgo(options).run()

val optimizedAssetSize = File(outputFilePath).length()
val baselineAssetSize = baselineAsset.toFile().length()
Expand All @@ -70,9 +86,14 @@ class BaselineTests {
val inputFile = unoptimizedAsset.toFile()
val inputFileName = inputFile.name.substring(0, inputFile.name.lastIndexOf('.'))
val outputFilePath = "build/test-results/${inputFileName}_testOptimizedAssetIsNotLargerThanOriginal.${inputFile.extension}"
val arguments = arrayOf(unoptimizedAsset.toString(), "-o", outputFilePath, "--indent", "2")

Vgo().run(arguments)
val options =
Vgo.Options(
indent = 2,
input = listOf(unoptimizedAsset.toString()),
output = listOf(outputFilePath),
)

Vgo(options).run()

val optimizedAssetSize = File(outputFilePath).length()
val unoptimizedAssetSize = unoptimizedAsset.toFile().length()
Expand Down
39 changes: 28 additions & 11 deletions vgo/src/test/kotlin/com/jzbrooks/vgo/InPlaceModificationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,51 @@ class InPlaceModificationTest {

@Test
fun `in-place optimization completes successfully`() {
val arguments = arrayOf("src/test/resources/in-place-modify")

val exitCode = Vgo().run(arguments)
val options =
Vgo.Options(
input = listOf("src/test/resources/in-place-modify"),
)
val exitCode = Vgo(options).run()

assertThat(exitCode).isEqualTo(0)
}

@Test
fun `individual file statistics are reported with a directory input`() {
val arguments = arrayOf("src/test/resources/in-place-modify", "--stats")

Vgo().run(arguments)
val options =
Vgo.Options(
printStats = true,
input = listOf("src/test/resources/in-place-modify"),
)
Vgo(options).run()

assertThat(systemOutput.toString())
.contains(Paths.get("src/test/resources/in-place-modify/avocado_example.xml").toString())
}

@Test
fun `non-vector files are not mentioned in statistics reporting with a directory input`() {
val arguments = arrayOf("src/test/resources/in-place-modify", "--stats")
val options =
Vgo.Options(
printStats = true,
input = listOf("src/test/resources/in-place-modify"),
)

Vgo().run(arguments)
Vgo(options).run()

assertThat(systemOutput.toString())
.doesNotContain("src/test/resources/in-place-modify/non_vector.xml")
}

@Test
fun `only modified files appear in statistics reporting`() {
val arguments = arrayOf("src/test/resources/in-place-modify", "--stats")
val options =
Vgo.Options(
printStats = true,
input = listOf("src/test/resources/in-place-modify"),
)

Vgo().run(arguments)
Vgo(options).run()

assertThat(systemOutput.toString())
.doesNotContain("src/test/resources/in-place-modify/avocado_example_optimized.xml")
Expand All @@ -84,7 +97,11 @@ class InPlaceModificationTest {
val input = File("src/test/resources/in-place-modify/non_vector.xml")
val before = input.readText()

Vgo().run(arrayOf(input.parent))
val options =
Vgo.Options(
input = listOf(input.parent.toString()),
)
Vgo(options).run()

val after = input.readText()
assertThat(after).isEqualTo(before)
Expand Down

0 comments on commit 50668b4

Please sign in to comment.