Skip to content

Commit

Permalink
feature: improved the files runner doc and fixed related issues
Browse files Browse the repository at this point in the history
 - the location of the files object
 - the reporting of unknown arguments
  • Loading branch information
symbiont-eric-torreborre committed May 22, 2021
1 parent 522bd18 commit e725bfb
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import text._

/**
* Methods with default Property values to create Arguments instances
*
* There is an implicit conversion from (=> T) to Property[T] to allow the direct passing of parameters
*
* There is an implicit conversion from (=> T) to Property[T] to allow the direct passing of parameters
*/
trait ArgumentsArgs extends ArgumentsCreation with ArgProperties

Expand Down Expand Up @@ -133,7 +133,7 @@ trait ArgumentsCreation {
checkUrls: ArgProperty[Boolean] = ArgProperty[Boolean](),
notoc: ArgProperty[Boolean] = ArgProperty[Boolean](),
notifier: ArgProperty[String] = ArgProperty[String](),
exporter: ArgProperty[String] = ArgProperty[String]()) = new Arguments(
printer: ArgProperty[String] = ArgProperty[String]()) = new Arguments(
report = Report(xonly.toOption.map(v => if (v) Report.xonlyFlags else Report.allFlags).orElse(showOnly.toOption),
failtrace.toOption,
color.toOption,
Expand All @@ -145,7 +145,7 @@ trait ArgumentsCreation {
checkUrls.toOption,
notoc.toOption,
notifier.toOption,
exporter.toOption))
printer.toOption))

}

Expand Down
29 changes: 29 additions & 0 deletions common/shared/src/main/scala/org/specs2/main/CommandLine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ object CommandLine extends Extract {
Report.allArguments ++
FilesRunnerArguments.allArguments

// other arguments which are not mentioned in Arguments
// this is a stop gap measure until a more modular solution is found
val extraArguments: Seq[ArgumentType] = List(
BooleanArgument("verbose"),
BooleanArgument("console"),
BooleanArgument("all"),
BooleanArgument("silent"),
BooleanArgument("pandoc"),
ValuedArgument("scalacheck.mintestsok"),
ValuedArgument("scalacheck.minsize"),
ValuedArgument("scalacheck.maxdiscardratio"),
ValuedArgument("scalacheck.maxsize"),
ValuedArgument("scalacheck.workers"),
ValuedArgument("scalacheck.seed"),
ValuedArgument("scalacheck.verbosity"),
ValuedArgument("sbt.tags"),
ValuedArgument("stats.outdir"),
ValuedArgument("junit.outdir"),
ValuedArgument("markdown.outdir"),
ValuedArgument("markdown.ext"),
ValuedArgument("html.outdir"),
ValuedArgument("html.template"),
ValuedArgument("html.variables"),
ValuedArgument("html.nostats"),
ValuedArgument("html.search"),
ValuedArgument("html.toc"),
ValuedArgument("html.toc.entrymaxsize"),
ValuedArgument("html.warn.missingref"))

val allArgumentNames = allArguments.map(_.name)

def splitValues(arguments: String): Seq[String] = splitValues(arguments.split(" "))
Expand Down
12 changes: 6 additions & 6 deletions common/shared/src/main/scala/org/specs2/main/Report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ case class Report(
_checkUrls : Option[Boolean] = None,
_notoc: Option[Boolean] = None,
_notifier: Option[String] = None,
_exporter: Option[String] = None) extends ShowArgs {
_printer: Option[String] = None) extends ShowArgs {

import Arguments._

Expand All @@ -36,7 +36,7 @@ case class Report(
def notoc: Boolean = _notoc.getOrElse(false)
def hasToc: Boolean = !notoc
def notifier: String = _notifier.getOrElse("")
def exporter: String = _exporter.getOrElse("")
def printer: String = _printer.getOrElse("")

def overrideWith(other: Report) = {
new Report(
Expand All @@ -51,7 +51,7 @@ case class Report(
other._checkUrls .orElse(_checkUrls),
other._notoc .orElse(_notoc),
other._notifier .orElse(_notifier),
other._exporter .orElse(_exporter)
other._printer .orElse(_printer)
)
}

Expand All @@ -67,7 +67,7 @@ case class Report(
"checkUrls" -> _checkUrls,
"notoc" -> _notoc,
"notifier" -> _notifier,
"exporter" -> _exporter).flatMap(showArg).mkString("Report(", ", ", ")")
"printer" -> _printer).flatMap(showArg).mkString("Report(", ", ", ")")

}

Expand All @@ -87,7 +87,7 @@ object Report extends Extract {
_checkUrls = bool("checkUrls"),
_notoc = bool("noToc"),
_notifier = value("notifier"),
_exporter = value("exporter")
_printer = value("printer")
)
}

Expand All @@ -111,6 +111,6 @@ object Report extends Extract {
BooleanArgument("checkUrls"),
BooleanArgument("noToc"),
ValuedArgument("notifier"),
ValuedArgument("exporter"))
ValuedArgument("printer"))

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ trait ArgumentsCreation extends org.specs2.main.ArgumentsCreation with MutableAr
checkUrls: ArgProperty[Boolean] = ArgProperty[Boolean](),
notoc: ArgProperty[Boolean] = ArgProperty[Boolean](),
notifier: ArgProperty[String] = ArgProperty[String](),
exporter: ArgProperty[String] = ArgProperty[String]()) = updateArguments(super.report(
printer: ArgProperty[String] = ArgProperty[String]()) = updateArguments(super.report(
xonly,
showOnly,
failtrace,
Expand All @@ -146,11 +146,8 @@ trait ArgumentsCreation extends org.specs2.main.ArgumentsCreation with MutableAr
checkUrls,
notoc,
notifier,
exporter))
printer))
}


}



