Skip to content

Commit

Permalink
Report summaries and in the same way as the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Oct 7, 2013
1 parent 545ecf5 commit 3e4dae2
Show file tree
Hide file tree
Showing 15 changed files with 532 additions and 355 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
## [1-1-6-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.5...master) ## [1-1-6-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.5...master)


* [Core, Java] Log a warning when more than one IoC dependency is found in the classpath ([#594](https://github.com/cucumber/cucumber-jvm/pull/594) Ariel Kogan) * [Core, Java] Log a warning when more than one IoC dependency is found in the classpath ([#594](https://github.com/cucumber/cucumber-jvm/pull/594) Ariel Kogan)
* [JUnit,TestNG] Report summaries and `.cucumber/stepdefs.json` in the same way as the CLI (Aslak Hellesøy)


## [1.1.5](https://github.com/cucumber/cucumber-jvm/compare/v1.1.4...v1.1.5) (2013-09-14) ## [1.1.5](https://github.com/cucumber/cucumber-jvm/compare/v1.1.4...v1.1.5) (2013-09-14)


Expand Down
2 changes: 1 addition & 1 deletion android/AndroidManifest.xml
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,3 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.1.5" package="cucumber.api.android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.1.6-SNAPSHOT" package="cucumber.api.android">
</manifest> </manifest>
1 change: 0 additions & 1 deletion core/src/main/java/cucumber/api/cli/Main.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static void run(String[] argv, ClassLoader classLoader) throws IOExceptio
ResourceLoader resourceLoader = new MultiLoader(classLoader); ResourceLoader resourceLoader = new MultiLoader(classLoader);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader); ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions); Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
runtime.writeStepdefsJson();
runtime.run(); runtime.run();
System.exit(runtime.exitStatus()); System.exit(runtime.exitStatus());
} }
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/cucumber/runtime/Glue.java
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
package cucumber.runtime; package cucumber.runtime;


import cucumber.runtime.io.ResourceLoader;
import gherkin.I18n; import gherkin.I18n;
import gherkin.formatter.model.Step; import gherkin.formatter.model.Step;


Expand All @@ -24,5 +25,5 @@ public interface Glue {


StepDefinitionMatch stepDefinitionMatch(String uri, Step step, I18n i18n); StepDefinitionMatch stepDefinitionMatch(String uri, Step step, I18n i18n);


void writeStepdefsJson(List<String> featurePaths, URL dotCucumber) throws IOException; void writeStepdefsJson(ResourceLoader resourceLoader, List<String> featurePaths, URL dotCucumber);
} }
32 changes: 16 additions & 16 deletions core/src/main/java/cucumber/runtime/Runtime.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cucumber.api.Pending; import cucumber.api.Pending;
import cucumber.runtime.io.ResourceLoader; import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.model.CucumberFeature; import cucumber.runtime.model.CucumberFeature;
import cucumber.runtime.snippets.SummaryPrinter;
import cucumber.runtime.xstream.LocalizedXStreams; import cucumber.runtime.xstream.LocalizedXStreams;
import gherkin.I18n; import gherkin.I18n;
import gherkin.formatter.Argument; import gherkin.formatter.Argument;
Expand Down Expand Up @@ -42,7 +41,7 @@ public class Runtime implements UnreportedStepExecutor {
private static final Object DUMMY_ARG = new Object(); private static final Object DUMMY_ARG = new Object();
private static final byte ERRORS = 0x1; private static final byte ERRORS = 0x1;


private final SummaryCounter summaryCounter; private final Stats stats;
final UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker(); final UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker();


private final Glue glue; private final Glue glue;
Expand Down Expand Up @@ -83,7 +82,7 @@ public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, Collectio
this.runtimeOptions = runtimeOptions; this.runtimeOptions = runtimeOptions;
this.stopWatch = stopWatch; this.stopWatch = stopWatch;
this.glue = optionalGlue != null ? optionalGlue : new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader)); this.glue = optionalGlue != null ? optionalGlue : new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader));
this.summaryCounter = new SummaryCounter(runtimeOptions.isMonochrome()); this.stats = new Stats(runtimeOptions.isMonochrome());


