Search in sources :

Example 1 with FeatureWithLines

use of io.cucumber.core.feature.FeatureWithLines in project cucumber-jvm by cucumber.

the class CucumberOptionsAnnotationParser method addFeatures.

private void addFeatures(CucumberOptions options, RuntimeOptionsBuilder args) {
    if (options != null && options.features().length != 0) {
        for (String feature : options.features()) {
            if (feature.startsWith("@")) {
                Path rerunFile = Paths.get(feature.substring(1));
                args.addRerun(parseFeatureWithLinesFile(rerunFile));
            } else {
                FeatureWithLines featureWithLines = FeatureWithLines.parse(feature);
                args.addFeature(featureWithLines);
            }
        }
        featuresSpecified = true;
    }
}
Also used : GluePath(io.cucumber.core.feature.GluePath) Path(java.nio.file.Path) FeatureWithLines(io.cucumber.core.feature.FeatureWithLines)

Example 2 with FeatureWithLines

use of io.cucumber.core.feature.FeatureWithLines in project cucumber-jvm by cucumber.

the class RerunFormatter method finishReport.

private void finishReport() {
    for (Map.Entry<URI, Collection<Integer>> entry : featureAndFailedLinesMapping.entrySet()) {
        FeatureWithLines featureWithLines = create(relativize(entry.getKey()), entry.getValue());
        out.println(featureWithLines.toString());
    }
    out.close();
}
Also used : FeatureWithLines(io.cucumber.core.feature.FeatureWithLines) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) URI(java.net.URI)

Example 3 with FeatureWithLines

use of io.cucumber.core.feature.FeatureWithLines in project cucumber-jvm by cucumber.

the class CommandlineOptionsParser method parse.

private RuntimeOptionsBuilder parse(List<String> args) {
    args = new ArrayList<>(args);
    RuntimeOptionsBuilder parsedOptions = new RuntimeOptionsBuilder();
    while (!args.isEmpty()) {
        String arg = args.remove(0).trim();
        if (arg.equals(HELP) || arg.equals(HELP_SHORT)) {
            printUsage();
            exitCode = 0;
            return parsedOptions;
        } else if (arg.equals(VERSION) || arg.equals(VERSION_SHORT)) {
            out.println(CORE_VERSION);
            exitCode = 0;
            return parsedOptions;
        } else if (arg.equals(I18N)) {
            String nextArg = removeArgFor(arg, args);
            exitCode = printI18n(nextArg);
            return parsedOptions;
        } else if (arg.equals(THREADS)) {
            int threads = Integer.parseInt(removeArgFor(arg, args));
            if (threads < 1) {
                out.println("--threads must be > 0");
                exitCode = 1;
                return parsedOptions;
            }
            parsedOptions.setThreads(threads);
        } else if (arg.equals(GLUE) || arg.equals(GLUE_SHORT)) {
            String gluePath = removeArgFor(arg, args);
            URI parse = GluePath.parse(gluePath);
            parsedOptions.addGlue(parse);
        } else if (arg.equals(TAGS) || arg.equals(TAGS_SHORT)) {
            parsedOptions.addTagFilter(TagExpressionParser.parse(removeArgFor(arg, args)));
        } else if (arg.equals(PUBLISH)) {
            parsedOptions.setPublish(true);
        } else if (arg.equals(PLUGIN) || arg.equals(PLUGIN_SHORT)) {
            String pluginName = removeArgFor(arg, args);
            if (pluginName.equals("null_summary")) {
                log.warn(() -> "Use '--no-summary' instead of '-p/--plugin null_summary'. '-p/--plugin null_summary' will be removed in a future release.");
                parsedOptions.setNoSummary();
            } else if (pluginName.equals("default_summary")) {
                log.warn(() -> "Use '-p/--plugin summary' instead of '-p/--plugin default_summary'. '-p/--plugin default_summary' will be removed in a future release.");
                parsedOptions.addPluginName("summary");
            } else {
                parsedOptions.addPluginName(pluginName);
            }
        } else if (arg.equals(DRY_RUN) || arg.equals(DRY_RUN_SHORT)) {
            parsedOptions.setDryRun(true);
        } else if (arg.equals(NO_DRY_RUN)) {
            parsedOptions.setDryRun(false);
        } else if (arg.equals(NO_SUMMARY)) {
            parsedOptions.setNoSummary();
        } else if (arg.equals(MONOCHROME) || arg.equals(MONOCHROME_SHORT)) {
            parsedOptions.setMonochrome(true);
        } else if (arg.equals(NO_MONOCHROME)) {
            parsedOptions.setMonochrome(false);
        } else if (arg.equals(SNIPPETS)) {
            String nextArg = removeArgFor(arg, args);
            parsedOptions.setSnippetType(SnippetTypeParser.parseSnippetType(nextArg));
        } else if (arg.equals(NAME) || arg.equals(NAME_SHORT)) {
            String nextArg = removeArgFor(arg, args);
            Pattern pattern = Pattern.compile(nextArg);
            parsedOptions.addNameFilter(pattern);
        } else if (arg.equals(WIP) || arg.equals(WIP_SHORT)) {
            parsedOptions.setWip(true);
        } else if (arg.equals(ORDER)) {
            parsedOptions.setPickleOrder(PickleOrderParser.parse(removeArgFor(arg, args)));
        } else if (arg.equals(COUNT)) {
            int count = Integer.parseInt(removeArgFor(arg, args));
            if (count < 1) {
                out.println("--count must be > 0");
                exitCode = 1;
                return parsedOptions;
            }
            parsedOptions.setCount(count);
        } else if (arg.equals(OBJECT_FACTORY)) {
            String objectFactoryClassName = removeArgFor(arg, args);
            parsedOptions.setObjectFactoryClass(parseObjectFactory(objectFactoryClassName));
        } else if (arg.startsWith("-")) {
            out.println("Unknown option: " + arg);
            printUsage();
            exitCode = 1;
            return parsedOptions;
        } else if (!arg.isEmpty()) {
            if (arg.startsWith("@")) {
                Path rerunFile = Paths.get(arg.substring(1));
                parsedOptions.addRerun(parseFeatureWithLinesFile(rerunFile));
            } else {
                FeatureWithLines featureWithLines = FeatureWithLines.parse(arg);
                parsedOptions.addFeature(featureWithLines);
            }
        }
    }
    return parsedOptions;
}
Also used : GluePath(io.cucumber.core.feature.GluePath) Path(java.nio.file.Path) Pattern(java.util.regex.Pattern) FeatureWithLines(io.cucumber.core.feature.FeatureWithLines) URI(java.net.URI)

