Skip to content

Commit

Permalink
Always match against normalized text blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Oct 16, 2023
1 parent 558fcfb commit 59b55f8
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractFunctionalTest
process.output.contains "Hello, native!"

and:
file("build/native/generated/generateResourcesConfigFile/resource-config.json").text == '''{
matches(file("build/native/generated/generateResourcesConfigFile/resource-config.json"), '''{
"resources" : {
"includes" : [ {
"pattern" : "\\\\Qmessage.txt\\\\E"
} ],
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')

where:
junitVersion = System.getProperty('versions.junit')
Expand Down Expand Up @@ -151,7 +151,7 @@ graalvmNative {
}

and:
file("build/native/generated/generateTestResourcesConfigFile/resource-config.json").text == '''{
matches(file("build/native/generated/generateTestResourcesConfigFile/resource-config.json"), '''{
"resources" : {
"includes" : [ {
"pattern" : "\\\\Qmessage.txt\\\\E"
Expand All @@ -161,7 +161,7 @@ graalvmNative {
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')

where:
junitVersion = System.getProperty('versions.junit')
Expand Down Expand Up @@ -242,15 +242,15 @@ graalvmNative {
nativeApp.exists()

and:
file("build/native/generated/generateResourcesConfigFile/resource-config.json").text == '''{
matches(file("build/native/generated/generateResourcesConfigFile/resource-config.json"), '''{
"resources" : {
"includes" : [ {
"pattern" : "\\\\Qmessage.txt\\\\E"
} ],
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')

when:
def process = execute(nativeApp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ReachabilityMetadataFunctionalTest extends AbstractFunctionalTest {
}

and: "has copied metadata file"
file("build/native-reachability-metadata/META-INF/native-image/com.h2database/h2/2.1.210/resource-config.json").text.trim() == '''{
matches(file("build/native-reachability-metadata/META-INF/native-image/com.h2database/h2/2.1.210/resource-config.json").text.trim(), '''{
"bundles": [],
"resources": {
"includes": [
Expand All @@ -71,7 +71,7 @@ class ReachabilityMetadataFunctionalTest extends AbstractFunctionalTest {
}
]
}
}'''
}''')
and: "has copied reachability-metadata.properties file"
file("build/native-reachability-metadata/META-INF/native-image/io.netty/netty-codec-http/4.1.80.Final/reachability-metadata.properties").text.trim() == 'override=true'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,11 @@ abstract class AbstractPluginTest extends Specification {
}
}

static boolean matches(String actual, String expected) {
normalizeString(actual) == normalizeString(expected)
}

private static String normalizeString(String input) {
input.replace("\r\n", "\n")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
then:
with(project) {
outputFile.exists()
outputFile.text == '''{
matches(outputFile.text, '''{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')
}
}

Expand All @@ -72,7 +72,7 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
then:
with(project) {
outputFile.exists()
outputFile.text == '''{
matches(outputFile.text, '''{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
Expand All @@ -82,7 +82,7 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
}, {
"name" : "other.bundle"
} ]
}'''
}''')
}
}

Expand All @@ -98,7 +98,7 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
then:
with(project) {
outputFile.exists()
outputFile.text == '''{
matches(outputFile.text, '''{
"resources" : {
"includes" : [ {
"pattern" : "pattern"
Expand All @@ -112,7 +112,7 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
} ]
},
"bundles" : [ ]
}'''
}''')
}
}

Expand All @@ -127,13 +127,13 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
then:
with(project) {
outputFile.exists()
outputFile.text == '''{
matches(outputFile.text, '''{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')
}
}

Expand All @@ -149,15 +149,15 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
then:
with(project) {
outputFile.exists()
outputFile.text == '''{
matches(outputFile.text, '''{
"resources" : {
"includes" : [ {
"pattern" : "\\\\Qorg/foo/some/resource.txt\\\\E"
} ],
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')
}
}

Expand All @@ -174,15 +174,15 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
then:
with(project) {
outputFile.exists()
outputFile.text == '''{
matches(outputFile.text, '''{
"resources" : {
"includes" : [ {
"pattern" : "\\\\Qorg/foo/some/resource.txt\\\\E"
} ],
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')
}
}

Expand All @@ -198,15 +198,15 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
then:
with(project) {
outputFile.exists()
outputFile.text == '''{
matches(outputFile.text, '''{
"resources" : {
"includes" : [ {
"pattern" : "\\\\Qorg/foo/some/resource.txt\\\\E"
} ],
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')
}
}

Expand All @@ -224,13 +224,13 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
then:
with(project) {
outputFile.exists()
outputFile.text == '''{
matches(outputFile.text, '''{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')
}
}

Expand All @@ -246,13 +246,13 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
then:
with(project) {
outputFile.exists()
outputFile.text == '''{
matches(outputFile.text, '''{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ abstract class AbstractFunctionalTest extends Specification {
assert errorOutput.contains(normalizeString(text))
}

static boolean matches(String actual, String expected) {
normalizeString(actual) == normalizeString(expected)
}

void tasks(@DelegatesTo(value = TaskExecutionGraph, strategy = Closure.DELEGATE_FIRST) Closure spec) {
def graph = new TaskExecutionGraph()
spec.delegate = graph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractGraalVMMavenFun
outputContains "Hello, native!"

and:
file("target/native/generated/generateResourceConfig/resource-config.json").text == '''{
matches(file("target/native/generated/generateResourceConfig/resource-config.json").text, '''{
"resources" : {
"includes" : [ {
"pattern" : "\\\\Qmessage.txt\\\\E"
} ],
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')

where:
detection | includedPatterns | restrictToModules | detectionExclusionPatterns
Expand Down Expand Up @@ -75,7 +75,7 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractGraalVMMavenFun
buildSucceeded

and:
file("target/native/generated/generateTestResourceConfig/resource-config.json").text == '''{
matches(file("target/native/generated/generateTestResourceConfig/resource-config.json").text, '''{
"resources" : {
"includes" : [ {
"pattern" : "\\\\Qmessage.txt\\\\E"
Expand All @@ -85,7 +85,7 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractGraalVMMavenFun
"excludes" : [ ]
},
"bundles" : [ ]
}'''
}''')

where:
detection | includedPatterns | restrictToModules | detectionExclusionPatterns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ class MetadataRepositoryFunctionalTest extends AbstractGraalVMMavenFunctionalTes
buildSucceeded

and:
file("target/classes/META-INF/native-image/org.graalvm.internal/library-with-reflection/1.5/reflect-config.json").text.trim() == '''[
matches(file("target/classes/META-INF/native-image/org.graalvm.internal/library-with-reflection/1.5/reflect-config.json").text.trim(), '''[
{
"name": "org.graalvm.internal.reflect.Message",
"allDeclaredFields": true,
"allDeclaredMethods": true
}
]'''
]''')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification {
!normalizeString(result.stdOut).contains(normalizeString(text))
}

static boolean matches(String actual, String expected) {
normalizeString(actual) == normalizeString(expected)
}

File file(String path) {
testDirectory.resolve(path).toFile()
}
Expand Down

0 comments on commit 59b55f8

Please sign in to comment.