1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.plugin
.multivm
;
12 import cc
.squirreljme
.plugin
.util
.TestDetection
;
14 import java
.util
.HashSet
;
18 import org
.gradle
.api
.internal
.file
.RelativeFile
;
19 import org
.gradle
.api
.internal
.tasks
.testing
.DefaultTestClassRunInfo
;
20 import org
.gradle
.api
.internal
.tasks
.testing
.TestClassProcessor
;
21 import org
.gradle
.api
.internal
.tasks
.testing
.detection
.TestFrameworkDetector
;
24 * Detects tests in the framework.
28 public class VMTestFrameworkDetector
29 implements TestFrameworkDetector
31 /** The test classes within. */
33 protected Set
<File
> testClasses
;
35 /** The classpath to use for tests. */
37 protected Set
<File
> testClasspath
;
39 /** The tests which are available. */
40 protected final Map
<String
, CandidateTestFiles
> tests
;
43 * Initializes the framework detector.
45 * @param __tests The tests that are available.
46 * @throws NullPointerException On null arguments.
49 public VMTestFrameworkDetector(Map
<String
, CandidateTestFiles
> __tests
)
50 throws NullPointerException
53 throw new NullPointerException("NARG");
63 public void startDetection(TestClassProcessor __processor
)
65 // Go through the available tests and register each one individually
66 Set
<String
> didBaseTest
= new HashSet
<>();
67 for (String test
: this.tests
.keySet())
69 // If this is a variant of a test, include the base test so
70 // Gradle actually knows it exists
71 int atSign
= test
.lastIndexOf('@');
74 String baseTest
= test
.substring(0, atSign
);
76 // If not added already, put it in
77 if (!didBaseTest
.contains(baseTest
))
79 __processor
.processTestClass(
80 new DefaultTestClassRunInfo(baseTest
));
81 didBaseTest
.add(baseTest
);
87 __processor
.processTestClass(
88 new DefaultTestClassRunInfo(test
));
93 * This is asking if the given test is something that would be run by
94 * this framework, in which case TAC is simple and is just prefixes and
97 * The actual output of this we probably do not really care for at all.
99 * @param __testClassFile The test class.
100 * @return If this is a test.
104 public boolean processTestClass(RelativeFile __testClassFile
)
106 // This will give for example io/MarkableInputStreamTest.class
107 String path
= __testClassFile
.getRelativePath().getPathString();
109 // Remove the suffix if there is any
110 if (path
.endsWith(".class"))
111 path
= path
.substring(0, path
.length() - ".class".length());
113 // If there is an at sign in this test then remove it since
114 int lastSlash
= path
.lastIndexOf('/');
115 int atSign
= path
.lastIndexOf('@');
116 if (atSign
>= 0 && atSign
> lastSlash
)
117 path
= path
.substring(0, atSign
);
119 // Remove the suffix if there is any, after @ removal since it may
120 // potentially appear twice
121 if (path
.endsWith(".class"))
122 path
= path
.substring(0, path
.length() - ".class".length());
124 // Normalize name for SquirrelJME, then check if this is something
126 return TestDetection
.isTest(path
.replace('/', '.'));