-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
409 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
common { | ||
show-times = true | ||
verbose = false | ||
quiet = false | ||
debug = true | ||
dry-run = false | ||
show-warnings = true | ||
show-missing-warnings = false | ||
show-style-warnings = false | ||
} | ||
|
||
test-pass-command { | ||
input-file = "test.riddl" | ||
output-directory = "target/test-output" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
common { | ||
show-times = true | ||
verbose = false | ||
quiet = false | ||
debug = true | ||
dry-run = false | ||
show-warnings = true | ||
show-missing-warnings = false | ||
show-style-warnings = false | ||
} | ||
|
||
test-pass-command { | ||
input-file = "test.riddl" | ||
} |
1 change: 1 addition & 0 deletions
1
...com.ossuminc.riddl.commands.CommandPlugin → .../com.ossuminc.riddl.command.CommandPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
com.ossuminc.riddl.command.TestPassCommand | ||
com.ossuminc.riddl.command.ASimpleTestCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
command/src/test/scala/com/ossuminc/riddl/command/PassCommandTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.ossuminc.riddl.command | ||
|
||
import java.nio.file.Path | ||
import com.ossuminc.riddl.language.Messages | ||
import org.scalatest.exceptions.TestFailedException | ||
|
||
class PassCommandTest extends CommandTestBase { | ||
|
||
override val confFile = s"$inputDir/test-pass-command.conf" | ||
|
||
"PassCommandOptions" must { | ||
"check content" in { | ||
val pco = TestPassCommand.Options( | ||
Some(Path.of("command/src/test/input/simple.riddl")), | ||
None | ||
) | ||
val messages = pco.check | ||
messages.size must be(2) | ||
val message_text = messages.format | ||
message_text must include("An output directory was not provided") | ||
message_text must include("check called") | ||
} | ||
} | ||
|
||
"PassCommand" must { | ||
"check filled options" in { | ||
pending // fails to find command when run in parallel :( | ||
CommandPlugin.loadCommandNamed(TestPassCommand.name) match { | ||
case Left(messages) => fail(messages.format) | ||
case Right(plugin: CommandPlugin[TestPassCommand.Options] @unchecked) => | ||
val expected = TestPassCommand.Options( | ||
Some(Path.of("test.riddl")), | ||
Some(Path.of("target/test-output")) | ||
) | ||
super.check[TestPassCommand.Options](plugin, expected) { (options: TestPassCommand.Options) => | ||
val messages = options.check | ||
messages.size must be(1) | ||
messages.head.message must include("check called") | ||
} | ||
} | ||
} | ||
"check empty input options" in { | ||
pending // fails to find command when run in parallel :( | ||
CommandPlugin.loadCommandNamed(TestPassCommand.name) match { | ||
case Left(messages) => fail(messages.format) | ||
case Right(plugin: CommandPlugin[TestPassCommand.Options] @unchecked) => | ||
val expected = TestPassCommand.Options( | ||
Some(Path.of("test.riddl")), | ||
Some(Path.of("none")) | ||
) | ||
val path = Path.of(s"$inputDir/test-pass-command2.conf") | ||
intercept[TestFailedException] { | ||
super.check[TestPassCommand.Options](plugin, expected, path) { (options: TestPassCommand.Options) => | ||
val messages = options.check | ||
messages.size must be(1) | ||
messages(0).message must include("check called") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
command/src/test/scala/com/ossuminc/riddl/command/TestPassCommand.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.ossuminc.riddl.command | ||
|
||
import com.ossuminc.riddl.language.{At, CommonOptions, Messages} | ||
import com.ossuminc.riddl.passes.{Pass, PassOptions, PassesCreator, TestPass} | ||
import com.ossuminc.riddl.utils.Logger | ||
import pureconfig.{ConfigCursor, ConfigReader} | ||
import scopt.{OParser, OParserBuilder} | ||
|
||
import java.io.File | ||
import java.nio.file.Path | ||
|
||
case class TestPassCommand() extends PassCommand[TestPassCommand.Options](TestPassCommand.name): | ||
override def getPasses(log: Logger, commonOptions: CommonOptions, options: TestPassCommand.Options): PassesCreator = | ||
Pass.standardPasses :+ TestPass.creator(options) | ||
|
||
override def overrideOptions(options: TestPassCommand.Options, newOutputDir: Path): TestPassCommand.Options = | ||
options.copy(outputDir = Some(newOutputDir)) | ||
|
||
override def getOptions: (OParser[Unit, TestPassCommand.Options], TestPassCommand.Options) = | ||
TestPassCommand.optionsParser | ||
|
||
override def getConfigReader: ConfigReader[TestPassCommand.Options] = TestPassCommand.configReader | ||
|
||
object TestPassCommand { | ||
val name = "test-pass-command" | ||
|
||
case class Options(inputFile: Option[Path], outputDir: Option[Path]) extends PassCommandOptions with PassOptions { | ||
override def check: Messages.Messages = { | ||
super.check ++ Seq(Messages.info("check called", At())) | ||
} | ||
def command: String = TestPassCommand.name | ||
} | ||
|
||
def optionsParser: (OParser[Unit, Options], Options) = { | ||
val builder: OParserBuilder[Options] = scopt.OParser.builder[Options] | ||
import builder.* | ||
|
||
cmd(TestPassCommand.name) | ||
.children( | ||
builder | ||
.arg[File]("input-file") | ||
.action { (file, opt) => opt.copy(inputFile = Some(file.toPath)) } | ||
.text("The input to be parsed"), | ||
arg[String]("output-directory") | ||
.action { (dir, opt) => opt.copy(outputDir = Some(Path.of(dir))) } | ||
.text("The path to the directory where the output will be placed") | ||
) | ||
.text("Just used for testing") -> Options(None, None) | ||
} | ||
|
||
def configReader: ConfigReader[Options] = { (cur: ConfigCursor) => | ||
for | ||
topCur <- cur.asObjectCursor | ||
topRes <- topCur.atKey(name) | ||
objCur <- topRes.asObjectCursor | ||
inFileRes <- objCur.atKey("input-file").map(_.asString) | ||
inFile <- inFileRes | ||
targetRes <- objCur.atKey("output-directory").map(_.asString) | ||
target <- targetRes | ||
yield { | ||
Options(inputFile = Some(Path.of(inFile)), outputDir = Some(Path.of(target))) | ||
} | ||
} | ||
} |
Oops, something went wrong.