4 changes: 2 additions & 2 deletions guide/src/test/scala/org/specs2/Website.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Website(env: Env) extends Specification with Specs2Variables with Specs2Ta
"""

implicit val ee = env.executionEnv

val outputDir = "target" / "specs2-reports" / "site"
val versionDirName = FileName.unsafe("SPECS2-"+VERSION)

Expand All @@ -39,7 +39,7 @@ class Website(env: Env) extends Specification with Specs2Variables with Specs2Ta
fs.writeFile(siteOutputDir | page.name, replacedVersion) >> {
// copy the index page at the root of the site
// it will then re-direct to a specific version
if (page.path.contains("index.html") && isOfficial(VERSION)) fs.writeFile(outputDir | page.name, replacedVersion)
if (page.path.contains("index.html")) fs.writeFile(outputDir | page.name, replacedVersion)
else Operations.ok(())
}
} yield ()
Expand Down
11 changes: 5 additions & 6 deletions guide/src/test/scala/org/specs2/guide/ArgumentsReference.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.specs2
package guide

import org.specs2.runner.SpecificationsFinder._
import org.specs2.main.FilesRunnerArguments._

object ArgumentsReference extends UserGuidePage { def is = "Arguments reference".title ^ s2"""

Expand Down Expand Up @@ -35,27 +35,28 @@ This reference guide for arguments is divided in several sections:
- "reporting" arguments to control the output
- API for arguments when used in the code

**Tip!** the `verbose` argument will report any unknown argument passed on the command line

## Paths

Name | Default value | Description
----------------------- | ------------------------------ | -------------------------------------------------------------------------------------------
`stats.outdir` | `target/specs2-reports/stats` | output directory for run statistics (see $Selection)
`junit.outdir` | `target/test-reports/` | output directory for JUnit XML files (see $JUnitXmlOutput)
`html.outdir` | `target/specs2-reports` | output directory for html files (see $HtmlOutput)
`filesrunner.basepath` | `$specificationsBasePath` | source directory for test files (see $RunInShell)
`filesrunner.path` | `$specificationsPath` | glob pattern for the file paths (see $RunInShell)
`filesrunner.pattern` | `$specificationsPattern` | regular expression capturing the specification class/object name (see $RunInShell)
`filesrunner.verbose` | `false` | logs of searched paths and potential classes to instantiate (see $RunInShell)
`html.outdir` | `target/specs2-reports` | output directory for html files (see $HtmlOutput)


## Selection

Name | Default value | Description
----------------------- | ------------------------------ | -------------------------------------------------------------------------------------------
`ex` | `.*` | regular expression specifying the examples to execute. Use `ex .*brilliant.*` on the command line
`was` | `""` | select only some previously executed examples based on their status
`include` | `""` | execute only the fragments tagged with any of the comma-separated list of tags: `t1,t2,...`
`exclude` | `""` | do not execute the fragments tagged with any of the comma-separated list of tags: `t1,t2,...`
`was` | `""` | select only some previously executed examples based on their status
`selector` | `""` | implementation of the `org.specs2.specification.process.Selector` trait