Example 4 with FeatureWithLines

use of io.cucumber.core.feature.FeatureWithLines in project cucumber-jvm by cucumber.

the class CucumberOptionsAnnotationParser method addDefaultFeaturePathIfNoFeaturePathIsSpecified.

private void addDefaultFeaturePathIfNoFeaturePathIsSpecified(RuntimeOptionsBuilder args, Class<?> clazz) {
    if (!featuresSpecified) {
        String packageName = packagePath(clazz);
        FeatureWithLines featureWithLines = FeatureWithLines.parse(packageName);
        args.addFeature(featureWithLines);
    }
}
Also used : FeatureWithLines(io.cucumber.core.feature.FeatureWithLines)

Example 5 with FeatureWithLines

use of io.cucumber.core.feature.FeatureWithLines in project cucumber-jvm by cucumber.

the class OptionsFileParser method parseFeatureWithLinesFile.

static Collection<FeatureWithLines> parseFeatureWithLinesFile(Path path) {
    try {
        List<FeatureWithLines> featurePaths = new ArrayList<>();
        readAllLines(path).forEach(line -> {
            Matcher matcher = RERUN_PATH_SPECIFICATION.matcher(line);
            while (matcher.find()) {
                featurePaths.add(FeatureWithLines.parse(matcher.group(1)));
            }
        });
        return featurePaths;
    } catch (Exception e) {
        throw new CucumberException(format("Failed to parse '%s'", path), e);
    }
}
Also used : FeatureWithLines(io.cucumber.core.feature.FeatureWithLines) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) CucumberException(io.cucumber.core.exception.CucumberException) CucumberException(io.cucumber.core.exception.CucumberException)

Aggregations

FeatureWithLines (io.cucumber.core.feature.FeatureWithLines)5 GluePath (io.cucumber.core.feature.GluePath)2 URI (java.net.URI)2 Path (java.nio.file.Path)2 CucumberException (io.cucumber.core.exception.CucumberException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1