Skip to content

Commit

Permalink
[#1932] Use System Rules for Java 5-7, and use System Lambda for Java 8+
Browse files Browse the repository at this point in the history
* System.exit tests
* Environment variable tests
  • Loading branch information
remkop committed Feb 5, 2023
1 parent 95d1087 commit 8c9ba91
Show file tree
Hide file tree
Showing 11 changed files with 3,453 additions and 965 deletions.
10 changes: 4 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,10 @@ allprojects {
testImplementation supportDependencies.jansi
testImplementation supportDependencies.groovy

if (!project.name in ['picocli-tests-java8plus']) {
testImplementation supportDependencies.junit
testImplementation supportDependencies.hamcrestCore
testImplementation supportDependencies.systemRules
testImplementation supportDependencies.junitParams
}
testImplementation supportDependencies.junit
testImplementation supportDependencies.hamcrestCore
testImplementation supportDependencies.systemRules
testImplementation supportDependencies.junitParams
}
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation'
Expand Down
8 changes: 8 additions & 0 deletions gradle/release-tasks.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ task gatherArtifacts(type: Copy) {

/*
Release procedure:
0. Run tests in Java 5:
cmd
cd picocli-tests-java567
: now build the project with Java 5, 6 and 7
set JAVA_HOME=C:\apps\jdk1.5.0_22
gradlew clean build --no-daemon
1. edit version numbers in dependencies.gradle: remove -SNAPSHOT classifier; edit releaseDate
2. ./gradlew bumpVersion
3. check modified files
Expand Down
2 changes: 1 addition & 1 deletion picocli-tests-java567/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ If you have multiple versions of Java installed, then before running this build,
: (on Windows)
: start command prompt if we are running in Powershell
cmd
cd picocli-legacy-tests
cd picocli-tests-java567
: now build the project with Java 5, 6 and 7
set JAVA_HOME=C:\apps\jdk1.5.0_22
Expand Down
2 changes: 1 addition & 1 deletion picocli-tests-java567/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"

sourceSets.main.java.srcDirs = ['../src/main/java']
sourceSets.test.java.srcDirs = ['../src/test/java']
sourceSets.test.java.srcDirs += ['../src/test/java']
sourceSets.test.resources.srcDirs = ['../src/test/resources']
sourceSets {
test {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package picocli;

import java.util.ListResourceBundle;

/**
* Resource bundle for DefaultProviderTest#testDefaultValueProviderWithVariablesResolvesResourceBundle
*/
public class DefaultProviderEnvironmentTestBundle extends ListResourceBundle {
protected Object[][] getContents() {
return new Object[][] {
// KEY VALUE PAIRS
{"VARIABLE", "789"},
// END OF MATERIAL TO LOCALIZE
};
}
}
1,060 changes: 1,060 additions & 0 deletions picocli-tests-java567/src/test/java/picocli/HelpAnsiEnvironmentTest.java

Large diffs are not rendered by default.

Large diffs are not rendered by default.

967 changes: 52 additions & 915 deletions src/test/java/picocli/AutoCompleteTest.java

Large diffs are not rendered by default.

42 changes: 0 additions & 42 deletions src/test/java/picocli/DefaultProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.junit.contrib.java.lang.system.ProvideSystemProperty;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.rules.TestRule;
Expand All @@ -16,7 +15,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListResourceBundle;
import java.util.Properties;

import static org.junit.Assert.*;
Expand All @@ -30,9 +28,6 @@ public class DefaultProviderTest {
@Rule
public final ProvideSystemProperty ansiOFF = new ProvideSystemProperty("picocli.ansi", "false");

@Rule
public final EnvironmentVariables envVars = new EnvironmentVariables();

static class TestDefaultProvider implements IDefaultValueProvider {
public String defaultValue(ArgSpec argSpec) {
return "Default provider string value";
Expand Down Expand Up @@ -416,31 +411,6 @@ class App {
assertEquals(123, app1.a);
}

@Test
public void testDefaultValueProviderWithVariablesPrefersSystemPropertyOverEnvVars() {
@Command(defaultValueProvider = DefaultProviderWithVariables.class)
class App {
@Option(names = "-a")
int a;
}
System.setProperty("VARIABLE", "123");
envVars.set("VARIABLE", "456");
App app1 = CommandLine.populateCommand(new App());
assertEquals(123, app1.a);
}

@Test
public void testDefaultValueProviderWithVariablesResolvesEnvironmentVariable() {
@Command(defaultValueProvider = DefaultProviderWithVariables.class)
class App {
@Option(names = "-a")
int a;
}
envVars.set("VARIABLE", "456");
App app1 = CommandLine.populateCommand(new App());
assertEquals(456, app1.a);
}

@Test
public void testDefaultValueProviderWithVariablesResolvesResourceBundle() {
@Command(defaultValueProvider = DefaultProviderWithVariables.class,
Expand All @@ -466,16 +436,4 @@ class App {
assertEquals(123, app1.a);
}

@Test
public void testDefaultValueProviderWithVariablesPrefersEnvVarsOverResourceBundle() {
@Command(defaultValueProvider = DefaultProviderWithVariables.class,
resourceBundle = "picocli.DefaultProviderTestBundle")
class App {
@Option(names = "-a")
int a;
}
envVars.set("VARIABLE", "456");
App app1 = CommandLine.populateCommand(new App());
assertEquals(456, app1.a);
}
}

0 comments on commit 8c9ba91

Please sign in to comment.