## Execution
Expand Down Expand Up @@ -109,7 +110,6 @@ See the $ConsoleOutput page for a more precise description of these options.
`showtimes` | `false` | show execution times for examples
`notifier` | `""` | name of a class extending the `org.specs2.reporter.Notifier` trait
`printer` | `""` | name of a class extending the `org.specs2.reporter.Printer` trait
`reporter` | `""` | name of a class extending the `org.specs2.reporter.Reporter` trait

For ${"the HTML output" ~/ HtmlOutput} the following options can be used:

Expand Down Expand Up @@ -166,4 +166,3 @@ There are also a few shortcuts:
"""

}

8 changes: 4 additions & 4 deletions guide/src/test/scala/org/specs2/guide/RunInShell.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.specs2
package guide

import org.specs2.runner.SpecificationsFinder._
import org.specs2.main.FilesRunnerArguments._

object RunInShell extends UserGuidePage { def is = s2"""
It is not necessary to use a build tool to run a specification. You just need to have the right dependencies on the classpath and use one of the $specs2 runners.
Expand All @@ -10,12 +10,12 @@ It is not necessary to use a build tool to run a specification. You just need to

When you use a build tool you generally only need to specify the main dependencies then any transitive dependency will be fetched for you.
However, when you run specifications from the shell you need to specify the classpath yourself. The best way to do this is to use `sbt` to
make sure your specification compiles with all the required dependencies, then export the classpath with:
make sure your specification compiles with all the required dependencies, then export the project classpath:
```
sbt> export Runtime / fullClasspath
sbt> export Test / fullClasspath
```
With the output of both commands you can define an environment variable, $$SPECS2_PATH
With the output of both commands you can define an environment variable, `$$SPECS2_PATH`
```
sh> export $$SPECS2_PATH=<runtime classpath>:<test classpath>
```
Expand All @@ -33,7 +33,7 @@ And the other arguments are used to drive the execution of the specification as

#### Run several specifications

The `specs2.files` object will select and execute all Specifications found in the test source directory according to the following parameters:
The `specs2.files` object will select and execute all specifications found in the test source directory according to the following parameters:

Name | Default value | Description
----------- | --------------- | -------------------------
Expand Down
20 changes: 8 additions & 12 deletions guide/src/test/scala/org/specs2/guide/Specs2Variables.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.specs2
package guide

import buildinfo._

object Specs2Variables extends Specs2Variables

trait Specs2Variables {
Expand All @@ -14,17 +16,11 @@ trait Specs2Variables {

lazy val specs2Variables: Map[String, String] =
Map(
"VERSION" -> VERSION,
"SITE_DIR" -> SITE_DIR,
"PROJECT_DIR" -> PROJECT_DIR,
"GUIDE_DIR" -> GUIDE_DIR,
"EXAMPLES_DIR" -> EXAMPLES_DIR,
"API_DIR" -> API_DIR
"VERSION" -> VERSION,
"SITE_DIR" -> SITE_DIR,
"PROJECT_DIR" -> PROJECT_DIR,
"GUIDE_DIR" -> GUIDE_DIR,
"EXAMPLES_DIR" -> EXAMPLES_DIR,
"API_DIR" -> API_DIR
)


/** @return true if the version is not timestamped */
def isOfficial(version: String): Boolean =
!version.contains(BuildInfo.timestamp)
}

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ case class Parameters(minTestsOk: Int = Test.Parameters.default.
maxSize = commandLine.intOr ("scalacheck.maxsize", maxSize),
workers = commandLine.intOr ("scalacheck.workers", workers),
seed = commandLine.value ("scalacheck.seed").flatMap(Parameters.makeSeed).orElse(seed)
).setVerbosity(commandLine.intOr ("scalacheck.verbosity", prettyParams.verbosity))
).setVerbosity(commandLine.intOr ("scalacheck.verbosity", prettyParams.verbosity))

if (commandLine.boolOr("scalacheck.verbose", false)) updated.verbose
else updated
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ThisBuild / version := "4.11.0"
ThisBuild / version := "4.11.1"
ThisBuild / versionScheme := Some("semver-spec")

0 comments on commit e725bfb

Please sign in to comment.