Browse Source

SQSCANNER-126 - Refactor test to be more precise in case of failure

pull/164/head
antoine.vinot 5 months ago
parent
commit
4e5aa33f75
1 changed files with 25 additions and 18 deletions
  1. 25
    18
      it/src/test/java/com/sonarsource/scanner/it/ScannerTest.java

+ 25
- 18
it/src/test/java/com/sonarsource/scanner/it/ScannerTest.java View File



Map<String, Measure> projectMeasures = getMeasures( Map<String, Measure> projectMeasures = getMeasures(
"java:basedir-with-source", "files", "ncloc"); "java:basedir-with-source", "files", "ncloc");
assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(1);
assertThat(parseInt(projectMeasures.get("ncloc").getValue()))
.isGreaterThan(1);

verifyProjectMeasures(projectMeasures, 1);
} }


/** /**
.useNative() .useNative()
.setProjectKey("SAMPLE"); .setProjectKey("SAMPLE");
orchestrator.executeBuild(build); orchestrator.executeBuild(build);

Map<String, Measure> projectMeasures = getMeasures("SAMPLE", "files", "ncloc"); Map<String, Measure> projectMeasures = getMeasures("SAMPLE", "files", "ncloc");
assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(1);
assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(1);
verifyProjectMeasures(projectMeasures, 1);
} }


/** /**
.setProjectKey("SAMPLE"); .setProjectKey("SAMPLE");
orchestrator.executeBuild(build); orchestrator.executeBuild(build);


Map<String, Measure> projectMeasures = getMeasures("SAMPLE", "files",
"ncloc");
assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(2);
assertThat(parseInt(projectMeasures.get("ncloc").getValue()))
.isGreaterThan(1);
Map<String, Measure> projectMeasures = getMeasures("SAMPLE", "files", "ncloc");
verifyProjectMeasures(projectMeasures, 2);
}

private void verifyProjectMeasures(Map<String, Measure> projectMeasures, int expectedFiles) {
assertThat(projectMeasures).isNotNull()
.containsKeys("files", "ncloc");
Measure files = projectMeasures.get("files");
assertThat(files).isNotNull();
assertThat(parseInt(files.getValue())).isEqualTo(expectedFiles);
Measure ncloc = projectMeasures.get("ncloc");
assertThat(ncloc).isNotNull();
assertThat(parseInt(ncloc.getValue())).isGreaterThan(1);
} }


/** /**
SonarScanner build = newScanner(new File("projects/bad-source-dirs")); SonarScanner build = newScanner(new File("projects/bad-source-dirs"));


BuildResult result = orchestrator.executeBuildQuietly(build); BuildResult result = orchestrator.executeBuildQuietly(build);
assertThat(result.getStatus()).isNotEqualTo(0);
assertThat(result.getStatus()).isNotZero();
// with the following message // with the following message
assertThat(result.getLogs()) assertThat(result.getLogs())
.contains("Invalid value of sonar.sources for bad-source-dirs"); .contains("Invalid value of sonar.sources for bad-source-dirs");


// Note: we can't really check the locale value and the charset because the ones used during the Sonar analysis may not be the ones // Note: we can't really check the locale value and the charset because the ones used during the Sonar analysis may not be the ones
// used to launch the tests. But we can check that the analysis is platform dependent (i.e. "sonar.sourceEncoding" hasn't been set). // used to launch the tests. But we can check that the analysis is platform dependent (i.e. "sonar.sourceEncoding" hasn't been set).
assertThat(log).contains("Default locale:");
assertThat(log).contains(", source code encoding:");
assertThat(log).contains("(analysis is platform dependent)");
assertThat(log).contains("Default locale:")
.contains(", source code encoding:")
.contains("(analysis is platform dependent)");
} }


/** /**
SonarScanner build = newScanner(new File("projects/simple-sample")) SonarScanner build = newScanner(new File("projects/simple-sample"))
.setEnvironmentVariable("SONAR_SCANNER_OPTS", "-Xmx1k"); .setEnvironmentVariable("SONAR_SCANNER_OPTS", "-Xmx1k");
BuildResult executeBuild = orchestrator.executeBuildQuietly(build); BuildResult executeBuild = orchestrator.executeBuildQuietly(build);
assertThat(executeBuild.getLastStatus()).isNotEqualTo(0);
assertThat(executeBuild.getLastStatus()).isNotZero();
String logs = executeBuild.getLogs(); String logs = executeBuild.getLogs();
assertThat(logs).contains("Error occurred during initialization of VM");
// Not the same message with JRE 8 and 11
assertThat(logs).containsPattern("Too small (initial|maximum) heap");
assertThat(logs).contains("Error occurred during initialization of VM")
// Not the same message with JRE 8 and 11
.containsPattern("Too small (initial|maximum) heap");
} }


// SQSCANNER-24 // SQSCANNER-24

Loading…
Cancel
Save