Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import jenkins.model.Jenkins;
import jenkins.tasks.SimpleBuildStep;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
Expand Down Expand Up @@ -68,13 +67,13 @@ public VsTestBuilder() {
}

protected Object readResolve() {
if (StringUtils.isNotBlank((otherPlatform))) {
if (!isBlank(otherPlatform)) {
this.platform = otherPlatform;
}
if (StringUtils.isNotBlank(otherFramework)) {
if (!isBlank(otherFramework)) {
this.framework = otherFramework;
}
if (StringUtils.isNotBlank(otherLogger)) {
if (!isBlank(otherLogger)) {
this.logger = otherLogger;
}
return this;
Expand Down Expand Up @@ -313,7 +312,7 @@ public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNul
args.add(pathToVsTest);

// Target dll path
if (!StringUtils.isBlank(testFiles)) {
if (!isBlank(testFiles)) {
List<String> targets = getTestFilesArguments(workspace, env);
if (targets.size() == 0) {
listener.getLogger().println("no files matching the pattern " + this.testFiles);
Expand All @@ -326,17 +325,17 @@ public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNul
}

// Run tests with additional settings such as data collectors.
if (!StringUtils.isBlank(settings)) {
if (!isBlank(settings)) {
args.add(convertArgumentWithQuote("Settings", replaceMacro(settings, env)));
}

// Run tests with names that match the provided values.
if (!StringUtils.isBlank(tests)) {
if (!isBlank(tests)) {
args.add(convertArgument("Tests", replaceMacro(tests, env)));
}

// Run tests that match the given expression.
if (!StringUtils.isBlank(testCaseFilter)) {
if (!isBlank(testCaseFilter)) {
args.add(convertArgumentWithQuote("TestCaseFilter", replaceMacro(testCaseFilter, env)));
}

Expand All @@ -361,24 +360,24 @@ public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNul

// Target platform architecture to be used for test execution.
String platformArg = getPlatformArgument(env);
if (!StringUtils.isBlank(platformArg)) {
if (!isBlank(platformArg)) {
args.add(convertArgument("Platform", platformArg));
}

// Target .NET Framework version to be used for test execution.
String frameworkArg = getFrameworkArgument(env);
if (!StringUtils.isBlank(frameworkArg)) {
if (!isBlank(frameworkArg)) {
args.add(convertArgument("Framework", frameworkArg));
}

// Specify a logger for test results.
String loggerArg = getLoggerArgument(env);
if (!StringUtils.isBlank(loggerArg)) {
if (!isBlank(loggerArg)) {
args.add(convertArgument("Logger", loggerArg));
}

// Manual Command Line String
if (!StringUtils.isBlank(cmdLineArgs)) {
if (!isBlank(cmdLineArgs)) {
args.add(replaceMacro(cmdLineArgs, env));
}

Expand Down Expand Up @@ -440,7 +439,7 @@ private String getVsTestPath(Node builtOn, TaskListener listener, EnvVars env) {
String testFile = testFilesTokenizer.nextToken();
testFile = replaceMacro(testFile, env);

if (!StringUtils.isBlank(testFile)) {
if (!isBlank(testFile)) {
try {
for (FilePath filePath : workspace.list(testFile)) {
files.add(appendQuote(relativize(workspace, filePath)));
Expand All @@ -467,7 +466,26 @@ private String getPlatformArgument(EnvVars env) {
*/
private String getFrameworkArgument(EnvVars env) {
String expanded = replaceMacro(framework, env);
return useVs2017Plus ? StringUtils.capitalize(expanded) : expanded;
return useVs2017Plus ? capitalize(expanded) : expanded;
}

/* package */ static boolean isBlank(String value) {
if (value == null || value.length() == 0) {
return true;
}
for (int i = 0; i < value.length(); i++) {
if (!Character.isWhitespace(value.charAt(i))) {
return false;
}
}
return true;
}

/* package */ static String capitalize(String value) {
if (value == null || value.length() == 0) {
return value;
}
return Character.toTitleCase(value.charAt(0)) + value.substring(1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import java.io.File;
import java.util.List;
import org.apache.commons.lang.StringUtils;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -57,9 +56,8 @@ public void testGetTestFilesArgument() throws Exception {
EnvVars envVars = new EnvVars();
List<String> testFilesArguments = step.getTestFilesArguments(workspace, envVars);
assertThat(testFilesArguments.size(), is(1));
String trimmedPath = StringUtils.strip(testFilesArguments.get(0), "\"");
String expected = StringUtils.strip(step.relativize(workspace, absolutePath), "\"");
assertThat(trimmedPath, is(expected));
String expected = "\"" + step.relativize(workspace, absolutePath) + "\"";
assertThat(testFilesArguments.get(0), is(expected));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jenkinsci.plugins.vstest_runner;

import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

public class VsTestBuilderTest {

@Test
public void detectsBlankValues() {
assertThat(VsTestBuilder.isBlank(null), is(true));
assertThat(VsTestBuilder.isBlank(""), is(true));
assertThat(VsTestBuilder.isBlank(" \t\r\n"), is(true));
assertThat(VsTestBuilder.isBlank(" value "), is(false));
}

@Test
public void capitalizesFirstCharacter() {
assertThat(VsTestBuilder.capitalize(null), nullValue());
assertThat(VsTestBuilder.capitalize(""), is(""));
assertThat(VsTestBuilder.capitalize("framework45"), is("Framework45"));
assertThat(VsTestBuilder.capitalize("Framework45"), is("Framework45"));
}
}
Loading