Skip to content

Commit

Permalink
External DirSuite Mk3
Browse files Browse the repository at this point in the history
This replace DirSuite Mk2 with external DirSuite Mk3.  See #125
for background information.

Major changes between Mk2 and Mk3:

 - Test are discovered based on exec file, not by conf files.
 - Args-files are gone. If there are args for test case,
   then those are defined in exec-files.
 - Mk3 scanning is recursive by default.
 - Mk3 supports also Glob's. With glob `something/**.exec` includes
   all subdirectories under `something/`
 - Mk3 is more strict against human errors (e.g. Suite is aborted if
   pattern doesn't find anything, or if basedir is wrong, etc.).
 - It is possible to run tests without any agruments, even without
   conf-file
 - It is possible to run multiple steps per test
 - It is possible to run multistep dual assertions
   (success + failure assertion)

Changes:
 - tests/**.exec: Added exec-file for every conf-file (previous "test case")
 - tests/**.args: removed args and content was moved to exec,
   if there was an args-file for test case
 - cli/src/test/../DirSuite.scala: removed Mk2 DirSuite
 - cli/src/tets/../TestComparator.scala: removed Mk2 DirSuite
 - cli/src/test/../DefaultArgsDirSuite.scala: Default Argument provider
   for Abandon test cases.
 - cli/src/test/../CliTest.scala: Use new Mk3 DirSuite,
   and change all old Regex to Glob
 - project/Dependencies.scala: Add library
   fi.sn127.utils.testing (rel:0.6.0 - DirSuite Mk3)
 - cli/build.sbt: Add test time dependency to DirSuite
  • Loading branch information
jaa127 committed Jan 22, 2017
1 parent a34e5b4 commit bd380c5
Show file tree
Hide file tree
Showing 60 changed files with 131 additions and 231 deletions.
1 change: 1 addition & 0 deletions cli/build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Dependencies._

libraryDependencies += scalatest % "test"
libraryDependencies += dirSuite % "test"

fork in Test := true
29 changes: 17 additions & 12 deletions cli/src/test/scala/co/uproot/abandon/CliTest.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package co.uproot.abandon

import java.nio.file.Paths

import fi.sn127.utils.fs.Glob

/**
* Test valid and invalid input with full CLI App
* and verify return value of main app.
*/
class CliAppTests extends DirSuite {
class CliAppTests extends DefaultArgsDirSuite {
val basedir = Paths.get("../tests").toAbsolutePath.normalize


/**
* OK Cases (should succeed)
*/
testDirSuite("../tests", ".*/sclT[0-9]+(-.*)$") { args: Array[String] =>
runDirSuiteTestCases(basedir, Glob("sclT*/**.exec")) { args: Array[String] =>
assertResult(CLIApp.SUCCEEDED) {
CLIApp.mainStatus(args)
}
Expand All @@ -19,7 +25,7 @@ class CliAppTests extends DirSuite {
* Error cases (should fail)
* Pending bugs are kept inside bugs* so don't match that
*/
testDirSuite("../tests/errors", ".*/[A-Z]([a-zA-Z])+$") { args: Array[String] =>
runDirSuiteTestCases(basedir, Glob("errors/[A-Z]*/**.exec")) { args: Array[String] =>
assertResult(CLIApp.FAILED) {
CLIApp.mainStatus(args)
}
Expand All @@ -30,22 +36,21 @@ class CliAppTests extends DirSuite {
* Test invalid input and options with CliApp
* and verify that specific exception is thrown.
*/
class CliAppErrors extends DirSuite {

val errorRoot = "../tests/errors"
class CliAppErrors extends DefaultArgsDirSuite {
val errorRoot = Paths.get("../tests/errors").toAbsolutePath.normalize

/**
* these should fail, but they are not failing
*/
ignoreDirSuite(errorRoot, ".*/bugsInputError$") { args: Array[String] =>
ignoreDirSuiteTestCases(errorRoot, Glob("bugsInputError/**.exec")) { args: Array[String] =>
assertThrows[SettingsError] {
CLIApp.run(args)
}
}
/**
* These errors should be specialized, but at least they error out at the moment
*/
testDirSuite(errorRoot, ".*/AssertionError$") { args: Array[String] =>
runDirSuiteTestCases(errorRoot, Glob("AssertionError/**.exec")) { args: Array[String] =>
assertThrows[AssertionError] {
CLIApp.run(args)
}
Expand All @@ -55,25 +60,25 @@ class CliAppErrors extends DirSuite {
* OK errors follows
*/

testDirSuite(errorRoot, ".*/InputFileNotFoundError$") { args: Array[String] =>
runDirSuiteTestCases(errorRoot, Glob("InputFileNotFoundError/**.exec")) { args: Array[String] =>
assertThrows[InputFileNotFoundError] {
CLIApp.run(args)
}
}

testDirSuite(errorRoot, ".*/InputError$") { args: Array[String] =>
runDirSuiteTestCases(errorRoot, Glob("InputError/**.exec")) { args: Array[String] =>
assertThrows[InputError] {
CLIApp.run(args)
}
}

testDirSuite(errorRoot, ".*/SettingsError$") { args: Array[String] =>
runDirSuiteTestCases(errorRoot, Glob("SettingsError/**.exec")) { args: Array[String] =>
assertThrows[SettingsError] {
CLIApp.run(args)
}
}

testDirSuite(errorRoot, ".*/ConstraintError$") { args: Array[String] =>
runDirSuiteTestCases(errorRoot, Glob("ConstraintError/**.exec")) { args: Array[String] =>
assertThrows[ConstraintError] {
CLIApp.run(args)
}
Expand Down
31 changes: 31 additions & 0 deletions cli/src/test/scala/co/uproot/abandon/DefaultArgsDirSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package co.uproot.abandon

import java.nio.file.Path

import fi.sn127.utils.testing.DirSuiteLike

/**
* Abandon specific default arguments for test cases.
*/
class DefaultArgsDirSuite extends DirSuiteLike {

/**
* Get configuration path based on name of current
* test case.
*
* Add conf-file and few other extra arguments to all
* test executions calls.
*/
override
protected def mapArgs(testname: Path, args: Array[String]): Array[String] = {
val fu = fi.sn127.utils.fs.FileUtils(testname.getFileSystem)
val testDir = fu.getParentDirPath(testname)

val basename = fu.getBasename(testname) match { case (base, ext) => base }
val conf = basename.toString + ".conf"

val fullPathConf = fu.getPath(testDir.toString, conf.toString).toString

Array("-c", fullPathConf) ++ Array("-X", "-q") ++ args
}
}
150 changes: 0 additions & 150 deletions cli/src/test/scala/co/uproot/abandon/DirSuite.scala

This file was deleted.

34 changes: 0 additions & 34 deletions cli/src/test/scala/co/uproot/abandon/TestComparator.scala

This file was deleted.

2 changes: 2 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ object Dependencies {
val scalaXMLVersion = "1.0.6"
val scalaParserCombinatorsVersion = "1.0.5"
val scalaFXVersion = "8.0.102-R11"
val dirSuiteVersion = "0.6.0"

// Libraries
val scalatest = "org.scalatest" %% "scalatest" % scalatestVersion
Expand All @@ -19,4 +20,5 @@ object Dependencies {
val scalaXML = "org.scala-lang.modules" %% "scala-xml" % scalaXMLVersion
val scalaParserCombinators = "org.scala-lang.modules" %% "scala-parser-combinators" % scalaParserCombinatorsVersion
val scalaFX = "org.scalafx" %% "scalafx" % scalaFXVersion
val dirSuite = "fi.sn127" %% "utils-testing" % dirSuiteVersion
}
2 changes: 2 additions & 0 deletions tests/errors/AssertionError/ae01.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/errors/ConstraintError/c01-pos.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/errors/ConstraintError/c02-neg.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/errors/InputError/ie-scope-01.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/errors/InputError/ie-scope-02.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/errors/InputError/ie02.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/errors/InputFileNotFoundError/ifnf01.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 0 additions & 2 deletions tests/errors/SettingsError/filters/f01.args

This file was deleted.

2 changes: 2 additions & 0 deletions tests/errors/SettingsError/filters/f01.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:--filter;asdf=2016-02-01;
2 changes: 0 additions & 2 deletions tests/errors/SettingsError/filters/f02.args

This file was deleted.

2 changes: 2 additions & 0 deletions tests/errors/SettingsError/filters/f02.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:--filter;before=2017-02-29;
2 changes: 2 additions & 0 deletions tests/errors/bugsInputError/pe01.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0001-balance/bal01.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0001-balance/bal02.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0001-balance/bal03.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0001-balance/bal04.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0002-ledger/all02.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0002-ledger/reports01.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0003-stdout/stdout.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0004-glob/glob01.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0005-def/acrossFiles/def.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0005-def/boolean/def.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
2 changes: 2 additions & 0 deletions tests/sclT0005-def/function/function.exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format: exec
exec:
Loading

0 comments on commit bd380c5

Please sign in to comment.