Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e51fe8d

Browse files
committed
runtest(): When generating output, if the result is a single line with the
name of the test, only write the output file if it already exists (and tell the user to consider removing it). This avoids the generation of unnecessary turds.
1 parent 4f1e495 commit e51fe8d

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

Lib/test/regrtest.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def runtest(test, generate, verbose, quiet, testdir = None):
230230
outputfile = os.path.join(outputdir, test)
231231
try:
232232
if generate:
233-
cfp = open(outputfile, "w")
233+
cfp = StringIO.StringIO()
234234
elif verbose:
235235
cfp = sys.stdout
236236
else:
@@ -273,6 +273,24 @@ def runtest(test, generate, verbose, quiet, testdir = None):
273273
traceback.print_exc(file=sys.stdout)
274274
return 0
275275
else:
276+
if generate:
277+
output = cfp.getvalue()
278+
if output == test + "\n":
279+
if os.path.exists(outputfile):
280+
# Write it since it already exists (and the contents
281+
# may have changed), but let the user know it isn't
282+
# needed:
283+
fp = open(outputfile, "w")
284+
fp.write(output)
285+
fp.close()
286+
print "output file", outputfile, \
287+
"is no longer needed; consider removing it"
288+
# else:
289+
# We don't need it, so don't create it.
290+
else:
291+
fp = open(outputfile, "w")
292+
fp.write(output)
293+
fp.close()
276294
return 1
277295

278296
def findtestdir():

0 commit comments

Comments
 (0)