Skip to content

Commit

Permalink
Update to work with JUnit Platform 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoberstar committed Feb 25, 2018
1 parent 246ff3d commit d7b6ea2
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2

# Clojure dialect settings
[*.{clj,cljc,cljs}]
indent_style = space
indent_size = 2
indent_size = 2
7 changes: 4 additions & 3 deletions jovial-engine-clojure.test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ plugins {
}

dependencies {
compile 'org.junit.platform:junit-platform-engine:1.0.0-M1'
compile 'org.junit.platform:junit-platform-engine:1.1.0'
compile 'org.clojure:clojure:1.9.0'
compile project(':jovial-lang-clojure')

testCompile 'junit:junit:4.12'
testCompile 'org.junit.platform:junit-platform-launcher:1.0.0-M1'
testCompile 'org.junit.platform:junit-platform-launcher:1.1.0'
}

test {
systemProperty "classpath.roots", classpath.asPath
classpath += files('src/test/samples')
systemProperty "classpath.roots", file('src/test/samples')
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import clojure.lang.Namespace;
import java.util.Set;
import org.ajoberstar.jovial.lang.clojure.util.SimpleClojure;
import org.junit.platform.engine.TestDescriptor.Type;
import org.junit.platform.engine.TestTag;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor;
Expand All @@ -27,24 +28,21 @@ public class ClojureNamespaceDescriptor extends AbstractTestDescriptor {
private final Set<TestTag> tags;

public ClojureNamespaceDescriptor(UniqueId id, Namespace ns) {
super(id, ns.toString());
super(
id,
ns.toString(),
SimpleClojure.invoke("org.ajoberstar.jovial.lang.clojure", "ns-source", ns));
this.ns = ns;
this.tags = SimpleClojure.invoke("org.ajoberstar.jovial.lang.clojure", "tags", ns);
setSource(SimpleClojure.invoke("org.ajoberstar.jovial.lang.clojure", "ns-source", ns));
}

public Namespace getNamespace() {
return ns;
}

@Override
public boolean isContainer() {
return true;
}

@Override
public boolean isTest() {
return false;
public Type getType() {
return Type.CONTAINER;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@
import clojure.lang.Var;
import java.util.Set;
import org.ajoberstar.jovial.lang.clojure.util.SimpleClojure;
import org.junit.platform.engine.TestDescriptor.Type;
import org.junit.platform.engine.TestTag;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor;

public class ClojureVarDescriptor extends AbstractTestDescriptor {
public final class ClojureVarDescriptor extends AbstractTestDescriptor {
private final Var var;
private final Set<TestTag> tags;

public ClojureVarDescriptor(UniqueId id, Var var) {
super(id, var.sym.getName());
super(
id,
var.sym.getName(),
SimpleClojure.invoke("org.ajoberstar.jovial.lang.clojure", "var-source", var));
this.var = var;
this.tags = SimpleClojure.invoke("org.ajoberstar.jovial.lang.clojure", "tags", var);
setSource(SimpleClojure.invoke("org.ajoberstar.jovial.lang.clojure", "var-source", var));
}

public Var getVar() {
Expand All @@ -43,13 +46,8 @@ public Namespace getNamespace() {
}

@Override
public boolean isContainer() {
return false;
}

@Override
public boolean isTest() {
return true;
public Type getType() {
return Type.TEST;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand All @@ -40,9 +42,9 @@
public class ClojureTestEngineTest {
@Test
public void selectingByClasspathDir() {
Set<File> roots =
Set<Path> roots =
Arrays.stream(System.getProperty("classpath.roots").split(File.pathSeparator))
.map(File::new)
.map(Paths::get)
.collect(Collectors.toSet());

EngineDiscoveryRequest request =
Expand All @@ -63,7 +65,7 @@ public void selectingByClasspathDir() {
TestDescriptor descriptor = new ClojureTestEngine().discover(request, root);
List<UniqueId> actualIds =
descriptor
.getAllDescendants()
.getDescendants()
.stream()
.map(TestDescriptor::getUniqueId)
.collect(Collectors.toList());
Expand All @@ -90,7 +92,7 @@ public void selectingByNamespace() {
TestDescriptor descriptor = new ClojureTestEngine().discover(request, root);
List<UniqueId> actualIds =
descriptor
.getAllDescendants()
.getDescendants()
.stream()
.map(TestDescriptor::getUniqueId)
.collect(Collectors.toList());
Expand All @@ -115,7 +117,7 @@ public void selectingByVar() {
TestDescriptor descriptor = new ClojureTestEngine().discover(request, root);
List<UniqueId> actualIds =
descriptor
.getAllDescendants()
.getDescendants()
.stream()
.map(TestDescriptor::getUniqueId)
.collect(Collectors.toList());
Expand Down Expand Up @@ -144,7 +146,7 @@ public void selectingTestByUniqueId() {
TestDescriptor descriptor = new ClojureTestEngine().discover(request, root);
List<UniqueId> actualIds =
descriptor
.getAllDescendants()
.getDescendants()
.stream()
.map(TestDescriptor::getUniqueId)
.collect(Collectors.toList());
Expand Down Expand Up @@ -173,7 +175,7 @@ public void selectingContainerByUniqueId() {
TestDescriptor descriptor = new ClojureTestEngine().discover(request, root);
List<UniqueId> actualIds =
descriptor
.getAllDescendants()
.getDescendants()
.stream()
.map(TestDescriptor::getUniqueId)
.collect(Collectors.toList());
Expand All @@ -183,9 +185,9 @@ public void selectingContainerByUniqueId() {

@Test
public void filteringByNamespace() {
Set<File> roots =
Set<Path> roots =
Arrays.stream(System.getProperty("classpath.roots").split(File.pathSeparator))
.map(File::new)
.map(Paths::get)
.collect(Collectors.toSet());

EngineDiscoveryRequest request =
Expand All @@ -206,7 +208,7 @@ public void filteringByNamespace() {
TestDescriptor descriptor = new ClojureTestEngine().discover(request, root);
List<UniqueId> actualIds =
descriptor
.getAllDescendants()
.getDescendants()
.stream()
.map(TestDescriptor::getUniqueId)
.collect(Collectors.toList());
Expand All @@ -216,9 +218,9 @@ public void filteringByNamespace() {

@Test
public void getsTagsFromMetadata() {
Set<File> roots =
Set<Path> roots =
Arrays.stream(System.getProperty("classpath.roots").split(File.pathSeparator))
.map(File::new)
.map(Paths::get)
.collect(Collectors.toSet());

EngineDiscoveryRequest request =
Expand All @@ -245,7 +247,7 @@ public void getsTagsFromMetadata() {
TestDescriptor descriptor = new ClojureTestEngine().discover(request, root);
Map<UniqueId, Set<TestTag>> actualTags =
descriptor
.getAllDescendants()
.getDescendants()
.stream()
.collect(Collectors.toMap(TestDescriptor::getUniqueId, TestDescriptor::getTags));

Expand Down
2 changes: 1 addition & 1 deletion jovial-lang-clojure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

dependencies {
compile 'org.junit.platform:junit-platform-engine:1.0.0-M1'
compile 'org.junit.platform:junit-platform-engine:1.1.0'
compile 'org.clojure:clojure:1.9.0'
compile 'org.clojure:tools.namespace:0.2.11'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@

(defn var-source [var]
(let [{:keys [ns name file line column]} (meta var)
file-pos (if (and line column) (FilePosition. line column))
file (if file (FileSource. (io/file *root-dir* file) file-pos))
file-pos (if (and line column) (FilePosition/from line column))
file (if file (FileSource/from (io/file *root-dir* file) file-pos))
var (->ClojureVarSource (str ns) (str name))]
(if file
(CompositeTestSource. [var file])
(CompositeTestSource/from [var file])
var)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
[clojure.string :as str])
(:import (clojure.lang Var Namespace)
(java.io File)
(java.nio.file Path)
(java.nio.file Path Paths)
(java.net URI)
(org.ajoberstar.jovial.lang.clojure VarSelector NamespaceSelector NamespaceFilter)
(org.junit.platform.engine UniqueId EngineDiscoveryRequest Filter DiscoverySelector)
(org.junit.platform.engine.discovery UniqueIdSelector ClasspathSelector ClassSelector)))
(org.junit.platform.engine.discovery UniqueIdSelector ClasspathRootSelector ClassSelector)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Selecting candidates for discovery
Expand Down Expand Up @@ -37,6 +38,8 @@
(->> [dir] find-namespaces (map sym->ns) (mapcat -select)))))
Path
(-select [dir] (-select (.toFile dir)))
URI
(-select [uri] (-select (Paths/get uri)))
Class
(-select [clazz]
(let [clazz-name (.getCanonicalName clazz)
Expand All @@ -56,20 +59,19 @@
(-select [selector] (-select (.getNamespace selector)))
UniqueIdSelector
(-select [selector] (-select (.getUniqueId selector)))
ClasspathSelector
ClasspathRootSelector
(-select [selector] (-select (.getClasspathRoot selector)))
ClassSelector
(-select [selector] (-select (.getJavaClass selector))))


(defn select [^EngineDiscoveryRequest request]
(mapcat -select (.getSelectorsByType request DiscoverySelector)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Filtering candidates for discovery
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- ns-filter [request candidates]
(let [filters (.getDiscoveryFiltersByType request NamespaceFilter)
(let [filters (.getFiltersByType request NamespaceFilter)
unified (Filter/composeFilters filters)
included? (fn [cand] (->> cand :namespace (.apply unified) .included))]
(clojure.core/filter included? candidates)))
Expand Down

0 comments on commit d7b6ea2

Please sign in to comment.