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

Feature: Add compiler option for test generation #9

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ jobs:
target/graalvm-native-image/baboon \
--model-dir ./src/test/resources/baboon/ \
--output ./test/cs-stub/ConversionsTest/Generated \
--test-output ./test/cs-stub/ConversionsTest/Generated
--test-output ./test/cs-stub/ConversionsTest/Generated/tests \
--gen-tests
cd ./test/cs-stub
dotnet build
dotnet test ConversionsTest/ConversionsTest.csproj
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/io/septimalmind/baboon/Baboon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ case class Options(
"do not generate usings for System, System.Collections.Generic and System.Linq (see ImplicitUsings)"
)
csExcludeGlobalUsings: Option[Boolean],
genTests: Option[Boolean]
)

sealed trait RuntimeGenOpt
Expand Down Expand Up @@ -64,6 +65,7 @@ object Baboon {
rtOpt,
!opts.disableConversions.getOrElse(false),
!opts.csExcludeGlobalUsings.getOrElse(false),
opts.genTests.getOrElse(false)
)
Injector.NoCycles().produceRun(new BaboonModule(options)) {
(compiler: BaboonCompiler) =>
Expand Down
18 changes: 10 additions & 8 deletions src/main/scala/io/septimalmind/baboon/BaboonCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@ trait BaboonCompiler {
}

object BaboonCompiler {
case class CompilerOptions(debug: Boolean,
obsoleteErrors: Boolean,
runtime: RuntimeGenOpt,
generateConversions: Boolean,
disregardImplicitUsings: Boolean,
)
case class CompilerOptions(
debug: Boolean,
obsoleteErrors: Boolean,
runtime: RuntimeGenOpt,
generateConversions: Boolean,
disregardImplicitUsings: Boolean,
generateTests: Boolean
)

class BaboonCompilerImpl(loader: BaboonLoader,
translator: CSBaboonTranslator,
options: CompilerOptions,
logger: BLogger,
) extends BaboonCompiler {
) extends BaboonCompiler {
override def run(inputs: Set[Path],
output: Path,
testOutput: Option[Path],
): Either[NEList[BaboonIssue], Unit] = {
): Either[NEList[BaboonIssue], Unit] = {
for {
loaded <- loader.load(inputs.toList)
translated <- translator.translate(loaded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DefEnum(context: ParserContext, meta: DefMeta) {
def enumVal[$: P]: P[RawEnumConst] = {
import fastparse.ScalaWhitespace.whitespace
(P("=") ~ constInt).map { v =>
RawEnumConst.RawInt(v)
RawEnumConst.RawInt(v.toLong)
}
}
def enumMember[$: P]: P[RawEnumMember] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ class CSBaboonTranslator(
}

private def sharedRuntime(): Out[List[CSDefnTranslator.Output]] = {
val metaFields =
(List(q"String id") ++ codecs.toList
.sortBy(_.getClass.getName)
.map(_.metaField())).join(", ")

val base =
q"""public interface IBaboonGenerated {
| public $csString BaboonDomainVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ object CSDefnTranslator {
.map(codec => q"${codec.codecName(srcRef).copy(fq = true)}.Instance"))
.join(", ")

val codecTestTrees = codecsTests.translate(defn, csTypeRef, srcRef, domain)
val codecTestTrees =
if (options.generateTests) codecsTests.translate(defn, csTypeRef, srcRef, domain)
else None
val codecTestWithNS = codecTestTrees.map(tools.inNs(ns.toSeq, _))
val codecTestOut = codecTestWithNS.map(
codecTestWithNS =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ abstract class BaboonTest extends Spec1[Identity] {
runtime = RuntimeGenOpt.With,
generateConversions = true,
disregardImplicitUsings = true,
generateTests = true
)
).morph[PluginBase]
)
Expand Down