mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
[build] Apply spotless for java formatting (#1768)
Update checkstyle config to be compatible with spotless. Co-authored-by: Austin Shalit <austinshalit@gmail.com>
This commit is contained in:
@@ -4,20 +4,18 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.test;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.MultipleFailureException;
|
||||
|
||||
import edu.wpi.first.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.DriverStation;
|
||||
import edu.wpi.first.wpilibj.MockDS;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.MultipleFailureException;
|
||||
|
||||
/**
|
||||
* This class serves as a superclass for all tests that involve the hardware on the roboRIO. It uses
|
||||
@@ -26,19 +24,16 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
* to run.
|
||||
*/
|
||||
public abstract class AbstractComsSetup {
|
||||
/**
|
||||
* Stores whether network coms have been initialized.
|
||||
*/
|
||||
/** Stores whether network coms have been initialized. */
|
||||
private static boolean initialized = false;
|
||||
|
||||
// We have no way to stop the MockDS, so its thread is daemon.
|
||||
private static MockDS ds;
|
||||
private static MockDS ds;
|
||||
|
||||
/**
|
||||
* This sets up the network communications library to enable the driver
|
||||
* station. After starting network coms, it will loop until the driver station
|
||||
* returns that the robot is enabled, to ensure that tests will be able to run
|
||||
* on the hardware.
|
||||
* This sets up the network communications library to enable the driver station. After starting
|
||||
* network coms, it will loop until the driver station returns that the robot is enabled, to
|
||||
* ensure that tests will be able to run on the hardware.
|
||||
*/
|
||||
static {
|
||||
if (!initialized) {
|
||||
@@ -83,12 +78,9 @@ public abstract class AbstractComsSetup {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected abstract Logger getClassLogger();
|
||||
|
||||
/**
|
||||
* This causes a stack trace to be printed as the test is running as well as at the end.
|
||||
*/
|
||||
/** This causes a stack trace to be printed as the test is running as well as at the end. */
|
||||
@Rule
|
||||
public final TestWatcher getTestWatcher() {
|
||||
return getOverridenTestWatcher();
|
||||
@@ -121,19 +113,32 @@ public abstract class AbstractComsSetup {
|
||||
int exceptionCount = 1; // Running exception count
|
||||
int failureCount = ((MultipleFailureException) throwable).getFailures().size();
|
||||
for (Throwable singleThrown : ((MultipleFailureException) throwable).getFailures()) {
|
||||
getClassLogger().logp(
|
||||
Level.SEVERE,
|
||||
description.getClassName(),
|
||||
description.getMethodName(),
|
||||
(exceptionCount++) + "/" + failureCount + " " + description.getDisplayName() + " "
|
||||
+ "failed " + singleThrown.getMessage() + "\n" + status, singleThrown);
|
||||
getClassLogger()
|
||||
.logp(
|
||||
Level.SEVERE,
|
||||
description.getClassName(),
|
||||
description.getMethodName(),
|
||||
(exceptionCount++)
|
||||
+ "/"
|
||||
+ failureCount
|
||||
+ " "
|
||||
+ description.getDisplayName()
|
||||
+ " "
|
||||
+ "failed "
|
||||
+ singleThrown.getMessage()
|
||||
+ "\n"
|
||||
+ status,
|
||||
singleThrown);
|
||||
}
|
||||
|
||||
} else {
|
||||
getClassLogger().logp(Level.SEVERE, description.getClassName(),
|
||||
description.getMethodName(),
|
||||
description.getDisplayName() + " failed " + throwable.getMessage() + "\n" + status,
|
||||
throwable);
|
||||
getClassLogger()
|
||||
.logp(
|
||||
Level.SEVERE,
|
||||
description.getClassName(),
|
||||
description.getMethodName(),
|
||||
description.getDisplayName() + " failed " + throwable.getMessage() + "\n" + status,
|
||||
throwable);
|
||||
}
|
||||
super.failed(throwable, description);
|
||||
}
|
||||
@@ -149,7 +154,6 @@ public abstract class AbstractComsSetup {
|
||||
failed(exception, description, "");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
@@ -169,8 +173,8 @@ public abstract class AbstractComsSetup {
|
||||
// Prints the message on one line overwriting itself each time
|
||||
TestBench.out().print("\rWaiting for enable: " + enableCounter++);
|
||||
}
|
||||
getClassLogger().logp(Level.INFO, description.getClassName(), description.getMethodName(),
|
||||
"Starting");
|
||||
getClassLogger()
|
||||
.logp(Level.INFO, description.getClassName(), description.getMethodName(), "Starting");
|
||||
super.starting(description);
|
||||
}
|
||||
|
||||
@@ -179,13 +183,12 @@ public abstract class AbstractComsSetup {
|
||||
simpleLog(Level.INFO, "TEST PASSED!");
|
||||
super.succeeded(description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a simple message without the logger formatting associated with it.
|
||||
*
|
||||
* @param level The level to log the message at
|
||||
* @param level The level to log the message at
|
||||
* @param message The message to log
|
||||
*/
|
||||
protected void simpleLog(Level level, String message) {
|
||||
@@ -199,8 +202,7 @@ public abstract class AbstractComsSetup {
|
||||
* correct state is reached.
|
||||
*/
|
||||
public abstract class BooleanCheck {
|
||||
public BooleanCheck() {
|
||||
}
|
||||
public BooleanCheck() {}
|
||||
|
||||
/**
|
||||
* Runs the enclosed code and evaluates it to determine what state it should return.
|
||||
@@ -213,22 +215,23 @@ public abstract class AbstractComsSetup {
|
||||
/**
|
||||
* Delays until either the correct state is reached or we reach the timeout.
|
||||
*
|
||||
* @param level The level to log the message at.
|
||||
* @param timeout How long the delay should run before it should timeout and allow the test
|
||||
* to continue
|
||||
* @param message The message to accompany the delay. The message will display 'message' took
|
||||
* 'timeout' seconds if it passed.
|
||||
* @param level The level to log the message at.
|
||||
* @param timeout How long the delay should run before it should timeout and allow the test to
|
||||
* continue
|
||||
* @param message The message to accompany the delay. The message will display 'message' took
|
||||
* 'timeout' seconds if it passed.
|
||||
* @param correctState A method to determine if the test has reached a state where it is valid to
|
||||
* continue
|
||||
* continue
|
||||
* @return a double representing how long the delay took to run in seconds.
|
||||
*/
|
||||
public double delayTillInCorrectStateWithMessage(Level level, double timeout, String message,
|
||||
BooleanCheck correctState) {
|
||||
public double delayTillInCorrectStateWithMessage(
|
||||
Level level, double timeout, String message, BooleanCheck correctState) {
|
||||
int timeoutIndex;
|
||||
// As long as we are not in the correct state and the timeout has not been
|
||||
// reached then continue to run this loop
|
||||
for (timeoutIndex = 0; timeoutIndex < (timeout * 100) && !correctState.getAsBoolean();
|
||||
timeoutIndex++) {
|
||||
for (timeoutIndex = 0;
|
||||
timeoutIndex < (timeout * 100) && !correctState.getAsBoolean();
|
||||
timeoutIndex++) {
|
||||
Timer.delay(0.01);
|
||||
}
|
||||
if (correctState.getAsBoolean()) {
|
||||
@@ -238,5 +241,4 @@ public abstract class AbstractComsSetup {
|
||||
}
|
||||
return timeoutIndex * 0.01;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.Request;
|
||||
@@ -37,8 +36,8 @@ public abstract class AbstractTestSuite {
|
||||
SuiteClasses annotation = getClass().getAnnotation(SuiteClasses.class);
|
||||
List<Class<?>> classes = new ArrayList<>();
|
||||
if (annotation == null) {
|
||||
throw new RuntimeException(String.format("class '%s' must have a SuiteClasses annotation",
|
||||
getClass().getName()));
|
||||
throw new RuntimeException(
|
||||
String.format("class '%s' must have a SuiteClasses annotation", getClass().getName()));
|
||||
}
|
||||
for (Class<?> c : annotation.value()) {
|
||||
classes.add(c);
|
||||
@@ -81,7 +80,8 @@ public abstract class AbstractTestSuite {
|
||||
for (Method m : c.getMethods()) {
|
||||
// If this is a test method that is not trying to be ignored and it
|
||||
// matches the regex
|
||||
if (m.getAnnotation(Test.class) != null && m.getAnnotation(Ignore.class) == null
|
||||
if (m.getAnnotation(Test.class) != null
|
||||
&& m.getAnnotation(Ignore.class) == null
|
||||
&& Pattern.matches(regex, m.getName())) {
|
||||
ClassMethodPair pair = new ClassMethodPair(c, m);
|
||||
classMethodPairs.add(pair);
|
||||
@@ -91,7 +91,6 @@ public abstract class AbstractTestSuite {
|
||||
return classMethodPairs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets all of the test classes listed in this suite. Does not include any of the test suites. All
|
||||
* of these classes contain tests.
|
||||
@@ -109,16 +108,20 @@ public abstract class AbstractTestSuite {
|
||||
// Add the tests from this suite that match the regex to the list of
|
||||
// tests to run
|
||||
runningList = suite.getAllContainedBaseTests(runningList);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
|
||||
} catch (NoSuchMethodException
|
||||
| InvocationTargetException
|
||||
| InstantiationException
|
||||
| IllegalAccessException ex) {
|
||||
// This shouldn't happen unless the constructor is changed in some
|
||||
// way.
|
||||
logger.log(Level.SEVERE, "Test suites can not take parameters in their constructors.",
|
||||
ex);
|
||||
logger.log(
|
||||
Level.SEVERE, "Test suites can not take parameters in their constructors.", ex);
|
||||
}
|
||||
} else if (c.getAnnotation(SuiteClasses.class) != null) {
|
||||
logger.log(Level.SEVERE,
|
||||
String.format("class '%s' must extend %s to be searchable using regex.",
|
||||
logger.log(
|
||||
Level.SEVERE,
|
||||
String.format(
|
||||
"class '%s' must extend %s to be searchable using regex.",
|
||||
c.getName(), AbstractTestSuite.class.getName()));
|
||||
} else { // This is a class containing tests
|
||||
// so add it to the list
|
||||
@@ -139,12 +142,11 @@ public abstract class AbstractTestSuite {
|
||||
return getAllContainedBaseTests(runningBaseTests);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves all of the classes listed in the <code>@SuiteClasses</code> annotation that match the
|
||||
* given regex text.
|
||||
*
|
||||
* @param regex the text pattern to retrieve.
|
||||
* @param regex the text pattern to retrieve.
|
||||
* @param runningList the running list of classes to prevent recursion
|
||||
* @return The list of classes matching the regex pattern
|
||||
*/
|
||||
@@ -178,12 +180,11 @@ public abstract class AbstractTestSuite {
|
||||
* @param regex the regex text to search for
|
||||
* @return the list of suite and/or test classes matching the regex.
|
||||
*/
|
||||
private List<Class<?>> getSuiteOrTestMatchingRegex(final String regex, List<Class<?>>
|
||||
runningList) {
|
||||
private List<Class<?>> getSuiteOrTestMatchingRegex(
|
||||
final String regex, List<Class<?>> runningList) {
|
||||
// Get any test suites matching the regex using the superclass methods
|
||||
runningList = getAllClassMatching(regex, runningList);
|
||||
|
||||
|
||||
// Then search any test suites not retrieved already for test classes
|
||||
// matching the regex.
|
||||
List<Class<?>> unCollectedSuites = getAllClasses();
|
||||
@@ -205,12 +206,14 @@ public abstract class AbstractTestSuite {
|
||||
runningList = suite.getSuiteOrTestMatchingRegex(regex, runningList);
|
||||
}
|
||||
|
||||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
|
||||
} catch (NoSuchMethodException
|
||||
| InvocationTargetException
|
||||
| InstantiationException
|
||||
| IllegalAccessException ex) {
|
||||
// This shouldn't happen unless the constructor is changed in some
|
||||
// way.
|
||||
logger.log(Level.SEVERE, "Test suites can not take parameters in their constructors.",
|
||||
ex);
|
||||
logger.log(
|
||||
Level.SEVERE, "Test suites can not take parameters in their constructors.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,7 +233,6 @@ public abstract class AbstractTestSuite {
|
||||
return getSuiteOrTestMatchingRegex(regex, matchingClasses);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves all of the classes listed in the <code>@SuiteClasses</code> annotation.
|
||||
*
|
||||
|
||||
@@ -4,8 +4,13 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.test;
|
||||
|
||||
import java.util.List;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import edu.wpi.first.wpilibj.test.AbstractTestSuite.ClassMethodPair;
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -13,13 +18,6 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
import edu.wpi.first.wpilibj.test.AbstractTestSuite.ClassMethodPair;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Yes, this is the test system testing itself. Functionally, this is making sure that all tests get
|
||||
* run correctly when you use parametrized arguments.
|
||||
@@ -28,10 +26,16 @@ import static org.junit.Assert.assertEquals;
|
||||
public class AbstractTestSuiteTest {
|
||||
@Ignore("Prevents ANT from trying to run these as tests")
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({FirstSampleTest.class, SecondSampleTest.class, ThirdSampleTest.class,
|
||||
FourthSampleTest.class, UnusualTest.class, ExampleSubSuite.class, EmptySuite.class})
|
||||
class TestForAbstractTestSuite extends AbstractTestSuite {
|
||||
}
|
||||
@SuiteClasses({
|
||||
FirstSampleTest.class,
|
||||
SecondSampleTest.class,
|
||||
ThirdSampleTest.class,
|
||||
FourthSampleTest.class,
|
||||
UnusualTest.class,
|
||||
ExampleSubSuite.class,
|
||||
EmptySuite.class
|
||||
})
|
||||
class TestForAbstractTestSuite extends AbstractTestSuite {}
|
||||
|
||||
TestForAbstractTestSuite m_testSuite;
|
||||
|
||||
@@ -79,10 +83,11 @@ public class AbstractTestSuiteTest {
|
||||
List<Class<?>> collectedTests = m_testSuite.getSuiteOrTestMatchingRegex(".*Test.*");
|
||||
// then
|
||||
assertEquals(7, collectedTests.size());
|
||||
assertThat(collectedTests, hasItems(FirstSubSuiteTest.class,
|
||||
SecondSubSuiteTest.class, UnusualTest.class));
|
||||
assertThat(collectedTests,
|
||||
not(hasItems(new Class<?>[]{ExampleSubSuite.class, EmptySuite.class})));
|
||||
assertThat(
|
||||
collectedTests,
|
||||
hasItems(FirstSubSuiteTest.class, SecondSubSuiteTest.class, UnusualTest.class));
|
||||
assertThat(
|
||||
collectedTests, not(hasItems(new Class<?>[] {ExampleSubSuite.class, EmptySuite.class})));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,31 +98,23 @@ public class AbstractTestSuiteTest {
|
||||
assertEquals(1, pairs.size());
|
||||
assertEquals(FirstSubSuiteTest.class, pairs.get(0).m_methodClass);
|
||||
assertEquals(FirstSubSuiteTest.METHODNAME, pairs.get(0).m_methodName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("OneTopLevelClass")
|
||||
class FirstSampleTest {
|
||||
}
|
||||
class FirstSampleTest {}
|
||||
|
||||
@SuppressWarnings("OneTopLevelClass")
|
||||
class SecondSampleTest {
|
||||
}
|
||||
class SecondSampleTest {}
|
||||
|
||||
@SuppressWarnings("OneTopLevelClass")
|
||||
class ThirdSampleTest {
|
||||
}
|
||||
class ThirdSampleTest {}
|
||||
|
||||
@SuppressWarnings("OneTopLevelClass")
|
||||
class FourthSampleTest {
|
||||
}
|
||||
class FourthSampleTest {}
|
||||
|
||||
@SuppressWarnings("OneTopLevelClass")
|
||||
class UnusualTest {
|
||||
} // This is a member of both suites
|
||||
|
||||
class UnusualTest {} // This is a member of both suites
|
||||
|
||||
@Ignore("Prevents ANT from trying to run these as tests")
|
||||
@SuppressWarnings("OneTopLevelClass")
|
||||
@@ -126,26 +123,20 @@ class FirstSubSuiteTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("MethodName")
|
||||
public void aTestMethod() {
|
||||
}
|
||||
public void aTestMethod() {}
|
||||
}
|
||||
|
||||
@SuppressWarnings("OneTopLevelClass")
|
||||
class SecondSubSuiteTest {
|
||||
}
|
||||
|
||||
class SecondSubSuiteTest {}
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({FirstSubSuiteTest.class, SecondSubSuiteTest.class, UnusualTest.class})
|
||||
@Ignore("Prevents ANT from trying to run these as tests")
|
||||
@SuppressWarnings("OneTopLevelClass")
|
||||
class ExampleSubSuite extends AbstractTestSuite {
|
||||
}
|
||||
|
||||
class ExampleSubSuite extends AbstractTestSuite {}
|
||||
|
||||
@Ignore("Prevents ANT from trying to run these as tests")
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({})
|
||||
@SuppressWarnings("OneTopLevelClass")
|
||||
class EmptySuite extends AbstractTestSuite {
|
||||
}
|
||||
class EmptySuite extends AbstractTestSuite {}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package edu.wpi.first.wpilibj.test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.tools.ant.BuildLogger;
|
||||
import org.apache.tools.ant.DefaultLogger;
|
||||
import org.apache.tools.ant.Project;
|
||||
@@ -76,13 +75,13 @@ public class AntJunitLanucher {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
TestBench.out().println(
|
||||
"Run will not output XML for Jenkins because " + "tests are not being run with ANT");
|
||||
TestBench.out()
|
||||
.println(
|
||||
"Run will not output XML for Jenkins because " + "tests are not being run with ANT");
|
||||
// This should never return as it makes its own call to
|
||||
// System.exit();
|
||||
TestSuite.main(args);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package edu.wpi.first.wpilibj.test;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -27,8 +26,6 @@ public class QuickTest extends AbstractComsSetup {
|
||||
return logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
}
|
||||
public void test() {}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ package edu.wpi.first.wpilibj.test;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
@@ -17,21 +16,18 @@ import org.junit.runners.model.Statement;
|
||||
* is important if you have a test that fails only "sometimes" and needs to be rerun to find the
|
||||
* issue.
|
||||
*
|
||||
* <p>This code was originally found here:
|
||||
* <a href="http://www.codeaffine.com/2013/04/10/running-junit-tests-repeatedly-without-loops/">
|
||||
* Running JUnit Tests Repeatedly Without Loops</a>
|
||||
* <p>This code was originally found here: <a
|
||||
* href="http://www.codeaffine.com/2013/04/10/running-junit-tests-repeatedly-without-loops/">Running
|
||||
* JUnit Tests Repeatedly Without Loops</a>
|
||||
*/
|
||||
public class RepeatRule implements TestRule {
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({java.lang.annotation.ElementType.METHOD})
|
||||
public @interface Repeat {
|
||||
/**
|
||||
* The number of times to repeat the test.
|
||||
*/
|
||||
/** The number of times to repeat the test. */
|
||||
int times();
|
||||
}
|
||||
|
||||
|
||||
private static class RepeatStatement extends Statement {
|
||||
private final int m_times;
|
||||
private final Statement m_statement;
|
||||
|
||||
@@ -4,12 +4,6 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.test;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogGyro;
|
||||
import edu.wpi.first.wpilibj.AnalogInput;
|
||||
import edu.wpi.first.wpilibj.AnalogOutput;
|
||||
@@ -24,6 +18,11 @@ import edu.wpi.first.wpilibj.fixtures.DIOCrossConnectFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.RelayCrossConnectFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.TiltPanCameraFixture;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class provides access to all of the elements on the test bench, for use in fixtures. This
|
||||
@@ -46,7 +45,6 @@ public final class TestBench {
|
||||
public static final int kTiltServoChannel = 9;
|
||||
public static final int kPanServoChannel = 8;
|
||||
|
||||
|
||||
/* PowerDistributionPanel channels */
|
||||
public static final int kJaguarPDPChannel = 6;
|
||||
public static final int kVictorPDPChannel = 8;
|
||||
@@ -58,17 +56,14 @@ public final class TestBench {
|
||||
public static final int DIOCrossConnectA2 = 7;
|
||||
public static final int DIOCrossConnectA1 = 6;
|
||||
|
||||
/**
|
||||
* The Singleton instance of the Test Bench.
|
||||
*/
|
||||
/** The Singleton instance of the Test Bench. */
|
||||
private static TestBench instance = null;
|
||||
|
||||
/**
|
||||
* The single constructor for the TestBench. This method is private in order to prevent multiple
|
||||
* TestBench objects from being allocated.
|
||||
*/
|
||||
protected TestBench() {
|
||||
}
|
||||
protected TestBench() {}
|
||||
|
||||
/**
|
||||
* Constructs a new set of objects representing a connected set of Talon controlled Motors and an
|
||||
@@ -198,21 +193,23 @@ public final class TestBench {
|
||||
return new DIOCrossConnectFixture(inputPort, outputPort);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets two lists of possible DIO pairs for the two pairs.
|
||||
*/
|
||||
/** Gets two lists of possible DIO pairs for the two pairs. */
|
||||
private List<List<Integer[]>> getDIOCrossConnect() {
|
||||
List<List<Integer[]>> pairs = new ArrayList<List<Integer[]>>();
|
||||
List<Integer[]> setA =
|
||||
Arrays.asList(new Integer[][]{
|
||||
{DIOCrossConnectA1, DIOCrossConnectA2},
|
||||
{DIOCrossConnectA2, DIOCrossConnectA1}});
|
||||
Arrays.asList(
|
||||
new Integer[][] {
|
||||
{DIOCrossConnectA1, DIOCrossConnectA2},
|
||||
{DIOCrossConnectA2, DIOCrossConnectA1}
|
||||
});
|
||||
pairs.add(setA);
|
||||
|
||||
List<Integer[]> setB =
|
||||
Arrays.asList(new Integer[][]{
|
||||
{DIOCrossConnectB1, DIOCrossConnectB2},
|
||||
{DIOCrossConnectB2, DIOCrossConnectB1}});
|
||||
Arrays.asList(
|
||||
new Integer[][] {
|
||||
{DIOCrossConnectB1, DIOCrossConnectB2},
|
||||
{DIOCrossConnectB2, DIOCrossConnectB1}
|
||||
});
|
||||
pairs.add(setB);
|
||||
// NOTE: IF MORE DIOCROSSCONNECT PAIRS ARE ADDED ADD THEM HERE
|
||||
return pairs;
|
||||
@@ -273,8 +270,8 @@ public final class TestBench {
|
||||
* @param flip whether this encoder needs to be flipped
|
||||
* @return A list of different inputs to use for the tests
|
||||
*/
|
||||
private Collection<Integer[]> getPairArray(List<Integer[]> listA, List<Integer[]> listB,
|
||||
boolean flip) {
|
||||
private Collection<Integer[]> getPairArray(
|
||||
List<Integer[]> listA, List<Integer[]> listB, boolean flip) {
|
||||
Collection<Integer[]> encoderPortPairs = new ArrayList<Integer[]>();
|
||||
for (Integer[] portPairsA : listA) {
|
||||
Integer[] inputs = new Integer[5];
|
||||
@@ -310,10 +307,10 @@ public final class TestBench {
|
||||
public Collection<Integer[]> getEncoderDIOCrossConnectCollection() {
|
||||
Collection<Integer[]> encoderPortPairs = new ArrayList<Integer[]>();
|
||||
assert getDIOCrossConnect().size() == 2;
|
||||
encoderPortPairs.addAll(getPairArray(getDIOCrossConnect().get(0), getDIOCrossConnect().get(1),
|
||||
false));
|
||||
encoderPortPairs.addAll(getPairArray(getDIOCrossConnect().get(1), getDIOCrossConnect().get(0),
|
||||
false));
|
||||
encoderPortPairs.addAll(
|
||||
getPairArray(getDIOCrossConnect().get(0), getDIOCrossConnect().get(1), false));
|
||||
encoderPortPairs.addAll(
|
||||
getPairArray(getDIOCrossConnect().get(1), getDIOCrossConnect().get(0), false));
|
||||
assert encoderPortPairs.size() == 8;
|
||||
return encoderPortPairs;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.test;
|
||||
|
||||
import edu.wpi.first.wpilibj.WpiLibJTestSuite;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
@@ -13,7 +14,8 @@ import java.util.Objects;
|
||||
import java.util.logging.LogManager;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.JUnit4TestAdapter;
|
||||
import junit.runner.Version;
|
||||
import org.junit.runner.JUnitCore;
|
||||
import org.junit.runner.Result;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -21,11 +23,6 @@ import org.junit.runner.notification.Failure;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
import junit.framework.JUnit4TestAdapter;
|
||||
import junit.runner.Version;
|
||||
|
||||
import edu.wpi.first.wpilibj.WpiLibJTestSuite;
|
||||
|
||||
/**
|
||||
* The WPILibJ Integeration Test Suite collects all of the tests to be run by junit. In order for a
|
||||
* test to be run, it must be added the list of suite classes below. The tests will be run in the
|
||||
@@ -50,9 +47,8 @@ public class TestSuite extends AbstractTestSuite {
|
||||
}
|
||||
|
||||
private static final Logger WPILIBJ_ROOT_LOGGER = Logger.getLogger("edu.wpi.first.wpilibj");
|
||||
private static final Logger WPILIBJ_COMMAND_ROOT_LOGGER = Logger
|
||||
.getLogger("edu.wpi.first.wpilibj.command");
|
||||
|
||||
private static final Logger WPILIBJ_COMMAND_ROOT_LOGGER =
|
||||
Logger.getLogger("edu.wpi.first.wpilibj.command");
|
||||
|
||||
private static final Class<?> QUICK_TEST = QuickTest.class;
|
||||
private static final String QUICK_TEST_FLAG = "--quick";
|
||||
@@ -63,9 +59,7 @@ public class TestSuite extends AbstractTestSuite {
|
||||
|
||||
private static TestSuite instance = null;
|
||||
|
||||
/**
|
||||
* Get the singleton instance of the test suite.
|
||||
*/
|
||||
/** Get the singleton instance of the test suite. */
|
||||
public static TestSuite getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new TestSuite();
|
||||
@@ -73,32 +67,41 @@ public class TestSuite extends AbstractTestSuite {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* This has to be public so that the JUnit4.
|
||||
*/
|
||||
public TestSuite() {
|
||||
}
|
||||
/** This has to be public so that the JUnit4. */
|
||||
public TestSuite() {}
|
||||
|
||||
/**
|
||||
* Displays a help message for the user when they use the --help flag at runtime.
|
||||
*/
|
||||
/** Displays a help message for the user when they use the --help flag at runtime. */
|
||||
protected static void displayHelp() {
|
||||
StringBuilder helpMessage = new StringBuilder("Test Parameters help: \n");
|
||||
helpMessage.append("\t" + QUICK_TEST_FLAG
|
||||
+ " will cause the quick test to be run. Ignores other flags except for "
|
||||
+ METHOD_REPEAT_FILTER + "\n");
|
||||
helpMessage.append("\t" + CLASS_NAME_FILTER
|
||||
+ " will use the supplied regex text to search for suite/test class names "
|
||||
+ "matching the regex and run them.\n");
|
||||
helpMessage.append("\t" + METHOD_NAME_FILTER
|
||||
+ " will use the supplied regex text to search for test methods (excluding methods "
|
||||
+ "with the @Ignore annotation) and run only those methods. Can be paired with "
|
||||
+ METHOD_REPEAT_FILTER + " to " + "repeat the selected tests multiple times.\n");
|
||||
helpMessage.append("\t" + METHOD_REPEAT_FILTER + " will repeat the tests selected with either "
|
||||
+ QUICK_TEST_FLAG + " or " + CLASS_NAME_FILTER
|
||||
+ " and run them the given number of times.\n");
|
||||
helpMessage
|
||||
.append("[NOTE] All regex uses the syntax defined by java.util.regex.Pattern. This "
|
||||
helpMessage.append(
|
||||
"\t"
|
||||
+ QUICK_TEST_FLAG
|
||||
+ " will cause the quick test to be run. Ignores other flags except for "
|
||||
+ METHOD_REPEAT_FILTER
|
||||
+ "\n");
|
||||
helpMessage.append(
|
||||
"\t"
|
||||
+ CLASS_NAME_FILTER
|
||||
+ " will use the supplied regex text to search for suite/test class names "
|
||||
+ "matching the regex and run them.\n");
|
||||
helpMessage.append(
|
||||
"\t"
|
||||
+ METHOD_NAME_FILTER
|
||||
+ " will use the supplied regex text to search for test methods (excluding methods "
|
||||
+ "with the @Ignore annotation) and run only those methods. Can be paired with "
|
||||
+ METHOD_REPEAT_FILTER
|
||||
+ " to "
|
||||
+ "repeat the selected tests multiple times.\n");
|
||||
helpMessage.append(
|
||||
"\t"
|
||||
+ METHOD_REPEAT_FILTER
|
||||
+ " will repeat the tests selected with either "
|
||||
+ QUICK_TEST_FLAG
|
||||
+ " or "
|
||||
+ CLASS_NAME_FILTER
|
||||
+ " and run them the given number of times.\n");
|
||||
helpMessage.append(
|
||||
"[NOTE] All regex uses the syntax defined by java.util.regex.Pattern. This "
|
||||
+ "documentation can be found at "
|
||||
+ "http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html\n");
|
||||
helpMessage.append("\n");
|
||||
@@ -118,12 +121,12 @@ public class TestSuite extends AbstractTestSuite {
|
||||
invalidMessage.append(a + " ");
|
||||
}
|
||||
invalidMessage.append("\n");
|
||||
invalidMessage
|
||||
.append("For details on proper usage of the runtime flags please run again with the "
|
||||
+ HELP_FLAG + " flag.\n\n");
|
||||
invalidMessage.append(
|
||||
"For details on proper usage of the runtime flags please run again with the "
|
||||
+ HELP_FLAG
|
||||
+ " flag.\n\n");
|
||||
|
||||
TestBench.out().println(invalidMessage);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +147,6 @@ public class TestSuite extends AbstractTestSuite {
|
||||
TestBench.out().println(loadedTestsMessage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses the arguments passed at runtime and runs the appropriate tests based upon these
|
||||
* arguments.
|
||||
@@ -176,8 +178,8 @@ public class TestSuite extends AbstractTestSuite {
|
||||
try {
|
||||
repeatCount = Integer.parseInt(new String(s).replace(METHOD_REPEAT_FILTER, ""));
|
||||
} catch (NumberFormatException ex) {
|
||||
displayInvalidUsage("The argument passed to the repeat rule was not a valid integer.",
|
||||
args);
|
||||
displayInvalidUsage(
|
||||
"The argument passed to the repeat rule was not a valid integer.", args);
|
||||
}
|
||||
}
|
||||
if (Pattern.matches(CLASS_NAME_FILTER + ".*", s)) {
|
||||
@@ -186,7 +188,6 @@ public class TestSuite extends AbstractTestSuite {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ArrayList<String> argsParsed = new ArrayList<String>(Arrays.asList(args));
|
||||
if (argsParsed.contains(HELP_FLAG)) {
|
||||
// If the user inputs the help flag then return the help message and exit
|
||||
@@ -200,8 +201,8 @@ public class TestSuite extends AbstractTestSuite {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the data from multiple {@link Result}s in one class that can be
|
||||
* returned to display the results.
|
||||
* Stores the data from multiple {@link Result}s in one class that can be returned to display
|
||||
* the results.
|
||||
*/
|
||||
class MultipleResult extends Result {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -252,8 +253,8 @@ public class TestSuite extends AbstractTestSuite {
|
||||
if (methodFilter) {
|
||||
List<ClassMethodPair> pairs = (new TestSuite()).getMethodMatching(methodRegex);
|
||||
if (pairs.size() == 0) {
|
||||
displayInvalidUsage("None of the arguments passed to the method name filter matched.",
|
||||
args);
|
||||
displayInvalidUsage(
|
||||
"None of the arguments passed to the method name filter matched.", args);
|
||||
return null;
|
||||
}
|
||||
// Print out the list of tests before we run them
|
||||
@@ -268,7 +269,6 @@ public class TestSuite extends AbstractTestSuite {
|
||||
TestBench.out().println("\t" + p.m_methodName);
|
||||
}
|
||||
|
||||
|
||||
// The test results will be saved here
|
||||
MultipleResult results = new MultipleResult();
|
||||
// Runs tests multiple times if the repeat rule is used
|
||||
@@ -320,9 +320,17 @@ public class TestSuite extends AbstractTestSuite {
|
||||
TestBench.out().println();
|
||||
TestBench.out().println("FAILURES!!!");
|
||||
// Print the test statistics
|
||||
TestBench.out().println(
|
||||
"Tests run: " + result.getRunCount() + ", Failures: " + result.getFailureCount()
|
||||
+ ", Ignored: " + result.getIgnoreCount() + ", In " + result.getRunTime() + "ms");
|
||||
TestBench.out()
|
||||
.println(
|
||||
"Tests run: "
|
||||
+ result.getRunCount()
|
||||
+ ", Failures: "
|
||||
+ result.getFailureCount()
|
||||
+ ", Ignored: "
|
||||
+ result.getIgnoreCount()
|
||||
+ ", In "
|
||||
+ result.getRunTime()
|
||||
+ "ms");
|
||||
|
||||
// Prints out a list of test that failed
|
||||
TestBench.out().println("Failure List (short):");
|
||||
@@ -337,9 +345,15 @@ public class TestSuite extends AbstractTestSuite {
|
||||
}
|
||||
} else {
|
||||
TestBench.out().println("SUCCESS!");
|
||||
TestBench.out().println(
|
||||
"Tests run: " + result.getRunCount() + ", Ignored: " + result.getIgnoreCount() + ", In "
|
||||
+ result.getRunTime() + "ms");
|
||||
TestBench.out()
|
||||
.println(
|
||||
"Tests run: "
|
||||
+ result.getRunCount()
|
||||
+ ", Ignored: "
|
||||
+ result.getIgnoreCount()
|
||||
+ ", In "
|
||||
+ result.getRunTime()
|
||||
+ "ms");
|
||||
}
|
||||
TestBench.out().println();
|
||||
}
|
||||
@@ -353,7 +367,6 @@ public class TestSuite extends AbstractTestSuite {
|
||||
return new JUnit4TestAdapter(TestSuite.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The method called at runtime.
|
||||
*
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
/**
|
||||
* This is the starting point for the integration testing framework. This package should contain
|
||||
* classes that are not explicitly for testing the library but instead provide the framework that
|
||||
* the tests can extend from. Every test should extend from
|
||||
* {@link edu.wpi.first.wpilibj.test.AbstractComsSetup}
|
||||
* to ensure that Network Communications is properly instantiated before the test is run. The
|
||||
* {@link edu.wpi.first.wpilibj.test.TestBench} should contain the port numbers for all of the
|
||||
* hardware and these values should not be explicitly defined anywhere else in the testing
|
||||
* framework.
|
||||
* the tests can extend from. Every test should extend from {@link
|
||||
* edu.wpi.first.wpilibj.test.AbstractComsSetup} to ensure that Network Communications is properly
|
||||
* instantiated before the test is run. The {@link edu.wpi.first.wpilibj.test.TestBench} should
|
||||
* contain the port numbers for all of the hardware and these values should not be explicitly
|
||||
* defined anywhere else in the testing framework.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.test;
|
||||
|
||||
Reference in New Issue
Block a user