-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from utPLSQL/feature/include-exclude-params
Added include and exclude params for coverage reports (dup for issue #6)
- Loading branch information
Showing
7 changed files
with
212 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/test/java/org/utplsql/cli/RunCommandCoverageReporterSystemTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.utplsql.cli; | ||
|
||
import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.utplsql.api.compatibility.OptionalFeatures; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Scanner; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* System tests for Code Coverage Reporter | ||
* | ||
* @author pesse | ||
*/ | ||
public class RunCommandCoverageReporterSystemTest { | ||
|
||
private static final Pattern REGEX_COVERAGE_TITLE = Pattern.compile("<a href=\"[a-zA-Z0-9#]+\" class=\"src_link\" title=\"[a-zA-Z\\._]+\">([a-zA-Z0-9\\._]+)<\\/a>"); | ||
|
||
private String getTempCoverageFileName(int counter) { | ||
|
||
return "tmpCoverage_" + String.valueOf(System.currentTimeMillis()) + "_" + String.valueOf(counter) + ".html"; | ||
} | ||
|
||
/** | ||
* Returns a random filename which does not yet exist on the local path | ||
* | ||
* @return | ||
*/ | ||
private Path getTempCoverageFilePath() { | ||
int i = 1; | ||
Path p = Paths.get(getTempCoverageFileName(i)); | ||
|
||
while (Files.exists(p) && i < 100) | ||
p = Paths.get(getTempCoverageFileName(i++)); | ||
|
||
if (i >= 100) | ||
throw new IllegalStateException("Could not get temporary file for coverage output"); | ||
|
||
return p; | ||
} | ||
|
||
/** Checks Coverage HTML Output if a given packageName is listed | ||
* | ||
* @param content | ||
* @param packageName | ||
* @return | ||
*/ | ||
private boolean hasCoverageListed( String content, String packageName) { | ||
Matcher m = REGEX_COVERAGE_TITLE.matcher(content); | ||
|
||
while ( m.find() ) { | ||
if ( packageName.equals(m.group(1)) ) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Test | ||
public void run_CodeCoverageWithIncludeAndExclude() { | ||
|
||
try { | ||
Path coveragePath = getTempCoverageFilePath(); | ||
|
||
RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), | ||
"-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s", "-exclude=app.award_bonus,app.betwnstr"); | ||
|
||
try { | ||
int result = runCmd.run(); | ||
|
||
String content = new Scanner(coveragePath).useDelimiter("\\Z").next(); | ||
|
||
Assert.assertEquals(true, hasCoverageListed(content, "app.remove_rooms_by_name")); | ||
Assert.assertEquals(false, hasCoverageListed(content, "app.award_bonus")); | ||
Assert.assertEquals(false, hasCoverageListed(content, "app.betwnstr")); | ||
|
||
} finally { | ||
Files.delete(coveragePath); | ||
} | ||
} catch (Exception e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.utplsql.cli; | ||
|
||
import com.beust.jcommander.JCommander; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.utplsql.api.CustomTypes; | ||
import org.utplsql.api.compatibility.OptionalFeatures; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* System tests for run command. | ||
*/ | ||
public class RunCommandSystemTest { | ||
|
||
|
||
@Test | ||
public void run_Default() { | ||
RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), | ||
"-f=ut_documentation_reporter", | ||
"-c", | ||
"--failure-exit-code=2"); | ||
|
||
try { | ||
int result = runCmd.run(); | ||
|
||
// Only expect failure-exit-code to work on several framework versions | ||
if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(runCmd.getDatabaseVersion()) ) | ||
Assert.assertEquals(2, result); | ||
else | ||
Assert.assertEquals(0, result); | ||
} | ||
catch ( Exception e ) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.utplsql.cli; | ||
|
||
import com.beust.jcommander.JCommander; | ||
|
||
class RunCommandTestHelper { | ||
private static String sUrl; | ||
private static String sUser; | ||
private static String sPass; | ||
|
||
static { | ||
sUrl = System.getenv("DB_URL") != null ? System.getenv("DB_URL") : "192.168.99.100:1521:XE"; | ||
sUser = System.getenv("DB_USER") != null ? System.getenv("DB_USER") : "app"; | ||
sPass = System.getenv("DB_PASS") != null ? System.getenv("DB_PASS") : "app"; | ||
} | ||
|
||
static RunCommand createRunCommand(String... args) { | ||
RunCommand runCmd = new RunCommand(); | ||
|
||
JCommander.newBuilder() | ||
.addObject(runCmd) | ||
.args(args) | ||
.build(); | ||
|
||
return runCmd; | ||
} | ||
|
||
static String getConnectionString() { | ||
return sUser + "/" + sPass + "@" + sUrl; | ||
} | ||
} |