Skip to content

Commit

Permalink
Fix Unit Test
Browse files Browse the repository at this point in the history
And migrate all tests to Spock

Change-Id: I99ba2f57c0f858db55c04fac08def6fff0b329e4
  • Loading branch information
ngyukman committed Jan 15, 2024
1 parent 9583ec7 commit 4de41c6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 176 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ext.dotnetPath = file('src/main/dotnet')
dependencies {
testImplementation(platform('org.junit:junit-bom:5.10.1'))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
testImplementation 'org.spockframework:spock-core:2.3-groovy-2.5'
implementation 'net.java.dev.jna:jna:4.2.2'
implementation 'net.java.dev.jna:jna-platform:4.2.2'
implementation 'com.google.guava:guava:32.0.0-jre'
Expand Down
20 changes: 20 additions & 0 deletions src/test/groovy/com/ullink/MsbuildLocateSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ullink

import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification

class MsbuildLocateSpec extends Specification {
def testMsBuildCanBeFound() {
given:
def resolver = new MsbuildResolver()

when:
Project p = ProjectBuilder.builder().build()
p.apply plugin: MsbuildPlugin
resolver.setupExecutable(p.tasks.msbuild)

then:
p.tasks.msbuild.msbuildDir != null
}
}
31 changes: 0 additions & 31 deletions src/test/groovy/com/ullink/MsbuildLocateTest.groovy

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.internal.os.OperatingSystem
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import spock.lang.Specification

import static org.junit.Assert.assertTrue

class MsbuildPluginTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
public void msbuildPluginAddsMsbuildTaskToProject() {
class MsbuildPluginSpec extends Specification {
def msbuildPluginAddsMsbuildTaskToProject() {
given:
Project project = ProjectBuilder.builder().build()

when:
project.apply plugin: MsbuildPlugin
assertTrue(project.tasks.msbuild instanceof Msbuild)

then:
project.tasks.msbuild instanceof Msbuild
}

@Test
public void testExecution() {
def testExecution() {
given:
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.Project(ToolsVersion:"4.0", DefaultTargets:"Test", xmlns:"http://schemas.microsoft.com/developer/msbuild/2003") {
Expand All @@ -34,23 +31,32 @@ class MsbuildPluginTest {
write writer.toString()
}

when:
Project p = ProjectBuilder.builder().build()
p.apply plugin: MsbuildPlugin
p.msbuild {
projectFile = file
}
p.tasks.msbuild.build()

then:
noExceptionThrown()
}
@Test
public void execution_nonExistentProjectFile_throwsGradleException() {

def execution_nonExistentProjectFile_throwsGradleException() {
given:
Project p = ProjectBuilder.builder().build()

when:
p.apply plugin: MsbuildPlugin
p.msbuild {
projectFile = OperatingSystem.current().isWindows() ? 'C:\\con' : '/con' // we can never create a file called `con` in root
}

expectedException.expect(GradleException.class);

and:
p.tasks.msbuild.build()

then:
thrown(GradleException)
}
}
67 changes: 0 additions & 67 deletions src/test/groovy/com/ullink/PosixMsbuildLocateTests.groovy

This file was deleted.

59 changes: 0 additions & 59 deletions src/test/groovy/com/ullink/XbuildLocateTest.groovy

This file was deleted.

0 comments on commit 4de41c6

Please sign in to comment.