Skip to content

Commit d7816e5

Browse files
authored
Merge pull request #351 from recca0120/feature/colored-output
feat: enhance TextMate grammar for colored output channel
2 parents 01438e9 + e937874 commit d7816e5

File tree

5 files changed

+140
-29
lines changed

5 files changed

+140
-29
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "PHPUnit Test Explorer",
55
"icon": "img/icon.png",
66
"publisher": "recca0120",
7-
"version": "3.8.1",
7+
"version": "3.8.2",
88
"private": true,
99
"license": "MIT",
1010
"repository": {
@@ -49,7 +49,10 @@
4949
{
5050
"language": "phpunit",
5151
"scopeName": "source.phpunit",
52-
"path": "./syntaxes/phpunit.tmLanguage.json"
52+
"path": "./syntaxes/collision.tmLanguage.json",
53+
"embeddedLanguages": {
54+
"meta.embedded.php.phpunit": "php"
55+
}
5356
}
5457
],
5558
"commands": [

src/Observers/Printers/CollisionPrinter.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('CollisionPrinter', () => {
5959
duration: 0,
6060
});
6161

62-
expect(output).toEqual('✅ passed 0 ms');
62+
expect(output).toEqual(' ✅ passed 0 ms');
6363
});
6464

6565
it('testFailed', () => {
@@ -80,12 +80,12 @@ describe('CollisionPrinter', () => {
8080
duration: 0,
8181
});
8282

83-
expect(output).toEqual([`❌ failed 0 ms`].join(EOL));
83+
expect(output).toEqual([` ❌ failed 0 ms`].join(EOL));
8484

8585
expect(printer.end()).toEqual(
8686
[
8787
``,
88-
`❌ FAILED Recca0120\\VSCode\\Tests\\AssertionsTest > failed`,
88+
` ❌ FAILED Recca0120\\VSCode\\Tests\\AssertionsTest > failed`,
8989
`Failed asserting that false is true.`,
9090
``,
9191
`at ${OutputFormatter.fileFormat(phpUnitProject('tests/AssertionsTest.php'), 27)}`,
@@ -127,12 +127,12 @@ describe('CollisionPrinter', () => {
127127
expected: "Array &0 [\n 'a' => 'b',\n 'c' => 'd',\n]",
128128
});
129129

130-
expect(output).toEqual([`❌ is_not_same 29 ms`].join(EOL));
130+
expect(output).toEqual([` ❌ is_not_same 29 ms`].join(EOL));
131131

132132
expect(printer.end()).toEqual(
133133
[
134134
``,
135-
`❌ FAILED Recca0120\\VSCode\\Tests\\AssertionsTest > is_not_same`,
135+
` ❌ FAILED Recca0120\\VSCode\\Tests\\AssertionsTest > is_not_same`,
136136
`Failed asserting that two arrays are identical.`,
137137
` Array &0 [`,
138138
`- 'a' => 'b',`,
@@ -208,12 +208,12 @@ describe('CollisionPrinter', () => {
208208
duration: 0,
209209
});
210210

211-
expect(output).toEqual([`❌ failed 0 ms`].join(EOL));
211+
expect(output).toEqual([` ❌ failed 0 ms`].join(EOL));
212212

213213
expect(printer.end()).toEqual(
214214
[
215215
``,
216-
`❌ FAILED Recca0120\\VSCode\\Tests\\NotFoundTest > failed`,
216+
` ❌ FAILED Recca0120\\VSCode\\Tests\\NotFoundTest > failed`,
217217
`Failed asserting that false is true.`,
218218
``,
219219
`1. ${OutputFormatter.fileFormat(phpUnitProject('tests/NotFoundTest.php'), 22)}`,
@@ -251,7 +251,7 @@ describe('CollisionPrinter', () => {
251251
});
252252

253253
expect(output).toEqual(
254-
[`➖ skipped ➜ The MySQLi extension is not available. 0 ms`].join(EOL),
254+
[` ➖ skipped ➜ The MySQLi extension is not available. 0 ms`].join(EOL),
255255
);
256256
});
257257
});

src/Observers/Printers/CollisionPrinter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export class CollisionPrinter extends OutputFormatter {
2626
}
2727

2828
if (result.event === TeamcityEvent.testIgnored) {
29-
return `${icon} ${name}${(result as TestIgnored).message} ${result.duration} ms`;
29+
return ` ${icon} ${name}${(result as TestIgnored).message} ${result.duration} ms`;
3030
}
3131

32-
return `${icon} ${name} ${result.duration} ms`;
32+
return ` ${icon} ${name} ${result.duration} ms`;
3333
}
3434

3535
testSuiteFinished(_result: TestSuiteFinished): string | undefined {
@@ -61,11 +61,11 @@ export class CollisionPrinter extends OutputFormatter {
6161
const [icon, message] = this.messages.get(result.event)!;
6262
const parts = result.id.split('::');
6363
if (parts.length < 2) {
64-
return `${icon} ${message} ${result.id}`;
64+
return ` ${icon} ${message} ${result.id}`;
6565
}
6666

6767
const [className, method] = parts;
68-
return `${icon} ${message} ${className} > ${method.replace(/^test_/, '')}`;
68+
return ` ${icon} ${message} ${className} > ${method.replace(/^test_/, '')}`;
6969
}
7070

7171
private formatMessage(result: TestFailed) {

syntaxes/collision.tmLanguage.json

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"name": "PHPUnit",
4+
"patterns": [
5+
{
6+
"comment": "Passed test line → green",
7+
"match": "^\\s+✅\\s+.+\\d+\\s*ms",
8+
"name": "markup.inserted.phpunit"
9+
},
10+
{
11+
"comment": "Failed test line → red (ends with ms)",
12+
"match": "^\\s+❌\\s+.+\\d+\\s*ms",
13+
"name": "invalid.phpunit"
14+
},
15+
{
16+
"comment": "Ignored/skipped test line → yellow",
17+
"match": "^\\s+➖\\s+.+",
18+
"name": "markup.deleted.phpunit"
19+
},
20+
{
21+
"comment": "FAILED error title → only icon+FAILED red, rest default",
22+
"match": "^(\\s+❌\\s+FAILED)(\\s+.+)",
23+
"captures": {
24+
"1": { "name": "invalid.phpunit" }
25+
}
26+
},
27+
{
28+
"comment": "Error line without indent → red",
29+
"match": "^❌\\s+.+",
30+
"name": "invalid.phpunit"
31+
},
32+
{
33+
"comment": "Printed output → yellow",
34+
"match": "^🟨\\s+.+",
35+
"name": "markup.deleted.phpunit"
36+
},
37+
{
38+
"comment": "Arrow source line → arrow+number highlighted, ▕ gray, code PHP",
39+
"match": "(➜\\s+\\d+\\s+)(▕)(\\s?.*$)",
40+
"captures": {
41+
"1": { "name": "keyword.phpunit" },
42+
"2": { "name": "comment.phpunit" },
43+
"3": {
44+
"name": "meta.embedded.php.phpunit",
45+
"patterns": [{ "include": "source.php" }]
46+
}
47+
}
48+
},
49+
{
50+
"comment": "Source line → line number gray, ▕ gray, code PHP",
51+
"match": "(\\s+\\d+\\s+)(▕)(\\s?.*$)",
52+
"captures": {
53+
"1": { "name": "comment.phpunit" },
54+
"2": { "name": "comment.phpunit" },
55+
"3": {
56+
"name": "meta.embedded.php.phpunit",
57+
"patterns": [{ "include": "source.php" }]
58+
}
59+
}
60+
},
61+
{
62+
"comment": "at file reference → link",
63+
"match": "^at\\s+\\S+\\.php:\\d+",
64+
"name": "string.link.phpunit"
65+
},
66+
{
67+
"comment": "File path links",
68+
"match": "\\S+\\.php:\\d+",
69+
"name": "string.link.phpunit"
70+
},
71+
{
72+
"comment": "Diff removed line → red",
73+
"match": "^-\\s+.+",
74+
"name": "invalid.phpunit"
75+
},
76+
{
77+
"comment": "Diff added line → green",
78+
"match": "^\\+\\s+.+",
79+
"name": "markup.inserted.phpunit"
80+
},
81+
{
82+
"comment": "PrettyPrinter box lines → gray",
83+
"match": "^\\s+[┐├│┴┊].*",
84+
"name": "comment.phpunit"
85+
},
86+
{
87+
"comment": "Pest summary: N failed → red",
88+
"match": "\\d+\\s+failed",
89+
"name": "invalid.phpunit"
90+
},
91+
{
92+
"comment": "Pest summary: N passed → green",
93+
"match": "\\d+\\s+passed",
94+
"name": "markup.inserted.phpunit"
95+
},
96+
{
97+
"comment": "Pest summary: N skipped → yellow",
98+
"match": "\\d+\\s+skipped",
99+
"name": "markup.deleted.phpunit"
100+
},
101+
{
102+
"comment": "PHPUnit summary: Errors/Failures → red",
103+
"match": "(Errors|Failures):\\s+\\d+",
104+
"name": "invalid.phpunit"
105+
},
106+
{
107+
"comment": "PHPUnit summary: Skipped/Incomplete/Risky/Warnings/Deprecations → yellow",
108+
"match": "(Skipped|Incomplete|Risky|Warnings|PHPUnit Deprecations):\\s+\\d+",
109+
"name": "markup.deleted.phpunit"
110+
},
111+
{
112+
"comment": "Info lines → gray",
113+
"match": "^(Time|Duration|Runtime|Configuration|Processes):.*",
114+
"name": "comment.phpunit"
115+
},
116+
{
117+
"comment": "Duration at end of line → gray",
118+
"match": "\\d+\\s*ms$",
119+
"name": "comment.phpunit"
120+
}
121+
],
122+
"scopeName": "source.phpunit"
123+
}

syntaxes/phpunit.tmLanguage.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)