Skip to content

Commit

Permalink
implemented comma separated part numbers for run-tests.py (#66)
Browse files Browse the repository at this point in the history
Co-authored-by: ibm5 <[email protected]>
  • Loading branch information
armanbm177 and ibm5 authored Jan 14, 2024
1 parent 9d6917d commit dfd6988
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
34 changes: 23 additions & 11 deletions framework/tst/dslabs/framework/testing/junit/DSLabsTestCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package dslabs.framework.testing.junit;

import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import dslabs.framework.testing.utils.ClassSearch;
import java.util.Set;
Expand Down Expand Up @@ -121,10 +122,10 @@ public static void main(String[] args) throws Exception {
Option.builder("p")
.longOpt("part")
.required(false)
.argName("PART")
.hasArg(true)
.numberOfArgs(1)
.desc("part number")
.argName("PART_NUMS")
.desc("comma-separated list of part numbers")
.build();
final Option testNum =
Option.builder("n")
Expand Down Expand Up @@ -196,9 +197,13 @@ public String describe() {
}
});

final ImmutableSet<String> partNumbers =
line.hasOption(part)
? ImmutableSet.copyOf(line.getOptionValue(part).split(","))
: ImmutableSet.of();

// Only run test classes for this part
if (line.hasOption(part)) {
final int partNum = Integer.parseInt(line.getOptionValue(part));
if (!partNumbers.isEmpty()) {
request =
request.filterWith(
new Filter() {
Expand All @@ -208,25 +213,32 @@ public boolean shouldRun(Description description) {
return true;
}
var p = description.getAnnotation(Part.class);
return p != null && p.value() == partNum;
return p != null && partNumbers.contains(String.valueOf(p.value()));
}

@Override
public String describe() {
return "part " + partNum;
return String.format("part %s", partNumbers);
}
});
}

// Only run chosen test numbers
if (line.hasOption(testNum)) {
final Set<String> testNumbers = Sets.newHashSet(line.getOptionValue(testNum).split(","));
final ImmutableSet<String> specifiedTestNumbers =
ImmutableSet.copyOf(line.getOptionValue(testNum).split(","));
final Set<String> testNumbers = Sets.newHashSet(specifiedTestNumbers);

// If the part is selected, allow specifying test number only
if (line.hasOption(part)) {
for (var tn : line.getOptionValue(testNum).split(",")) {
if (!partNumbers.isEmpty()) {
if (partNumbers.size() > 1) {
throw new IllegalArgumentException(
"Cannot specify multiple part numbers when selecting individual test numbers.");
}
final String partStr = partNumbers.stream().findFirst().get();
for (var tn : specifiedTestNumbers) {
// XXX: not the best way of doing this, but it works
testNumbers.add(line.getOptionValue(part) + "." + tn);
testNumbers.add(partStr + "." + tn);
}
}

Expand All @@ -243,7 +255,7 @@ public boolean shouldRun(Description description) {

@Override
public String describe() {
return String.format("test numbers %s", testNumbers);
return String.format("test numbers %s", specifiedTestNumbers);
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions handout-files/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ def main():
group = run_modes.add_mutually_exclusive_group()

parser.add_argument('-l', '--lab', help="lab to run tests for")
parser.add_argument('-p', '--part', type=int,
help="part number for tests to run")

parser.add_argument('-p', '--part',
help="part number(s) to run tests for (comma-separated)")

parser.add_argument('-n', '--test-num',
help="specific, comma-separated test numbers to run "
Expand Down

0 comments on commit dfd6988

Please sign in to comment.