From c2e019ed31ed6e4121c011e76a51b5090483560f Mon Sep 17 00:00:00 2001 From: Rintaro Kuroiwa Date: Tue, 4 Apr 2017 16:35:25 -0700 Subject: [PATCH] Output command line when packager tests fail - Changed python packaging test to output the command line it ran for tests that failed. Change-Id: I52c06bcec725c9dce7f845ab138cfab29b582201 --- packager/app/test/packager_app.py | 9 +++++++++ packager/app/test/packager_test.py | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packager/app/test/packager_app.py b/packager/app/test/packager_app.py index 60c92c549f..58381fc2aa 100644 --- a/packager/app/test/packager_app.py +++ b/packager/app/test/packager_app.py @@ -22,6 +22,9 @@ class PackagerApp(object): if platform.system() == 'Windows': packager_name += '.exe' self.binary = os.path.join(test_env.SCRIPT_DIR, packager_name) + # Set this to empty for now in case GetCommandLine() is called before + # Package(). + self.packaging_command_line = '' assert os.path.exists(self.binary), ('Please run from output directory, ' 'e.g. out/Debug/packager_test.py') @@ -39,4 +42,10 @@ class PackagerApp(object): cmd = [self.binary] cmd.extend(streams) cmd.extend(flags) + # Put single-quotes around each entry so that things like '$' signs in + # segment templates won't be interpreted as shell variables. + self.packaging_command_line = ' '.join(["'%s'" % entry for entry in cmd]) assert 0 == subprocess.call(cmd) + + def GetCommandLine(self): + return self.packaging_command_line diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 71f5441554..3164c1c576 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -19,6 +19,14 @@ import unittest import packager_app import test_env +_TEST_FAILURE_COMMAND_LINE_MESSAGE = """ +!!! To reproduce the failure, change the output files to an !!! +!!! existing directory, e.g. output artifacts to current !!! +!!! directory by removing /tmp/something/ in the following !!! +!!! command line. !!! +The test executed the following command line: +""" + class PackagerAppTest(unittest.TestCase): @@ -658,7 +666,11 @@ class PackagerAppTest(unittest.TestCase): stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = p.communicate() - self.fail(output + error) + command_line = self.packager.GetCommandLine() + failure_message = (output + error + '\n' + + _TEST_FAILURE_COMMAND_LINE_MESSAGE + + command_line) + self.fail(failure_message) # '*.media_info' outputs contain media file names, which is changing for # every test run. These needs to be replaced for comparison.