Skip to content

Commit

Permalink
Cleaning up code
Browse files Browse the repository at this point in the history
  • Loading branch information
thegridman committed Feb 12, 2024
1 parent 0afff1d commit 8f74aa5
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 211 deletions.
16 changes: 14 additions & 2 deletions lib_xunit/src/main/x/xunit.x
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,27 @@ module xunit.xtclang.org {
* A function that performs a predicate check on a test fixture.
*/
typedef function Boolean (Object) as FixturePredicate;


/**
* A `FixturePredicate` that tests a value is a `Method`.
*/
static FixturePredicate MethodFixturePredicate = o -> o.is(Method);

/**
* A `FixturePredicate` that tests a value is a `Class`.
*/
static FixturePredicate ClassFixturePredicate = o -> o.is(Class);

/**
* A `FixturePredicate` that tests a value is a `Package`.
*/
static FixturePredicate PackageFixturePredicate = o -> o.is(Package);

/**
* A skipped test result.
* The result for a possibly skipped test,
*
* @param skipped a flag that is `True` if the test was skipped, or `False` if the test was executed.
* @param reason an optional message to describe why the test was skipped
*/
const SkipResult(Boolean skipped, String reason = "unknown") {
/**
Expand Down
5 changes: 2 additions & 3 deletions lib_xunit/src/main/x/xunit/DisplayNameGenerator.x
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import annotations.DisplayName;

/**
* A class that can generate display names for classes and methods.
* A class that can generate human readable names for test classes and methods.
* These names will be used in console output and test reports.
*/
interface DisplayNameGenerator
extends Const {
Expand Down Expand Up @@ -43,14 +44,12 @@ interface DisplayNameGenerator
*/
static String parameterTypesAsString(MethodOrFunction method) {
StringBuffer buf = new StringBuffer().add('(');

EachParam: for (Parameter param : method.params) {
if (!EachParam.first) {
", ".appendTo(buf);
}
param.appendTo(buf);
}

return buf.add(')').toString();
}

Expand Down
4 changes: 2 additions & 2 deletions lib_xunit/src/main/x/xunit/ExecutionContext.x
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* A holder of information that an `ExtensionProvider` can use to provide
* an `Extension`.
* A holder of information that an `ExtensionProvider` can use
* when providing an `Extension`.
*/
interface ExecutionContext {
/**
Expand Down
1 change: 0 additions & 1 deletion lib_xunit/src/main/x/xunit/ExtensionProvider.x
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* A provider of `Extension`s.
*/
interface ExtensionProvider {

/**
* The name of this provider.
*/
Expand Down
5 changes: 2 additions & 3 deletions lib_xunit/src/main/x/xunit/ParameterResolver.x
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ecstasy.reflect.Parameter;

/**
* A `ParameterResolver` is able to resolve values for parameters to be used to call methods and functions.
* A `ParameterResolver` is able to resolve values for parameters to be used
* when executing test methods and functions.
*/
interface ParameterResolver {
/**
Expand Down Expand Up @@ -30,7 +31,6 @@ interface ParameterResolver {
if (unresolved.empty) {
return values;
}

ParameterResolver[] resolvers = context.registry.getResources(ParameterResolver);
throw new IllegalState($"Failed to resolve parameters: unresolved={unresolved} resolvers={resolvers}");
}
Expand Down Expand Up @@ -71,7 +71,6 @@ interface ParameterResolver {
unresolved.add(param);
}
}

return paramValues, unresolved;
}

Expand Down
5 changes: 2 additions & 3 deletions lib_xunit_engine/src/main/x/xunit_engine/DefaultTestEngine.x
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ service DefaultTestEngine
*
* @return the modified `EngineExecutionContext.Builder` to modify
*/
protected EngineExecutionContext.Builder modifyExecutionContext(EngineExecutionContext.Builder builder) {
return builder.withListener(listener);
}
protected EngineExecutionContext.Builder modifyExecutionContext(EngineExecutionContext.Builder builder) =
builder.withListener(listener);
}
24 changes: 6 additions & 18 deletions lib_xunit_engine/src/main/x/xunit_engine/DiscoveryConfiguration.x
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ const DiscoveryConfiguration {
/**
* Return this `DiscoveryConfiguration` as a `Builder`.
*/
Builder asBuilder() {
return new Builder(this);
}
Builder asBuilder() = new Builder(this);

/**
* A convenience method to return the display name for a
Expand All @@ -46,9 +44,7 @@ const DiscoveryConfiguration {
*
* @return the human readable display name for the `Class`
*/
String displayNameFor(Class clz) {
return displayNameGenerator.nameForClass(clz);
}
String displayNameFor(Class clz) = displayNameGenerator.nameForClass(clz);

/**
* A convenience method to return the display name for a
Expand All @@ -59,25 +55,19 @@ const DiscoveryConfiguration {
*
* @return the human readable display name for the `Class`
*/
String displayNameFor(Class clz, MethodOrFunction method) {
return displayNameGenerator.nameForMethod(clz, method);
}
String displayNameFor(Class clz, MethodOrFunction method) = displayNameGenerator.nameForMethod(clz, method);

// ----- factory methods -----------------------------------------------------------------------

/**
* Create a default `DiscoveryConfiguration`.
*/
static DiscoveryConfiguration create() {
return builder().build();
}
static DiscoveryConfiguration create() = builder().build();

/**
* Create a `DiscoveryConfiguration` builder.
*/
static Builder builder() {
return new Builder();
}
static Builder builder() = new Builder();

// ----- inner class: Builder ------------------------------------------------------------------

Expand Down Expand Up @@ -142,8 +132,6 @@ const DiscoveryConfiguration {
*
* @return a `DiscoveryConfiguration` built from this `Builder`
*/
DiscoveryConfiguration build() {
return new DiscoveryConfiguration(this);
}
DiscoveryConfiguration build() = new DiscoveryConfiguration(this);
}
}
4 changes: 1 addition & 3 deletions lib_xunit_engine/src/main/x/xunit_engine/DiscoveryEngine.x
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ interface DiscoveryEngine
*
* @return an instance of the default `DiscoveryEngine`
*/
static DiscoveryEngine create() {
return new DefaultDiscoveryEngine();
}
static DiscoveryEngine create() = new DefaultDiscoveryEngine();
}
16 changes: 4 additions & 12 deletions lib_xunit_engine/src/main/x/xunit_engine/ExecutionConfiguration.x
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,17 @@ const ExecutionConfiguration {
/**
* Return this `ExecutionConfiguration` as a `Builder`.
*/
Builder asBuilder() {
return new Builder(this);
}
Builder asBuilder() = new Builder(this);

/**
* Create a default `ExecutionConfiguration`.
*/
static ExecutionConfiguration create() {
return builder().build();
}
static ExecutionConfiguration create() = builder().build();

/**
* Create an `ExecutionConfiguration` builder.
*/
static Builder builder() {
return new Builder();
}
static Builder builder() = new Builder();

/**
* An `ExecutionConfiguration` builder.
Expand All @@ -54,8 +48,6 @@ const ExecutionConfiguration {
*
* @return an `ExecutionConfiguration` built from this `Builder`
*/
ExecutionConfiguration build() {
return new ExecutionConfiguration(this);
}
ExecutionConfiguration build() = new ExecutionConfiguration(this);
}
}
10 changes: 4 additions & 6 deletions lib_xunit_engine/src/main/x/xunit_engine/ExecutionListener.x
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,14 @@ interface ExecutionListener {
/**
* Compare two ReportEntry values for the purposes of ordering.
*/
static <CompileType extends ReportEntry> Ordered compare(CompileType value1, CompileType value2) {
return value1.timestamp <=> value2.timestamp;
}
static <CompileType extends ReportEntry> Ordered compare(CompileType value1, CompileType value2) =
value1.timestamp <=> value2.timestamp;

/**
* Compare two ReportEntry values for equality.
*/
static <CompileType extends ReportEntry> Boolean equals(CompileType value1, CompileType value2) {
return value1.timestamp == value2.timestamp;
}
static <CompileType extends ReportEntry> Boolean equals(CompileType value1, CompileType value2) =
value1.timestamp == value2.timestamp;
}

// ---- inner const: NoOpListener --------------------------------------------------------------
Expand Down
27 changes: 8 additions & 19 deletions lib_xunit_engine/src/main/x/xunit_engine/Model.x
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,12 @@ interface Model
*
* A root model is a model without a parent.
*/
Boolean isRoot() {
return parentId == Null;
}
Boolean isRoot() = parentId == Null;

/**
* Determine if this model may register dynamic tests during execution.
*/
Boolean mayRegisterTests() {
return False;
}
Boolean mayRegisterTests() = False;

/**
* Determine if the supplied model (or any of its descendants)
Expand All @@ -103,10 +99,8 @@ interface Model
* @return `True` if the model is a test, contains tests, or may
* later register tests dynamically
*/
static Boolean containsTests(Model model) {
return !model.isContainer || model.mayRegisterTests()
|| model.children.any((d) -> d.containsTests());
}
static Boolean containsTests(Model model) =
!model.isContainer || model.mayRegisterTests() || model.children.any((d) -> d.containsTests());

/**
* Find the model with the supplied unique ID.
Expand Down Expand Up @@ -167,21 +161,16 @@ interface Model
/**
* Compare two Model values for equality.
*/
static <CompileType extends Model> Boolean equals(CompileType value1, CompileType value2) {
return value1.uniqueId == value2.uniqueId;
}
static <CompileType extends Model> Boolean equals(CompileType value1, CompileType value2) =
value1.uniqueId == value2.uniqueId;

// ----- Stringable methods --------------------------------------------------------------------

@Override
Int estimateStringLength() {
return displayName.estimateStringLength();
}
Int estimateStringLength() = displayName.estimateStringLength();

@Override
Appender<Char> appendTo(Appender<Char> buf) {
return displayName.appendTo(buf);
}
Appender<Char> appendTo(Appender<Char> buf) = displayName.appendTo(buf);

// ----- Visitor interface ---------------------------------------------------------------------

Expand Down
4 changes: 1 addition & 3 deletions lib_xunit_engine/src/main/x/xunit_engine/Result.x
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const Result(Status status, Exception? exception = Null, Exception[]? suppressed
*
* @return a copy of this `Result` with a specific duration
*/
Result withDuration(Duration d) {
return new Result(status, exception, suppressed, d);
}
Result withDuration(Duration d) = new Result(status, exception, suppressed, d);

/**
* A singleton `Result` representing a successful test fixture.
Expand Down
25 changes: 7 additions & 18 deletions lib_xunit_engine/src/main/x/xunit_engine/UniqueId.x
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ const UniqueId
*
* @return the type of this `UniqueId`
*/
@Lazy SegmentType type.calc() {
return segments[size -1].type;
}
@Lazy SegmentType type.calc() = segments[size -1].type;

/**
* Return the value of this `UniqueId`.
Expand All @@ -48,9 +46,7 @@ const UniqueId
*
* @return the value of this `UniqueId`
*/
@Lazy String value.calc() {
return segments[size -1].value;
}
@Lazy String value.calc() = segments[size -1].value;

/**
* Return the path for this `UniqueId`.
Expand Down Expand Up @@ -94,9 +90,7 @@ const UniqueId
* @param type the `Segment` type
* @param value the `Segment` value
*/
UniqueId! append(SegmentType type, String value) {
return new UniqueId(segments + new Segment(type, value));
}
UniqueId! append(SegmentType type, String value) = new UniqueId(segments + new Segment(type, value));

/**
* Returns the parent of this `UniqueId`.
Expand Down Expand Up @@ -128,21 +122,16 @@ const UniqueId
}

@Override
static <CompileType extends UniqueId> Boolean equals(CompileType value1, CompileType value2) {
return value1.segments == value2.segments;
}
static <CompileType extends UniqueId> Boolean equals(CompileType value1, CompileType value2)
= value1.segments == value2.segments;

// ----- Stringable methods --------------------------------------------------------------------

@Override
Int estimateStringLength() {
return stringValue.size;
}
Int estimateStringLength() = stringValue.size;

@Override
Appender<Char> appendTo(Appender<Char> buf) {
return stringValue.appendTo(buf);
}
Appender<Char> appendTo(Appender<Char> buf) = stringValue.appendTo(buf);

// ----- factory methods -----------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ package selectors {
return selectors;
}

Selector forMethod(Class clz, MethodOrFunction testMethod) {
return new MethodSelector(clz, testMethod);
}
Selector forMethod(Class clz, MethodOrFunction testMethod) = new MethodSelector(clz, testMethod);

conditional Selector forPackage(Type type) {
if (type.isA(Package)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import xunit.MethodOrFunction;
// ----- ExecutionLifecycle methods ------------------------------------------------------------

@Override
List<Model> getChildren(EngineExecutionContext context) {
return model.children;
}
List<Model> getChildren(EngineExecutionContext context) = model.children;

// ----- helper methods ------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit 8f74aa5

Please sign in to comment.