Limit how often GC can be run.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / multivm / VMModernTestTask.java
blob1b293d76623cfaac049aa5afd613137d43e695ae
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 Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.plugin.multivm;
12 import cc.squirreljme.plugin.multivm.ident.SourceTargetClassifier;
13 import cc.squirreljme.plugin.util.SingleTaskOutputFile;
14 import javax.inject.Inject;
15 import lombok.Getter;
16 import org.gradle.api.tasks.Internal;
17 import org.gradle.api.tasks.testing.Test;
18 import org.gradle.api.tasks.testing.TestTaskReports;
19 import org.gradle.workers.WorkerExecutor;
21 /**
22 * Not Described.
24 * @since 2022/09/11
26 public class VMModernTestTask
27 extends Test
28 implements VMBaseTask, VMExecutableTask
30 /** The classifier used. */
31 @Internal
32 @Getter
33 protected final SourceTargetClassifier classifier;
35 /**
36 * Initializes the task.
38 * @param __executor The executor for the task.
39 * @param __classifier The classifier used.
40 * @param __libTask The task used to create libraries, this may be directly
41 * depended upon.
42 * @since 2020/08/07
44 @Inject
45 public VMModernTestTask(WorkerExecutor __executor,
46 SourceTargetClassifier __classifier, VMLibraryTask __libTask)
47 throws NullPointerException
49 if (__executor == null || __classifier == null || __libTask == null)
50 throw new NullPointerException("NARG");
52 // These are used at the test stage
53 this.classifier = __classifier;
55 // Set details of this task
56 this.setGroup("squirreljme");
57 this.setDescription("Runs the various automated tests (modern).");
59 // Use our custom test framework?
60 this.getTestFrameworkProperty().set(
61 new VMTestFramework(this, __classifier));
63 // Depends on the library to exist first along with the emulator
64 // itself
65 this.dependsOn(this.getProject().provider(
66 new VMRunDependencies(this.getProject(), __classifier)),
67 new VMEmulatorDependencies(this.getProject(),
68 __classifier.getTargetClassifier()));
70 // Add the entire JAR as input, so that if it changes for any reason
71 // then all tests should be considered invalid and rerun
72 // All the input source files to be tested
73 this.getInputs().files(
74 this.getProject().provider(
75 new SingleTaskOutputFile(__libTask)),
76 this.getProject().provider(
77 new VMTestInputs(this, __classifier.getSourceSet())));
79 // All the test results that are created
80 this.getOutputs().files(this.getProject().provider(
81 new VMTestOutputs(this, __classifier)));
83 // Add additional testing to see if our test run will not be up-to-
84 // date when we run these. Also, this is never up-to-date if
85 // test.single/single.test is used because we do not want to
86 // interfere with the caching or not running tests in such
87 // situations.
88 this.getOutputs().upToDateWhen((__task) ->
90 return new VMRunUpToDateWhen(__classifier)
91 .isSatisfiedBy(__task) &&
92 !VMHelpers.runningTests(__task.getProject(),
93 __classifier.getSourceSet()).isSingle;
94 });
96 // Only run if there are actual tests to run
97 this.onlyIf(new CheckForTests(__classifier.getSourceSet()));
99 // Maximum forks, limited accordingly
100 this.setMaxParallelForks(VMTestTaskAction.maxParallelTests());
102 // Change location of JUnit XML reports, to match legacy output
103 TestTaskReports reports = this.getReports();
104 reports.getJunitXml().getOutputLocation().set(
105 VMHelpers.testResultXmlDir(this.getProject(), __classifier)
106 .get().toFile());
108 // Each individual test case has its own output, as is traditional for
109 // SquirrelJME. This ends up being easier to read and is much better
110 // when there are parameters to tests.
111 reports.getJunitXml().setOutputPerTestCase(true);
113 // Always show streams
114 this.getTestLogging().setShowStandardStreams(true);
116 // For extra debugging
117 this.getTestLogging().setShowExceptions(true);
118 this.getTestLogging().setShowStackTraces(true);
119 this.getTestLogging().setShowCauses(true);