From 1e5d779cb38725176b4ba94cde0a1de4294d9170 Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Fri, 4 Nov 2016 14:58:27 +0000 Subject: [PATCH] prism-auto: In test mode, cleanup the temporary files used for capturing PRISM output Due to the use of NamedTemporaryFile(delete=False) we actually have to delete the log files ourselves. git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@11881 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/etc/scripts/prism-auto | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/prism/etc/scripts/prism-auto b/prism/etc/scripts/prism-auto index 3e032de4..18e99869 100755 --- a/prism/etc/scripts/prism-auto +++ b/prism/etc/scripts/prism-auto @@ -334,6 +334,8 @@ def walk(dir, meth): # Run PRISM with a given list of command-line args def runPrism(args, dir=""): + # keep track if we need to cleanup the log file after use + cleanupLogFile = False if options.test: if options.testAll: args.append("-testall") else: args.append("-test") @@ -365,6 +367,8 @@ def runPrism(args, dir=""): elif options.test or options.ddWarnings: f = tempfile.NamedTemporaryFile(delete=False) logFile = f.name + # we want cleanup when we are done, as this is a real temporary file + cleanupLogFile = True if isWindows(): # On Windows, PRISM can not open a temporary file created with NamedTemporaryFile. # So, we just pass the file to Popen to capture standard output instead of redirecting @@ -391,6 +395,9 @@ def runPrism(args, dir=""): if options.showWarnings and re.match('Warning:', line): printTestResult(line) if options.test and exitCode != 0: + # failure, we don't want to cleanup the log (if it was a temporary file) + # so that the user can inspect it + cleanupLogFile = False for line in open(logFile, 'r').readlines(): if re.match('Error:', line): printTestResult(line) @@ -398,6 +405,9 @@ def runPrism(args, dir=""): print("edit " + logFile) if not options.testAll: closeDown(1) + if cleanupLogFile: + # logFile was a temporary file and we'd like to clean it up + os.remove(logFile) # Print a testing-related message, colour coding if needed