Skip to content

Commit

Permalink
SCANGRADLE-176 Fix unit tests on Windows (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardo-pilastri-sonarsource authored Nov 4, 2024
1 parent a138e25 commit aae606f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
24 changes: 13 additions & 11 deletions src/test/groovy/org/sonarqube/gradle/FunctionalTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,15 @@ class FunctionalTests extends Specification {

var mainSources = ((String) props."sonar.sources").split(",")
mainSources.size() == 3
mainSources[0].endsWith("""$projectDir/build.gradle""")
mainSources[1].endsWith("""$projectDir/gradle.properties""")
mainSources[2].endsWith("""$projectDir/settings.gradle""")
var projectPath = projectDir.toString() + File.separator
mainSources[0].endsWith("""${projectPath}build.gradle""")
mainSources[1].endsWith("""${projectPath}gradle.properties""")
mainSources[2].endsWith("""${projectPath}settings.gradle""")

var testSources = ((String) props."sonar.tests").split(",")
testSources.size() == 2
testSources[0].endsWith("""$projectDir/integrationTests/run-all.sh""")
testSources[1].endsWith("""$projectDir/test-license.sh""")
testSources[0].endsWith("""${projectPath}integrationTests${File.separator}run-all.sh""")
testSources[1].endsWith("""${projectPath}test-license.sh""")
}

def "scan all is enabled but not applied because of overridden properties on the command line"() {
Expand Down Expand Up @@ -538,14 +539,15 @@ class FunctionalTests extends Specification {
// Test that the empty script is is collected but the reports are not collected
var mainSources = ((String) props."sonar.sources").split(",")
mainSources.size() == 4
mainSources[0].endsWith("""$projectDir/build.gradle""")
mainSources[1].endsWith("""$projectDir/empty-script.groovy""")
mainSources[2].endsWith("""$projectDir/gradle.properties""")
mainSources[3].endsWith("""$projectDir/settings.gradle""")
var projectPath = projectDir.toString() + File.separator
mainSources[0].endsWith("""${projectPath}build.gradle""")
mainSources[1].endsWith("""${projectPath}empty-script.groovy""")
mainSources[2].endsWith("""${projectPath}gradle.properties""")
mainSources[3].endsWith("""${projectPath}settings.gradle""")

var testSources = ((String) props."sonar.tests").split(",")
testSources.size() == 2
testSources[0].endsWith("""$projectDir/integrationTests/run-all.sh""")
testSources[1].endsWith("""$projectDir/test-license.sh""")
testSources[0].endsWith("""${projectPath}integrationTests${File.separator}run-all.sh""")
testSources[1].endsWith("""${projectPath}test-license.sh""")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ class SonarQubePluginTest extends Specification {
return properties.getOrDefault(propertyName, "").split(",")
.stream()
.filter(s -> !s.isBlank())
.map(s -> project.projectDir.toPath().relativize(Path.of(s)).toString())
.map(s -> project.projectDir.toPath().relativize(Path.of(s)).toString().replace(File.separator, '/'))
// filter out an unexpected file internally created by the test framework
.filter(s -> !s.endsWith("file-access.properties"))
.sorted()
Expand Down
15 changes: 10 additions & 5 deletions src/test/java/org/sonarqube/gradle/SourceCollectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
*/
package org.sonarqube.gradle;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Set;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -156,6 +160,7 @@ void visitorIgnoresExcludedFiles() throws IOException {
}

@Test
@DisabledOnOs(OS.WINDOWS)
void visitorIgnoresSymbolicLinks() throws IOException {
Path simpleProjectPom = simpleProjectBasedDir.resolve("pom.xml");
simpleProjectPom.toFile().createNewFile();
Expand Down

0 comments on commit aae606f

Please sign in to comment.