дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
Порівняти коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
1634cd8e84 |
No files matched your search
@@ -51,7 +51,8 @@ with tempfile.TemporaryDirectory() as scratch:
|
||||
"##teamcity[testFailed name='fails' className='sample.SampleTest' message='org.opentest4j.AssertionFailedError: it|'s wrong ==> expected: <1> but was: <2>'",
|
||||
"##teamcity[testIgnored name='disabled' className='sample.SampleTest'",
|
||||
"##teamcity[testIgnored name='aborted' className='sample.SampleTest']",
|
||||
"##teamcity[testFailed name='parameterized' className='sample.SampleTest'",
|
||||
"##teamcity[testStarted name='parameterized' className='sample.SampleTest' invocation='|[1|] 1']",
|
||||
"##teamcity[testFailed name='parameterized' className='sample.SampleTest' invocation='|[2|] 2'",
|
||||
"##teamcity[testFinished name='nested' className='sample.SampleTest$Inner' duration=",
|
||||
"7 tests completed, 2 failed, 2 skipped",
|
||||
]
|
||||
|
||||
Бінарний файл не відображається.
@@ -153,18 +153,25 @@ final class PlatformRunner implements TestExecutionListener {
|
||||
for (Output o : outputs) o.flushLines(true);
|
||||
}
|
||||
|
||||
/** `name='method' className='a.B$Nested'`, the method and class of the test or its closest source. */
|
||||
/**
|
||||
* `name='method' className='a.B$Nested'`, the method and class of the test or its closest source;
|
||||
* an invocation of a parameterized, repeated or dynamic test adds `invocation='[1] a'`, its display name.
|
||||
*/
|
||||
private String id(TestIdentifier id) {
|
||||
// The outermost method of the chain: the test itself, or the method container of its invocations.
|
||||
TestIdentifier method = null;
|
||||
for (TestIdentifier at = id; at != null; at = plan.getParent(at).orElse(null)) {
|
||||
TestSource source = at.getSource().orElse(null);
|
||||
if (source instanceof MethodSource) {
|
||||
MethodSource m = (MethodSource) source;
|
||||
return Reporter.attr("name", m.getMethodName()) + Reporter.attr("className", m.getClassName());
|
||||
}
|
||||
if (source instanceof ClassSource)
|
||||
if (source instanceof MethodSource) method = at;
|
||||
else if (method != null) break;
|
||||
else if (source instanceof ClassSource)
|
||||
return Reporter.attr("name", id.getLegacyReportingName()) + Reporter.attr("className", ((ClassSource) source).getClassName());
|
||||
}
|
||||
return Reporter.attr("name", id.getLegacyReportingName()) + Reporter.attr("className", id.getDisplayName());
|
||||
if (method == null)
|
||||
return Reporter.attr("name", id.getLegacyReportingName()) + Reporter.attr("className", id.getDisplayName());
|
||||
MethodSource m = (MethodSource) method.getSource().get();
|
||||
String own = Reporter.attr("name", m.getMethodName()) + Reporter.attr("className", m.getClassName());
|
||||
return method == id ? own : own + Reporter.attr("invocation", id.getDisplayName());
|
||||
}
|
||||
|
||||
private Optional<String> className(TestIdentifier id) {
|
||||
|
||||
@@ -12,6 +12,17 @@ def tc = { String s ->
|
||||
.replace('[', '|[').replace(']', '|]')
|
||||
}
|
||||
|
||||
// `name='method(Type)[1]' className='a.B'`; an invocation of a parameterized, repeated or dynamic
|
||||
// test (its parent is the method, not the class) adds `invocation='[1] a'`, its display name.
|
||||
def id = { TestDescriptor test ->
|
||||
def own = "name='${tc(test.name)}' className='${tc(test.className)}'"
|
||||
def parent = test.parent
|
||||
if (parent == null || parent.className != test.className || parent.name == test.className) return own
|
||||
// `getDisplayName` is Gradle 4.10+.
|
||||
def shown = test.hasProperty('displayName') ? test.displayName : test.name
|
||||
"${own} invocation='${tc(shown)}'"
|
||||
}
|
||||
|
||||
allprojects {
|
||||
each(tasks.withType(Test)) { Test task ->
|
||||
task.outputs.upToDateWhen { false }
|
||||
@@ -21,29 +32,29 @@ allprojects {
|
||||
void afterSuite(TestDescriptor suite, TestResult result) {}
|
||||
|
||||
void beforeTest(TestDescriptor test) {
|
||||
println "##teamcity[testStarted name='${tc(test.name)}' className='${tc(test.className)}']"
|
||||
println "##teamcity[testStarted ${id(test)}]"
|
||||
}
|
||||
|
||||
void afterTest(TestDescriptor test, TestResult result) {
|
||||
def id = "name='${tc(test.name)}' className='${tc(test.className)}'"
|
||||
def own = id(test)
|
||||
def type = result.resultType.toString()
|
||||
if (type == 'FAILURE') {
|
||||
def error = result.exception
|
||||
def trace = new StringWriter()
|
||||
error?.printStackTrace(new PrintWriter(trace))
|
||||
println "##teamcity[testFailed ${id} message='${tc(error?.toString())}' details='${tc(trace.toString())}']"
|
||||
println "##teamcity[testFailed ${own} message='${tc(error?.toString())}' details='${tc(trace.toString())}']"
|
||||
} else if (type == 'SKIPPED') {
|
||||
println "##teamcity[testIgnored ${id}]"
|
||||
println "##teamcity[testIgnored ${own}]"
|
||||
}
|
||||
println "##teamcity[testFinished ${id} duration='${result.endTime - result.startTime}']"
|
||||
println "##teamcity[testFinished ${own} duration='${result.endTime - result.startTime}']"
|
||||
}
|
||||
})
|
||||
task.addTestOutputListener(new TestOutputListener() {
|
||||
void onOutput(TestDescriptor test, TestOutputEvent output) {
|
||||
if (test.className == null) return
|
||||
// A class's own output (`@BeforeAll`, `@AfterAll`) carries no test name.
|
||||
def name = test.composite ? '' : " name='${tc(test.name)}'"
|
||||
println "##teamcity[testStdOut${name} className='${tc(test.className)}' out='${tc(output.message)}']"
|
||||
def own = test.composite ? "className='${tc(test.className)}'" : id(test)
|
||||
println "##teamcity[testStdOut ${own} out='${tc(output.message)}']"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -32,7 +32,9 @@ function frameLocation(line: string): TestLocation | null {
|
||||
|
||||
/**
|
||||
* Test events of the init script's messages. Tests are `[class, method]`, named as in the XML reports
|
||||
* (`add(int, int)[1]` → `add`); `outcomes` keeps each test's failure or skip until it finishes.
|
||||
* (`add(int, int)` → `add`), and an invocation of a parameterized, repeated or dynamic test is
|
||||
* `[class, method, "[1] a"]` (its `invocation`, the display name); `outcomes` keeps each test's
|
||||
* failure or skip until it finishes.
|
||||
*/
|
||||
function initScriptEvents({ kind, attrs }: ServiceMessage, outcomes: Map<string, "failed" | "skipped">): TestEvent[] {
|
||||
if (!attrs.className) return [];
|
||||
@@ -43,8 +45,9 @@ function initScriptEvents({ kind, attrs }: ServiceMessage, outcomes: Map<string,
|
||||
// A class's own output (`@BeforeAll`, `@AfterAll`) belongs to the class.
|
||||
if (!attrs.name) return kind === "testStdOut" || kind === "testStdErr" ? printed([attrs.className]) : [];
|
||||
const path = [attrs.className, attrs.name.split("(")[0]!.trim() || attrs.name];
|
||||
if (attrs.invocation) path.push(attrs.invocation);
|
||||
const key = path.join("\0");
|
||||
// A parameterized method's invocations share its node: one failure fails the method.
|
||||
// Invocations without a name of their own share the method's node: one failure fails the method.
|
||||
const failed = outcomes.get(key) === "failed";
|
||||
switch (kind) {
|
||||
case "testStarted":
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
type TestOutputParser,
|
||||
} from "./index";
|
||||
import { moveToReportedClasses } from "./jvm";
|
||||
import { failedTestPaths } from "./rerun";
|
||||
|
||||
function results(parser: TestOutputParser, text: string) {
|
||||
const r = new TestResults();
|
||||
@@ -589,6 +590,31 @@ CalcTest > fails() FAILED
|
||||
expect(r.hasResult(["demo.CalcTest", "other"])).toBe(false);
|
||||
});
|
||||
|
||||
it("shows each invocation of a parameterized test under its method", () => {
|
||||
const r = results(
|
||||
jvmParser(),
|
||||
`##teamcity[testStarted name='accepts' className='demo.ParamTest' invocation='|[1|] a']
|
||||
##teamcity[testFinished name='accepts' className='demo.ParamTest' invocation='|[1|] a' duration='2']
|
||||
##teamcity[testStarted name='accepts' className='demo.ParamTest' invocation='|[2|] bb']
|
||||
##teamcity[testStdOut name='accepts' className='demo.ParamTest' invocation='|[2|] bb' out='checking bb|n']
|
||||
##teamcity[testFailed name='accepts' className='demo.ParamTest' invocation='|[2|] bb' message='no' details='org.opentest4j.AssertionFailedError: no|n\tat app//demo.ParamTest.accepts(ParamTest.java:12)|n']
|
||||
##teamcity[testFinished name='accepts' className='demo.ParamTest' invocation='|[2|] bb' duration='1']
|
||||
##teamcity[testStarted name='accepts(String)|[3|]' className='demo.ParamTest' invocation='|[3|] c']
|
||||
##teamcity[testFinished name='accepts(String)|[3|]' className='demo.ParamTest' invocation='|[3|] c' duration='1']
|
||||
`,
|
||||
);
|
||||
const method = leaf(r, "demo.ParamTest", "accepts")!;
|
||||
expect(method.children.map((n) => n.name)).toEqual(["[1] a", "[2] bb", "[3] c"]);
|
||||
expect(nodeStatus(method)).toBe("failed");
|
||||
expect(leaf(r, "demo.ParamTest", "accepts", "[1] a")).toMatchObject({ own: "passed", durationMs: 2, output: [] });
|
||||
const failed = leaf(r, "demo.ParamTest", "accepts", "[2] bb")!;
|
||||
expect(failed.own).toBe("failed");
|
||||
expect(failed.output.slice(0, 2)).toEqual(["checking bb", "org.opentest4j.AssertionFailedError: no"]);
|
||||
expect(failed.location).toMatchObject({ path: "demo/ParamTest.java", line: 12 });
|
||||
expect(leaf(r, "demo.ParamTest", "accepts", "[3] c")?.own).toBe("passed");
|
||||
expect(failedTestPaths(r)).toEqual([["demo.ParamTest", "accepts", "[2] bb"]]);
|
||||
});
|
||||
|
||||
it("gives a class's own output from the gradle init script to the class", () => {
|
||||
const r = results(
|
||||
jvmParser(),
|
||||
|
||||
@@ -244,6 +244,15 @@ describe("rerunFailedConfig", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("jvm: a failed invocation of a parameterized test reruns its method", async () => {
|
||||
expect(
|
||||
(await rerunFailedConfig(cfg("gradle", "./gradlew", ["test"]), [
|
||||
["com.a.FooTest", "add", "[2] b"],
|
||||
["com.a.FooTest", "add", "[3] c"],
|
||||
]))!.args,
|
||||
).toEqual(["test", "--tests", "com.a.FooTest.add"]);
|
||||
});
|
||||
|
||||
it("maven: a rerun replaces the previous selection and lets modules without the tests pass", async () => {
|
||||
const narrowed = cfg("maven", "./mvnw", [
|
||||
"test",
|
||||
|
||||
@@ -153,9 +153,8 @@ function goArgs(base: string[], paths: string[][], file?: string): string[] | nu
|
||||
}
|
||||
|
||||
function jvmArgs(config: RunConfig, paths: string[][]): string[] | null {
|
||||
const tests = paths
|
||||
.filter((p) => p.length >= 2)
|
||||
.map((p) => ({ cls: p[0]!, method: p[p.length - 1]!.replace(/\(\)$/, "") }));
|
||||
// `[class, method]`, or `[class, method, invocation]`: an invocation reruns its method.
|
||||
const tests = paths.filter((p) => p.length >= 2).map((p) => ({ cls: p[0]!, method: p[1]!.replace(/\(.*\)$/, "") }));
|
||||
const classes = unique(paths.filter((p) => p.length === 1).map((p) => p[0]!));
|
||||
if (!tests.length && !classes.length) return null;
|
||||
if (isJunitRunner(config)) {
|
||||
|
||||
Reference in new issue
Заблокувати користувача