comparison tests/generate-working-copy-states.py @ 23195:29977b315be1

test-revert: move embedded script to its own file Move the gen-revert-cases.py out of test-revert.t into its own file so we can reuse it from other tests (specifically test-status-rev.t).
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 03 Nov 2014 16:27:01 -0800
parents
children 390a2610eaef
comparison
equal deleted inserted replaced
23194:8c29000c4295 23195:29977b315be1
1 # generate proper file state to test working copy behavior
2 import sys
3 import os
4
5 # build the combination of possible states
6 combination = []
7 for base in [None, 'content1']:
8 for parent in set([None, 'content2']) | set([base]):
9 for wcc in set([None, 'content3']) | set([base, parent]):
10 for tracked in (False, True):
11 def statestring(content):
12 return content is None and 'missing' or content
13 trackedstring = tracked and 'tracked' or 'untracked'
14 filename = "%s_%s_%s-%s" % (statestring(base),
15 statestring(parent),
16 statestring(wcc),
17 trackedstring)
18 combination.append((filename, base, parent, wcc))
19
20 # make sure we have stable output
21 combination.sort()
22
23 # retrieve the state we must generate
24 target = sys.argv[1]
25
26 # compute file content
27 content = []
28 for filename, base, parent, wcc in combination:
29 if target == 'filelist':
30 print filename
31 elif target == 'base':
32 content.append((filename, base))
33 elif target == 'parent':
34 content.append((filename, parent))
35 elif target == 'wc':
36 # Make sure there is content so the file gets written and can be
37 # tracked. It will be deleted outside of this script.
38 content.append((filename, wcc or 'TOBEDELETED'))
39 else:
40 print >> sys.stderr, "unknown target:", target
41 sys.exit(1)
42
43 # write actual content
44 for filename, data in content:
45 if data is not None:
46 f = open(filename, 'w')
47 f.write(data + '\n')
48 f.close()
49 elif os.path.exists(filename):
50 os.remove(filename)