Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External DirSuite Mk3 #127

Merged
merged 1 commit into from
Jan 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the library prepend a hyphen automatically? If so, that seems inflexible. What if an option needs to be added which doesn't start with a hyphen?

Copy link
Contributor Author

@jaa127 jaa127 Jan 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't. It feeds arguments excatly as they are between ';' chars.
It is testing filter, which has command line in general form:
"--filter" "date=2017-01-01", but in this case, because it's an error test, it is using incorrect filter name. It has excatly same args than what it had with *.args file. So it is ok. =)

Here is link to documentation of exec-file:
https://github.com/sn127/utils/blob/master/docs/dirsuite.md#exec-file-format

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I finally understood. I was counting the - shown by the diff as part of the argument 🤦‍♂️

Looks correct now.

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