Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Custom file mapping support
  • Loading branch information
viniciusam committed Jul 23, 2017
commit 80ee1f0c4d541e0fd843872954630c548acf3dfd
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,25 @@ db - Database to connect to.
Generates a JSON report providing detailed information on test execution.
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.

-o=output - Defines file name to save the output from the specified reporter.
-o=output - Defines file name to save the output from the specified reporter.
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
-s - Forces putting output to to screen for a given -f parameter.
-s - Forces putting output to to screen for a given -f parameter.
-source_path=source - path to project source files, use the following options to enable custom type mappings:
-owner="app"
-regex_expression="pattern"
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
-owner_subexpression=subexpression_number
-type_subexpression=subexpression_number
-name_subexpression=subexpression_number
-test_path=test - path to project test files, use the following options to enable custom type mappings:
-owner="app"
-regex_expression="pattern"
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
-owner_subexpression=subexpression_number
-type_subexpression=subexpression_number
-name_subexpression=subexpression_number
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards.
Works only on reporeters that support colors (ut_documentation_reporter).
--failure-exit-code - Override the exit code on failure, defaults to 1. You can set it to 0 to always exit with a success status.
Expand Down
145 changes: 103 additions & 42 deletions src/main/java/io/github/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import io.github.utplsql.api.CustomTypes;
import io.github.utplsql.api.OutputBuffer;
import io.github.utplsql.api.TestRunner;
import io.github.utplsql.api.*;
import io.github.utplsql.api.exception.SomeTestsFailedException;
import io.github.utplsql.api.reporter.Reporter;
import io.github.utplsql.api.reporter.ReporterFactory;
Expand Down Expand Up @@ -35,16 +33,15 @@ public class RunCommand {

@Parameter(
names = {"-p", "--path"},
description = "run suites/tests by path, format: \n" +
description = "run suites/tests by path, format: " +
"-p=[schema|schema:[suite ...][.test]|schema[.suite ...][.test]")
private List<String> testPaths = new ArrayList<>();

@Parameter(
names = {"-f", "--format"},
variableArity = true,
description = "output reporter format: \n" +
"enables specified format reporting to specified output file (-o) and to screen (-s)\n" +
"-f=reporter_name [-o=output_file [-s]]")
description = "-f=reporter_name [-o=output_file [-s]] - enables specified format reporting to specified " +
"output file (-o) and to screen (-s)")
private List<String> reporterParams = new ArrayList<>();

