From 311615bc0a1d41d6ab6bb384864ceb927e58360b Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 23 Jul 2023 18:13:08 +0300 Subject: [PATCH 1/4] Add test that tries to add test compile dependency on custom source set This reproduces the issue reported in #116, where a `NullPointerException` is thrown. --- .../hdvl/svunit/SVUnitPluginSpec.groovy | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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 5d62d87..e49dbb1 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,31 @@ class SVUnitPluginSpec extends Specification { dummyLog.text.contains "-f ${testProjectDir.root}/build/full_test_xrun_args.f" } + def "'testWithXrun' uses full args file for source set dependency"() { + File mainSv = testProjectDir.newFolder('src', 'mocks', 'sv') + new File(mainSv, 'dummy_mocks.sv').createNewFile() + + buildFile << """ + sourceSets.register('mocks') + + dependencies { + testCompile files(genMocksXrunArgsFile.destination) + } + """ + + when: + def result = newGradleRunnerWithFakeRunSVunit() + .withProjectDir(testProjectDir.root) + .withPluginClasspath() + .withArguments('testWithXrun') + .build() + + then: + result.task(":testWithXrun").outcome == SUCCESS + def dummyLog = new File(testProjectDir.root, 'build/svunit/runSVUnit.log') + dummyLog.text.contains "-f ${testProjectDir.root}/build/full_mocks_xrun_args.f" + } + def "'check' task executes test tasks"() { File testSv = testProjectDir.newFolder('src', 'test', 'sv') new File(testSv, 'dummy_test.sv').createNewFile() From 2b5cdc1b4b796f5255d3c35eb49570c686e4ad27 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 23 Jul 2023 18:25:29 +0300 Subject: [PATCH 2/4] Avoid build failure due to non-existing directory for `test` source set --- .../gradle/hdvl/svunit/SVUnitPluginSpec.groovy | 2 ++ 1 file changed, 2 insertions(+) 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 e49dbb1..aff5689 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy @@ -369,6 +369,8 @@ class SVUnitPluginSpec extends Specification { } def "'testWithXrun' uses full args file for source set dependency"() { + File testSv = testProjectDir.newFolder('src', 'test', 'sv') + File mainSv = testProjectDir.newFolder('src', 'mocks', 'sv') new File(mainSv, 'dummy_mocks.sv').createNewFile() From fd0c22e877b3a875b33cfbefeb7b7aa0bed2a809 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 23 Jul 2023 18:32:40 +0300 Subject: [PATCH 3/4] Fix to check contents of full args file for args file of `mocks` We're checking too much by checking the contents of the full args, because this is handled by the base HDVL plugin. Without this check, though, the test would look kind of weird. --- .../gradle/hdvl/svunit/SVUnitPluginSpec.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 aff5689..52155de 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy @@ -368,7 +368,7 @@ class SVUnitPluginSpec extends Specification { dummyLog.text.contains "-f ${testProjectDir.root}/build/full_test_xrun_args.f" } - def "'testWithXrun' uses full args file for source set dependency"() { + def "'testWithXrun' uses args file for source set dependency"() { File testSv = testProjectDir.newFolder('src', 'test', 'sv') File mainSv = testProjectDir.newFolder('src', 'mocks', 'sv') @@ -391,8 +391,8 @@ class SVUnitPluginSpec extends Specification { then: result.task(":testWithXrun").outcome == SUCCESS - def dummyLog = new File(testProjectDir.root, 'build/svunit/runSVUnit.log') - dummyLog.text.contains "-f ${testProjectDir.root}/build/full_mocks_xrun_args.f" + def testFullXrunArgsFile = new File(testProjectDir.root, 'build/full_test_xrun_args.f') + testFullXrunArgsFile.text.contains "-f ${testProjectDir.root}/build/mocks_xrun_args.f" } def "'check' task executes test tasks"() { From 115b0519b109bdaf03cdff436a191db6ebb9a8e5 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 23 Jul 2023 18:37:09 +0300 Subject: [PATCH 4/4] Fix crash when specifying test compile dependency on source set The `getGroup()` and `getName()` methods may return `null`, for example in our case, where we don't specify a dependency on a module using `":"` coordinates. It's a common Java idiom to call `equals()` on the string constants, which we know are never `null`, instead of adding `null` checks. This makes for more compact code. --- .../verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 dcf2f88..ab4610c 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java @@ -96,7 +96,7 @@ private void configureSVUnitRootConfiguration(Project project) { } private boolean isSVUnit(Dependency dependency) { - return dependency.getGroup().equals("org.svunit") && dependency.getName().equals("svunit"); + return "org.svunit".equals(dependency.getGroup()) && "svunit".equals(dependency.getName()); } private void configureArgsFilesConfiguration(Project project, SourceSet testSourceSet, String toolName) {