diff --git a/README.md b/README.md index f4626ed..07addd8 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index 69dfa89..72ec9fb 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -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; @@ -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 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 reporterParams = new ArrayList<>(); @Parameter( @@ -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 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 testPathParams = new ArrayList<>(); public ConnectionInfo getConnectionInfo() { return connectionInfoList.get(0); @@ -71,33 +77,6 @@ public List getTestPaths() { return testPaths; } - public List getReporterOptionsList() { - List 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(); @@ -106,18 +85,22 @@ public int run() throws Exception { final List reporterList = new ArrayList<>(); final File baseDir = new File("").getAbsoluteFile(); - List sourceFilesTmp = null; - List testFilesTmp = null; + final FileMapperOptions[] sourceMappingOptions = {null}; + final FileMapperOptions[] testMappingOptions = {null}; - if (this.sourcePath != null) - sourceFilesTmp = new FileWalker().getFileList(baseDir, this.sourcePath); + final int[] returnCode = {0}; - if (this.testPath != null) - testFilesTmp = new FileWalker().getFileList(baseDir, this.testPath); + if (!this.sourcePathParams.isEmpty()) { + String sourcePath = this.sourcePathParams.get(0); + List sourceFiles = new FileWalker().getFileList(baseDir, sourcePath); + sourceMappingOptions[0] = getMapperOptions(this.sourcePathParams, sourceFiles); + } - final List sourceFiles = sourceFilesTmp; - final List testFiles = testFilesTmp; - final int[] returnCode = {0}; + if (!this.testPathParams.isEmpty()) { + String testPath = this.testPathParams.get(0); + List testFiles = new FileWalker().getFileList(baseDir, testPath); + testMappingOptions[0] = getMapperOptions(this.testPathParams, testFiles); + } if (testPaths.isEmpty()) testPaths.add(ci.getUser()); @@ -142,8 +125,8 @@ public int run() throws Exception { new TestRunner() .addPathList(testPaths) .addReporterList(reporterList) - .withSourceFiles(sourceFiles) - .withTestFiles(testFiles) + .sourceMappingOptions(sourceMappingOptions[0]) + .testMappingOptions(testMappingOptions[0]) .colorConsole(this.colorConsole) .failOnErrors(true) .run(conn); @@ -187,4 +170,74 @@ public int run() throws Exception { return returnCode[0]; } + public List getReporterOptionsList() { + List 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 mappingParams, List filePaths) { + FileMapperOptions mapperOptions = new FileMapperOptions(filePaths); + + 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 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; + } + }