@Parameter(
Expand All @@ -57,11 +54,20 @@ public class RunCommand {
description = "override the exit code on failure, default = 1")
private int failureExitCode = 1;

@Parameter(names = {"-source_path"}, description = "path to project source files")
private String sourcePath;
@Parameter(
names = {"-source_path"},
variableArity = true,
description = "-source_path [-owner=\"owner\" -regex_expression=\"pattern\" " +
"-type_mapping=\"matched_string=TYPE/matched_string=TYPE\" " +
"-owner_subexpression=0 -type_subexpression=0 -name_subexpression=0] - path to project source files")
private List<String> sourcePathParams = new ArrayList<>();

@Parameter(names = {"-test_path"}, description = "path to project test files")
private String testPath;
@Parameter(
names = {"-test_path"},
variableArity = true,
description = "-test_path [-regex_expression=\"pattern\" -owner_subexpression=0 -type_subexpression=0 " +
"-name_subexpression=0] - path to project test files")
private List<String> testPathParams = new ArrayList<>();

public ConnectionInfo getConnectionInfo() {
return connectionInfoList.get(0);
Expand All @@ -71,33 +77,6 @@ public List<String> getTestPaths() {
return testPaths;
}

public List<ReporterOptions> getReporterOptionsList() {
List<ReporterOptions> reporterOptionsList = new ArrayList<>();
ReporterOptions reporterOptions = null;

for (String p : reporterParams) {
if (reporterOptions == null || !p.startsWith("-")) {
reporterOptions = new ReporterOptions(p);
reporterOptionsList.add(reporterOptions);
}
else
if (p.startsWith("-o=")) {
reporterOptions.setOutputFileName(p.substring(3));
}
else
if (p.equals("-s")) {
reporterOptions.forceOutputToScreen(true);
}
}

// If no reporter parameters were passed, use default reporter.
if (reporterOptionsList.isEmpty()) {
reporterOptionsList.add(new ReporterOptions(CustomTypes.UT_DOCUMENTATION_REPORTER));
}

return reporterOptionsList;
}

public int run() throws Exception {
final ConnectionInfo ci = getConnectionInfo();

Expand All @@ -108,15 +87,25 @@ public int run() throws Exception {
final File baseDir = new File("").getAbsoluteFile();
List<String> sourceFilesTmp = null;
List<String> testFilesTmp = null;
FileMapperOptions sourceMappingOptionsTmp= null;
FileMapperOptions testMappingOptionsTmp = null;

if (this.sourcePath != null)
sourceFilesTmp = new FileWalker().getFileList(baseDir, this.sourcePath);
if (!this.sourcePathParams.isEmpty()) {
String sourcePath = this.sourcePathParams.get(0);
sourceFilesTmp = new FileWalker().getFileList(baseDir, sourcePath);
sourceMappingOptionsTmp = getMapperOptions(this.sourcePathParams);
}

if (this.testPath != null)
testFilesTmp = new FileWalker().getFileList(baseDir, this.testPath);
if (!this.testPathParams.isEmpty()) {
String testPath = this.testPathParams.get(0);
testFilesTmp = new FileWalker().getFileList(baseDir, testPath);
testMappingOptionsTmp = getMapperOptions(this.testPathParams);
}

final List<String> sourceFiles = sourceFilesTmp;
final List<String> testFiles = testFilesTmp;
final FileMapperOptions sourceMappingOptions = sourceMappingOptionsTmp;
final FileMapperOptions testMappingOptions = testMappingOptionsTmp;
final int[] returnCode = {0};

if (testPaths.isEmpty()) testPaths.add(ci.getUser());
Expand All @@ -143,7 +132,9 @@ public int run() throws Exception {
.addPathList(testPaths)
.addReporterList(reporterList)
.withSourceFiles(sourceFiles)
.sourceMappingOptions(sourceMappingOptions)
.withTestFiles(testFiles)
.testMappingOptions(testMappingOptions)
.colorConsole(this.colorConsole)
.failOnErrors(true)
.run(conn);
Expand Down Expand Up @@ -187,4 +178,74 @@ public int run() throws Exception {
return returnCode[0];
}

public List<ReporterOptions> getReporterOptionsList() {
List<ReporterOptions> reporterOptionsList = new ArrayList<>();
ReporterOptions reporterOptions = null;

for (String p : reporterParams) {
if (reporterOptions == null || !p.startsWith("-")) {
reporterOptions = new ReporterOptions(p);
reporterOptionsList.add(reporterOptions);
}
else
if (p.startsWith("-o=")) {
reporterOptions.setOutputFileName(p.substring(3));
}
else
if (p.equals("-s")) {
reporterOptions.forceOutputToScreen(true);
}
}

// If no reporter parameters were passed, use default reporter.
if (reporterOptionsList.isEmpty()) {
reporterOptionsList.add(new ReporterOptions(CustomTypes.UT_DOCUMENTATION_REPORTER));
}

return reporterOptionsList;
}

public FileMapperOptions getMapperOptions(List<String> mappingParams) {
FileMapperOptions mapperOptions = new FileMapperOptions();

for (String p : mappingParams) {
if (p.startsWith("-object_owner=")) {
mapperOptions.setObjectOwner(p.substring("-object_owner=".length()));
}
else
if (p.startsWith("-regex_pattern=")) {
mapperOptions.setRegexPattern(p.substring("-regex_pattern=".length()));
}
else
if (p.startsWith("-type_mapping=")) {
String typeMappingsParam = p.substring("-type_mapping=".length());

List<KeyValuePair> typeMappings = new ArrayList<>();
for (String mapping : typeMappingsParam.split("/")) {
String[] values = mapping.split("=");
typeMappings.add(new KeyValuePair(values[0], values[1]));
}

mapperOptions.setTypeMappings(typeMappings);
}
else
if (p.startsWith("-owner_subexpression=")) {
mapperOptions.setOwnerSubExpression(Integer.parseInt(p.substring("-owner_subexpression=".length())));
}
else
if (p.startsWith("-name_subexpression=")) {
mapperOptions.setNameSubExpression(Integer.parseInt(p.substring("-name_subexpression=".length())));
}
else
if (p.startsWith("-type_subexpression=")) {
mapperOptions.setTypeSubExpression(Integer.parseInt(p.substring("-type_subexpression=".length())));
}
}

if (mapperOptions.getRegexPattern() == null || mapperOptions.getRegexPattern().isEmpty())
return null;
else
return mapperOptions;
}

}