Skip to content

Commit 219ed0b

Browse files
mmarchinitargos
authored andcommitted
test: add Actions annotation output
It's possible to annotate failures in Actions by printing "::error file={},line={},col={}::{message}". This methos is preferrable over using a problem matcher because problem matchers only allow single-line messages, whereas ::error allows multi-line messages. PR-URL: #34590 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 9fa8d20 commit 219ed0b

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

.github/workflows/test-asan.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
- name: Build
3737
run: make build-ci -j2 V=1
3838
- name: Test
39-
run: make run-ci -j2 V=1 TEST_CI_ARGS="-p dots"
39+
run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions"

.github/workflows/test-linux.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
- name: Build
2828
run: make build-ci -j2 V=1 CONFIG_FLAGS="--error-on-warn"
2929
- name: Test
30-
run: make run-ci -j2 V=1 TEST_CI_ARGS="-p dots"
30+
run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions"

.github/workflows/test-macos.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
- name: Build
3232
run: make build-ci -j2 V=1 CONFIG_FLAGS="--error-on-warn"
3333
- name: Test
34-
run: make run-ci -j2 V=1 TEST_CI_ARGS="-p dots"
34+
run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions"

tools/test.py

+37-12
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ def __init__(self, cases, flaky_tests_mode):
116116
self.lock = threading.Lock()
117117
self.shutdown_event = threading.Event()
118118

119+
def GetFailureOutput(self, failure):
120+
output = []
121+
if failure.output.stderr:
122+
output += ["--- stderr ---" ]
123+
output += [failure.output.stderr.strip()]
124+
if failure.output.stdout:
125+
output += ["--- stdout ---"]
126+
output += [failure.output.stdout.strip()]
127+
output += ["Command: %s" % EscapeCommand(failure.command)]
128+
if failure.HasCrashed():
129+
output += ["--- %s ---" % PrintCrashed(failure.output.exit_code)]
130+
if failure.HasTimedOut():
131+
output += ["--- TIMEOUT ---"]
132+
output = "\n".join(output)
133+
return output
134+
135+
def PrintFailureOutput(self, failure):
136+
print(self.GetFailureOutput(failure))
137+
119138
def PrintFailureHeader(self, test):
120139
if test.IsNegative():
121140
negative_marker = '[negative] '
@@ -224,17 +243,7 @@ def Done(self):
224243
print()
225244
for failed in self.failed:
226245
self.PrintFailureHeader(failed.test)
227-
if failed.output.stderr:
228-
print("--- stderr ---")
229-
print(failed.output.stderr.strip())
230-
if failed.output.stdout:
231-
print("--- stdout ---")
232-
print(failed.output.stdout.strip())
233-
print("Command: %s" % EscapeCommand(failed.command))
234-
if failed.HasCrashed():
235-
print("--- %s ---" % PrintCrashed(failed.output.exit_code))
236-
if failed.HasTimedOut():
237-
print("--- TIMEOUT ---")
246+
self.PrintFailureOutput(failed)
238247
if len(self.failed) == 0:
239248
print("===")
240249
print("=== All tests succeeded")
@@ -288,6 +297,21 @@ def HasRun(self, output):
288297
sys.stdout.write('.')
289298
sys.stdout.flush()
290299

300+
class ActionsAnnotationProgressIndicator(DotsProgressIndicator):
301+
def GetAnnotationInfo(self, test, output):
302+
traceback = output.stdout + output.stderr
303+
find_full_path = re.search(r' +at .*\(.*%s:([0-9]+):([0-9]+)' % test.file, traceback)
304+
col = line = 0
305+
if find_full_path:
306+
line, col = map(int, find_full_path.groups())
307+
root_path = abspath(join(dirname(__file__), '../')) + os.sep
308+
filename = test.file.replace(root_path, "")
309+
return filename, line, col
310+
311+
def PrintFailureOutput(self, failure):
312+
output = self.GetFailureOutput(failure)
313+
filename, line, column = self.GetAnnotationInfo(failure.test, failure.output)
314+
print("::error file=%s,line=%d,col=%d::%s" % (filename, line, column, output.replace('\n', '%0A')))
291315

292316
class TapProgressIndicator(SimpleProgressIndicator):
293317

@@ -496,6 +520,7 @@ def ClearLine(self, last_line_length):
496520
PROGRESS_INDICATORS = {
497521
'verbose': VerboseProgressIndicator,
498522
'dots': DotsProgressIndicator,
523+
'actions': ActionsAnnotationProgressIndicator,
499524
'color': ColorProgressIndicator,
500525
'tap': TapProgressIndicator,
501526
'mono': MonochromeProgressIndicator,
@@ -1299,7 +1324,7 @@ def BuildOptions():
12991324
result.add_option('--logfile', dest='logfile',
13001325
help='write test output to file. NOTE: this only applies the tap progress indicator')
13011326
result.add_option("-p", "--progress",
1302-
help="The style of progress indicator (verbose, dots, color, mono, tap)",
1327+
help="The style of progress indicator (%s)" % ", ".join(PROGRESS_INDICATORS.keys()),
13031328
choices=list(PROGRESS_INDICATORS.keys()), default="mono")
13041329
result.add_option("--report", help="Print a summary of the tests to be run",
13051330
default=False, action="store_true")

0 commit comments

Comments
 (0)