-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathrobot.ts
767 lines (756 loc) · 20 KB
/
robot.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
import { filepaths } from "@fig/autocomplete-generators";
const tagsGenerator: Fig.Generator = {
script: [
"bash",
"-c",
'for i in $(find -E . -regex ".*.robot" -type f); do cat -s $i ; done',
],
postProcess: (out) => {
// find all lines with tags
// regex: line that starts with 2+ spaces, than '[Tags] ' and words
const iter = out.matchAll(/(?:^\s\s+\[Tags\])\s\s+(\w+ *)*(?!.\#.*)/gm);
const seen: Set<string> = new Set();
const suggestions: Fig.Suggestion[] = [];
for (const [line] of iter) {
// original line: " [Tags] first tag dev tag some tag "
// desired line: ["first tag", "dev tag", "some tag"]
for (const tag of line.trim().substring(6).trim().split(/\s\s+/)) {
if (seen.has(tag)) continue;
seen.add(tag);
suggestions.push({
name: tag,
description: "Tag",
icon: "🏷",
});
}
}
return suggestions;
},
};
const variablesGenerator: Fig.Generator = {
trigger: ":",
custom: async (tokens, executeShellCommand) => {
const finalToken = tokens[tokens.length - 1];
const isKey = !finalToken.includes(":");
if (!isKey) return [];
const { stdout } = await executeShellCommand({
command: "bash",
args: [
"-c",
'for i in $(find -E . -regex ".*.(robot|resource)" -type f); do cat -s $i ; done',
],
});
const iter = stdout.matchAll(/^\$\{(.*?)\}/gm);
return [...iter]
.map((item) => item[1])
.map((variable) => ({
name: variable,
description: "Variable",
}));
},
};
const testCasesGenerator: Fig.Generator = {
script: [
"bash",
"-c",
'for i in $(find -E . -regex ".*.robot" -type f); do cat -s $i ; done',
],
postProcess: (out) => {
// find all parts of the code with test cases
// regex: everything after '***Test Cases***' until '***???***')
const iter = out.matchAll(
/(?:\*{3} ?Test Cases ?\*{3})([\S\s]*)(?:\*{3}(\w+\s?)+\*{3})*/gim
);
const seen: Set<string> = new Set();
const suggestions: Fig.Suggestion[] = [];
// go through ***Test Cases** blocks
for (const [_, block] of iter) {
// get every test case name
// regex: word/s at the start of a line until '#'
const lines = block.matchAll(/^(\w+( |-)*)+(?!.\#.*)(?!.\#.*)/gm);
// go through all the test cases names found
for (let [testCase] of lines) {
testCase = testCase.trim();
// validate if the test case name isn't divided by more than one space
if (testCase.search(/\s\s+/) != -1) continue;
if (seen.has(testCase)) continue;
seen.add(testCase);
suggestions.push({
name: testCase,
description: "Test case",
});
}
}
return suggestions;
},
};
const completionSpec: Fig.Spec = {
name: "robot",
description: "CLI for running Robot Framework automation tests",
args: {
name: "robot script",
isScript: true,
isVariadic: true,
generators: filepaths({
extensions: ["robot"],
editFileSuggestions: { priority: 76, icon: "fig://icon?type=txt" },
}),
},
options: [
{
name: ["-h", "-?", "--help"],
description: "Print usage instructions",
},
{
name: "--rpa",
description:
'Turn on the generic automation mode. Mainly affects terminology so that "test" is replaced with "task" in logs and reports',
},
{
name: ["-F", "--extension"],
description:
"Parse only files with this extension when executing a directory",
args: {
name: "extension",
description: "File extensions divided by colon",
suggestions: ["txt", "robot:txt"],
},
},
{
name: ["-N", "--name"],
description: "Set a name of the top level suite",
args: {
name: "name",
},
},
{
name: ["-D", "--doc"],
insertValue: "-D '{cursor}'",
description: "Set a documentation of the top level suite",
},
{
name: ["-M", "--metadata"],
insertValue: "-M {cursor}:",
description: "Set metadata of the top level suite",
args: {
name: "name:value",
},
},
{
name: ["-G", "--settag"],
description: "Sets given tag to all executed tests",
args: {
name: "tag",
},
},
{
name: ["-t", "--test"],
description:
"Select tests by name or by long name containing also parent suite name like `Parent.Test`",
args: {
name: "name",
generators: testCasesGenerator,
},
},
{
name: "--task",
description: "Alias to --test. Especially applicable with --rpa",
args: {
name: "name",
generators: testCasesGenerator,
},
},
{
name: ["-s", "--suite"],
description: "Select suites by name",
args: {
name: "name",
},
},
{
name: ["-i", "--include"],
description: "Select test cases by tag",
args: {
name: "tag",
generators: tagsGenerator,
},
},
{
name: ["-e", "--exclude"],
description: "Select test cases not to run by tag",
args: {
name: "tag",
generators: tagsGenerator,
},
},
{
name: ["-R", "--rerunfailed"],
description:
"Select failed tests from an earlier output file to be re-executed",
args: {
name: "output file",
generators: filepaths({
extensions: ["xml"],
}),
},
},
{
name: ["-S", "--rerunfailedsuites"],
description:
"Select failed suites from an earlier output file to be re-executed",
args: {
name: "output file",
generators: filepaths({
extensions: ["xml"],
}),
},
},
{
name: "--runemptysuite",
description: "Executes suite even if it contains no tests",
},
{
name: "--skip",
description: "Tests having given tag will be skipped",
args: {
name: "tag",
generators: tagsGenerator,
},
},
{
name: "--skiponfailure",
description: "Tests having given tag will be skipped if they fail",
args: {
name: "tag",
generators: tagsGenerator,
},
},
{
name: ["-v", "--variable"],
description: "Set variables in the test data",
args: {
name: "variable",
generators: variablesGenerator,
},
},
{
name: ["-V", "--variablefile"],
description: "Python or YAML file file to read variables from",
args: {
name: "file",
generators: filepaths({
extensions: ["py", "yaml"],
}),
},
},
{
name: ["-d", "--outputdir"],
description:
"Where to create output files. The default is the directory where tests are run from",
args: {
name: "directory",
template: "folders",
},
},
{
name: ["-o", "--output"],
description:
"XML output file relative to --outputdir unless given as an absolute path. Default: output.xml",
args: {
name: "file",
suggestions: ["output.xml"],
},
},
{
name: ["-l", "--log"],
description:
"HTML log file. Can be disabled by giving a special value `NONE`. Default: log.html",
args: {
name: "file",
suggestions: ["log.html", "NONE"],
},
},
{
name: ["-r", "--report"],
description:
"HTML report file. Can be disabled with `NONE` similarly as --log. Default: report.html",
args: {
name: "file",
suggestions: ["report.html", "NONE"],
},
},
{
name: ["-x", "--xunit"],
description:
"XUnit compatible result file. Not created unless this option is specified",
args: {
name: "file",
suggestions: ["xunit.xml"],
},
},
{
name: ["-b", "--debugfile"],
description:
"Debug file written during execution. Not created unless this option is specified",
args: {
name: "file",
},
},
{
name: ["-T", "--timestampoutputs"],
description:
"Adds timestamp in a format `YYYYMMDD-hhmmss` to all generated output files between their basename and extension",
},
{
name: "--splitlog",
description:
"Split the log file into smaller pieces that open in browsers transparently",
},
{
name: "--logtitle",
description:
"Title for the generated log file. The default title is `<SuiteName> Log.`",
args: {
name: "title",
},
},
{
name: "--reporttitle",
description:
"Title for the generated report file. The default title is `<SuiteName> Report`",
args: {
name: "title",
},
},
{
name: "--reportbackground",
description:
"Background colors to use in the report file. Given in format `passed:failed:skipped` where the `:skipped` part can be omitted",
args: {
name: "colors",
},
},
{
name: "--maxerrorlines",
description:
"Maximum number of error message lines to show in report when tests fail. Default is 40, minimum is 10 and `NONE` can be used to show the full message",
args: {
name: "lines",
suggestions: [
{
name: "40",
displayName: "40 (default)",
priority: 76,
description: "Default number of lines",
},
{
name: "10",
displayName: "10 (minimum)",
description: "Minimum number of lines",
},
{
name: "NONE",
description: "Unlimited number of lines. Shows the full message",
},
],
},
},
{
name: "--maxassignlength",
description:
"Maximum number of characters to show in log when variables are assigned. Zero or negative values can be used to avoid showing assigned values at all. Default is 200",
args: {
name: "characters",
suggestions: [
{
name: "200",
displayName: "200 (default)",
priority: 76,
description: "Default number of characters",
},
{
name: "0",
description: "No values at all",
},
],
},
},
{
name: ["-L", "--loglevel"],
description: "Threshold level for logging",
args: {
name: "level",
suggestions: [
{ name: "TRACE", type: "option" },
{ name: "DEBUG", type: "option" },
{
name: "INFO",
displayName: "INFO (default)",
priority: 76,
type: "option",
},
{ name: "WARN", type: "option" },
{
name: "NONE",
displayName: "NONE (no logging)",
type: "option",
},
],
},
},
{
name: "--suitestatlevel",
description:
"How many levels to show in `Statistics by Suite` in log and report",
args: {
name: "level",
},
},
{
name: "--tagstatinclude",
description:
"Include only matching tags in `Statistics by Tag` in log and report",
args: {
name: "tag",
generators: tagsGenerator,
},
},
{
name: "--tagstatexclude",
description: "Exclude matching tags from `Statistics by Tag`",
args: {
name: "tag",
generators: tagsGenerator,
},
},
{
name: "--tagstatcombine",
description:
"Create combined statistics based on tags. These statistics are added into `Statistics by Tag`",
args: {
name: "tags:name",
generators: tagsGenerator,
},
},
{
name: "--tagdoc",
description: "Add documentation to tags matching the given pattern",
args: {
name: "pattern:doc",
generators: tagsGenerator,
},
},
{
name: "--tagstatlink",
description:
"Add external links into `Statistics by Tag`. Pattern can use `*`, `?` and `[]` as wildcards",
args: {
name: "pattern:link:title",
generators: tagsGenerator,
},
},
{
name: "--expandkeywords",
description:
"Matching keywords will be automatically expanded in the log file",
args: {
name: "pattern",
suggestions: [
{
name: "name:<pattern>",
insertValue: "name:{cursor}",
type: "option",
},
{
name: "tag:<pattern>",
insertValue: "tag:{cursor}",
type: "option",
},
],
},
},
{
name: "--removekeywords",
description: "Remove keyword data from the generated log file",
args: {
name: "pattern",
suggestions: [
{
name: "all",
description: "Remove data from all keywords",
type: "option",
},
{
name: "passed",
description:
"Remove data only from keywords in passed test cases and suites",
type: "option",
},
{
name: "for",
description: "Remove passed iterations from for loops",
type: "option",
},
{
name: "while",
description: "Remove passed iterations from while loops",
type: "option",
},
{
name: "wuks",
description:
"Remove all but the last failing keyword inside `BuiltIn.Wait Until Keyword Succeeds`",
type: "option",
},
{
name: "name:<pattern>",
insertValue: "name:{cursor}",
type: "option",
},
{
name: "tag:<pattern>",
insertValue: "tag:{cursor}",
type: "option",
},
],
},
},
{
name: "--flattenkeywords",
description: "Flattens matching keywords in the generated log file",
args: {
name: "pattern",
suggestions: [
{
name: "for",
description: "Flatten FOR loops fully",
type: "option",
},
{
name: "while",
description: "Flatten WHILE loops fully",
type: "option",
},
{
name: "iteration",
description: "Flatten FOR/WHILE loop iterations",
type: "option",
},
{
name: "name:<pattern>",
insertValue: "name:{cursor}",
type: "option",
},
{
name: "tag:<pattern>",
insertValue: "tag:{cursor}",
type: "option",
},
],
},
},
{
name: "--listener",
description:
"A class for monitoring test execution. Gets notifications e.g. when tests start and end",
args: {
name: "class",
},
},
{
name: "--nostatusrc",
description:
"Sets the return code to zero regardless of failures in test cases. Error codes are returned normally",
},
{
name: "--dryrun",
description:
"Sets the return code to zero regardless of failures in test cases. Error codes are returned normally",
},
{
name: ["-X", "--exitonfailure"],
description: "Stops test execution if any test fails",
},
{
name: "--exitonerror",
description:
"Stops test execution if any error occurs when parsing test data, importing libraries, and so on",
},
{
name: "--skipteardownonexit",
description:
"Causes teardowns to be skipped if test execution is stopped prematurely",
},
{
name: "--randomize",
description: "Randomizes the test execution order",
args: {
name: "type",
suggestions: [
{
name: "all",
description: "Randomizes both suites and tests",
type: "option",
},
{ name: "suites", description: "Randomizes suites", type: "option" },
{ name: "tests", description: "Randomizes tests", type: "option" },
{
name: "none",
displayName: "none (default)",
priority: 76,
description: "No randomization (default)",
type: "option",
},
],
},
},
{
name: "--prerunmodifier",
description:
"Class to programmatically modify the suite structure before execution",
args: {
name: "class",
},
},
{
name: "--prerebotmodifier",
description:
"Class to programmatically modify the result model before creating reports and logs",
args: {
name: "class",
},
},
{
name: "--console",
description: "How to report execution on the console",
args: {
name: "type",
suggestions: [
{
name: "verbose",
displayName: "verbose (default)",
priority: 76,
description: "Report every suite and test (default)",
type: "option",
},
{
name: "dotted",
description:
"Only show `.` for passed test, `s` for skipped tests, and `F` for failed tests",
type: "option",
},
{
name: "quiet",
description: "No output except for errors and warnings",
type: "option",
},
{
name: "none",
description: "No output whatsoever",
type: "option",
},
],
},
},
{
name: ["-.", "--dotted"],
description: "Shortcut for `--console dotted`",
},
{
name: "--quiet",
description: "Shortcut for `--console quiet`",
},
{
name: ["-W", "--consolewidth"],
description: "Width of the console output. Default is 78",
args: {
name: "chars",
suggestions: [
{
name: "78",
displayName: "78 (default)",
priority: 76,
},
],
},
},
{
name: ["-C", "--consolecolors"],
description: "Use colors on console output or not",
args: {
name: "option",
suggestions: [
{
name: "auto",
displayName: "auto (default)",
priority: 76,
description: "Use colors when output not redirected (default)",
type: "option",
},
{
name: "on",
description: "Always use colors",
type: "option",
},
{
name: "ansi",
description: "Like `on` but use ANSI colors also on Windows",
type: "option",
},
{
name: "off",
description: "Disable colors altogether",
type: "option",
},
],
},
},
{
name: ["-K", "--consolemarkers"],
description:
"Show markers on the console when top level keywords in a test case end",
args: {
name: "option",
suggestions: [
{
name: "auto",
type: "option",
},
{
name: "on",
type: "option",
},
{
name: "off",
type: "option",
},
],
},
},
{
name: ["-P", "--pythonpath"],
description:
"Additional locations (directories, ZIPs) where to search libraries and other extensions when they are imported",
args: {
name: "path",
generators: filepaths({
extensions: ["zip"],
}),
},
},
{
name: ["-A", "--argumentfile"],
description:
"Text file to read more arguments from. Use special path `STDIN` to read contents from the standard input stream",
args: {
name: "path",
template: "filepaths",
},
},
{
name: "--version",
description: "Print version information",
},
],
};
export default completionSpec;