From 1e9118ea9582d24362247bcf700ea87ef3c5fea6 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Wed, 25 Jan 2023 19:45:33 +0200 Subject: [PATCH] Attach test tasks to `check` tasks Running `check` will trigger both `testWithQrun` and `testWithXrun`. This might cause issues when one of the simulators is not available. To combat this, we should only add tasks for the simulator that is present on `PATH`. --- .../gradle/hdvl/svunit/SVUnitPluginSpec.groovy | 17 +++++++++++++++++ .../gradle/hdvl/svunit/SVUnitPlugin.java | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy index c2c95e3..5b01ce0 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy @@ -368,6 +368,23 @@ class SVUnitPluginSpec extends Specification { dummyLog.text.contains "-f ${testProjectDir.root}/build/full_test_xrun_args.f" } + def "'check' task executes test tasks"() { + File testSv = testProjectDir.newFolder('src', 'test', 'sv') + new File(testSv, 'dummy_test.sv').createNewFile() + + when: + def result = newGradleRunnerWithFakeRunSVunit() + .withProjectDir(testProjectDir.root) + .withPluginClasspath() + .withArguments('check') + .build() + + then: + result.task(":check").outcome == SUCCESS + result.task(":testWithXrun").outcome == SUCCESS + result.task(":testWithQrun").outcome == SUCCESS + } + def newGradleRunnerWithFakeRunSVunit() { def runSVUnitFake = new File(getClass().getResource('/runSVUnit').toURI()) def env = System.getenv() diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java index 73a5aa7..fbe8f6a 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java @@ -32,6 +32,7 @@ import org.gradle.api.artifacts.Dependency; import org.gradle.api.internal.HasConvention; import org.gradle.api.reflect.TypeOf; +import org.gradle.api.tasks.TaskProvider; import org.gradle.util.GUtil; import java.io.File; @@ -130,7 +131,7 @@ private void configureTestTask(Project project, SourceSet mainSourceSet, SourceS GenFullArgsFile genFullTestArgsFile = (GenFullArgsFile) project.getTasks().getByName(testSourceSet.getGenFullArgsFileTaskName(toolName)); Configuration svUnitRoot = project.getConfigurations().getByName("svUnitRoot"); - project.getTasks().register(Names.getTestTaskName(toolName), TestTask.class, new Action() { + TaskProvider testTask = project.getTasks().register(Names.getTestTaskName(toolName), TestTask.class, new Action() { @Override public void execute(TestTask testTask) { testTask.setDescription("Runs the unit tests using SVUnit."); @@ -143,6 +144,7 @@ public void execute(TestTask testTask) { testTask.getExtraArgs().set(toolChains.getRunSVUnit().getArgs()); } }); + project.getTasks().getByName("check").dependsOn(testTask); } }