for (Backend backend : backends) { for (Backend backend : backends) {
backend.loadGlue(glue, runtimeOptions.getGlue()); backend.loadGlue(glue, runtimeOptions.getGlue());
Expand All @@ -103,7 +102,7 @@ public void addError(Throwable error) {
/** /**
* This is the main entry point. Used from CLI, but not from JUnit. * This is the main entry point. Used from CLI, but not from JUnit.
*/ */
public void run() { public void run() throws IOException {
for (CucumberFeature cucumberFeature : runtimeOptions.cucumberFeatures(resourceLoader)) { for (CucumberFeature cucumberFeature : runtimeOptions.cucumberFeatures(resourceLoader)) {
run(cucumberFeature); run(cucumberFeature);
} }
Expand All @@ -120,9 +119,18 @@ private void run(CucumberFeature cucumberFeature) {
cucumberFeature.run(formatter, reporter, this); cucumberFeature.run(formatter, reporter, this);
} }


private void printSummary() { public void printSummary() {
// TODO: inject a SummaryPrinter in the ctor // TODO: inject a SummaryPrinter in the ctor
new SummaryPrinter(System.out).print(this); new SummaryPrinter(System.out).print(this);
writeStepdefsJson();
}

void printStats(PrintStream out) {
stats.printStats(out);
}

private void writeStepdefsJson() {
glue.writeStepdefsJson(resourceLoader, runtimeOptions.getFeaturePaths(), runtimeOptions.getDotCucumber());
} }


public void buildBackendWorlds(Reporter reporter, Set<Tag> tags) { public void buildBackendWorlds(Reporter reporter, Set<Tag> tags) {
Expand All @@ -136,7 +144,7 @@ public void buildBackendWorlds(Reporter reporter, Set<Tag> tags) {
} }


public void disposeBackendWorlds() { public void disposeBackendWorlds() {
summaryCounter.addScenario(scenarioResult.getStatus()); stats.addScenario(scenarioResult.getStatus());
for (Backend backend : backends) { for (Backend backend : backends) {
backend.disposeWorld(); backend.disposeWorld();
} }
Expand Down Expand Up @@ -308,21 +316,13 @@ public static boolean isPending(Throwable t) {
return t.getClass().isAnnotationPresent(Pending.class) || Arrays.binarySearch(PENDING_EXCEPTIONS, t.getClass().getName()) >= 0; return t.getClass().isAnnotationPresent(Pending.class) || Arrays.binarySearch(PENDING_EXCEPTIONS, t.getClass().getName()) >= 0;
} }


public void writeStepdefsJson() throws IOException {
glue.writeStepdefsJson(runtimeOptions.getFeaturePaths(), runtimeOptions.getDotCucumber());
}

public void printSummary(PrintStream out) {
summaryCounter.printSummary(out);
}

private void addStepToCounterAndResult(Result result) { private void addStepToCounterAndResult(Result result) {
scenarioResult.add(result); scenarioResult.add(result);
summaryCounter.addStep(result); stats.addStep(result);
} }


private void addHookToCounterAndResult(Result result) { private void addHookToCounterAndResult(Result result) {
scenarioResult.add(result); scenarioResult.add(result);
summaryCounter.addHookTime(result.getDuration()); stats.addHookTime(result.getDuration());
} }
} }
17 changes: 11 additions & 6 deletions core/src/main/java/cucumber/runtime/RuntimeGlue.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import cucumber.runtime.autocomplete.MetaStepdef; import cucumber.runtime.autocomplete.MetaStepdef;
import cucumber.runtime.autocomplete.StepdefGenerator; import cucumber.runtime.autocomplete.StepdefGenerator;
import cucumber.runtime.io.FileResourceLoader; import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.io.URLOutputStream; import cucumber.runtime.io.URLOutputStream;
import cucumber.runtime.io.UTF8OutputStreamWriter; import cucumber.runtime.io.UTF8OutputStreamWriter;
import cucumber.runtime.model.CucumberFeature; import cucumber.runtime.model.CucumberFeature;
Expand Down Expand Up @@ -101,16 +101,21 @@ private List<StepDefinitionMatch> stepDefinitionMatches(String uri, Step step) {
} }


@Override @Override
public void writeStepdefsJson(List<String> featurePaths, URL dotCucumber) throws IOException { public void writeStepdefsJson(ResourceLoader resourceLoader, List<String> featurePaths, URL dotCucumber) {
if (dotCucumber != null) { if (dotCucumber != null) {
List<CucumberFeature> features = load(new FileResourceLoader(), featurePaths, NO_FILTERS); List<CucumberFeature> features = load(resourceLoader, featurePaths, NO_FILTERS);
List<MetaStepdef> metaStepdefs = new StepdefGenerator().generate(stepDefinitionsByPattern.values(), features); List<MetaStepdef> metaStepdefs = new StepdefGenerator().generate(stepDefinitionsByPattern.values(), features);
Gson gson = new GsonBuilder().setPrettyPrinting().create(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(metaStepdefs); String json = gson.toJson(metaStepdefs);


Writer stepdefsJson = new UTF8OutputStreamWriter(new URLOutputStream(new URL(dotCucumber, "stepdefs.json"))); try {
stepdefsJson.append(json); URL stepdefsUrl = new URL(dotCucumber, "stepdefs.json");
stepdefsJson.close(); Writer stepdefsJson = new UTF8OutputStreamWriter(new URLOutputStream(stepdefsUrl));
stepdefsJson.append(json);
stepdefsJson.close();
} catch (IOException e) {
throw new CucumberException("Failed to write stepdefs.json", e);
}
} }
} }
} }
Loading

0 comments on commit 3e4dae2

Please sign in to comment.