|
1 | 1 | import { filepaths } from "@fig/autocomplete-generators";
|
2 | 2 |
|
3 | 3 | const tagsGenerator: Fig.Generator = {
|
4 |
| - custom: async (tokens, executeShellCommand) => { |
5 |
| - const out = await executeShellCommand( |
6 |
| - 'for i in $(find -E . -regex ".*.robot" -type f); do cat -s $i ; done' |
7 |
| - ); |
| 4 | + script: |
| 5 | + 'for i in $(find -E . -regex ".*.robot" -type f); do cat -s $i ; done', |
| 6 | + postProcess: (out) => { |
| 7 | + // find all lines with tags |
| 8 | + // regex: line that starts with 2+ spaces, than '[Tags] ' and words |
8 | 9 | const iter = out.matchAll(/(?:^\s\s+\[Tags\])\s\s+(\w+ *)*(?!.\#.*)/gm);
|
9 | 10 |
|
10 | 11 | const seen: Set<string> = new Set();
|
@@ -46,6 +47,44 @@ const variablesGenerator: Fig.Generator = {
|
46 | 47 | },
|
47 | 48 | };
|
48 | 49 |
|
| 50 | +const testCasesGenerator: Fig.Generator = { |
| 51 | + script: |
| 52 | + 'for i in $(find -E . -regex ".*.robot" -type f); do cat -s $i ; done', |
| 53 | + postProcess: (out) => { |
| 54 | + // find all the parts of the code with test cases |
| 55 | + // regex: everytring after '***Test Cases***' until '***???***') |
| 56 | + const iter = out.matchAll( |
| 57 | + /(?:\*{3}Test Cases\*{3})([\S\s]*)(?:\*{3}(\w+\s?)+\*{3})/gim |
| 58 | + ); |
| 59 | + |
| 60 | + const seen: Set<string> = new Set(); |
| 61 | + const suggestions: Fig.Suggestion[] = []; |
| 62 | + |
| 63 | + // go through ***Test Cases** blocks |
| 64 | + for (const [_, block] of iter) { |
| 65 | + // get every test case name |
| 66 | + // regex: word/s at the start of a line divided |
| 67 | + const lines = block.matchAll(/^(\w+ *)+(?!.\#.*)(?!.\#.*)/gm); |
| 68 | + // go through all the test cases names found |
| 69 | + for (let [testCase] of lines) { |
| 70 | + testCase = testCase.trim(); |
| 71 | + // validate if the test case name isn't divided by more than one space |
| 72 | + if (testCase.search(/\s\s+/) != -1) continue; |
| 73 | + |
| 74 | + if (seen.has(testCase)) continue; |
| 75 | + seen.add(testCase); |
| 76 | + |
| 77 | + suggestions.push({ |
| 78 | + name: testCase, |
| 79 | + description: "Test case", |
| 80 | + }); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + return suggestions; |
| 85 | + }, |
| 86 | +}; |
| 87 | + |
49 | 88 | const completionSpec: Fig.Spec = {
|
50 | 89 | name: "robot",
|
51 | 90 | description: "CLI for running Robot Framework automation tests",
|
@@ -111,13 +150,15 @@ const completionSpec: Fig.Spec = {
|
111 | 150 | "Select tests by name or by long name containing also parent suite name like `Parent.Test`",
|
112 | 151 | args: {
|
113 | 152 | name: "name",
|
| 153 | + generators: testCasesGenerator, |
114 | 154 | },
|
115 | 155 | },
|
116 | 156 | {
|
117 | 157 | name: "--task",
|
118 | 158 | description: "Alias to --test. Especially applicable with --rpa",
|
119 | 159 | args: {
|
120 | 160 | name: "name",
|
| 161 | + generators: testCasesGenerator, |
121 | 162 | },
|
122 | 163 | },
|
123 | 164 | {
|
@@ -203,7 +244,6 @@ const completionSpec: Fig.Spec = {
|
203 | 244 | }),
|
204 | 245 | },
|
205 | 246 | },
|
206 |
| - |
207 | 247 | {
|
208 | 248 | name: ["-d", "--outputdir"],
|
209 | 249 | description:
|
|
0 commit comments