Followup to r29625: fix getopt tests.
[svn.git] / subversion / tests / libsvn_subr / target-test.py
blobed8a25f16a2a4f51c2be19452e5e267d7961114a
1 #!/usr/bin/env python
3 # target-test.py: testing svn_path_condense_targets.
5 # Subversion is a tool for revision control.
6 # See http://subversion.tigris.org for more information.
8 # ====================================================================
9 # Copyright (c) 2000-2004 CollabNet. All rights reserved.
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at http://subversion.tigris.org/license-1.html.
14 # If newer versions of this license are posted there, you may use a
15 # newer version instead, at your option.
17 ######################################################################
19 import os, sys, shutil, string
21 # The list of test cases: [(name, params, expected) ...]
22 cwd = os.getcwd().replace('\\', '/') # Use forward slashes on Windows
23 tests = [('normal use',
24 'z/A/B z/A z/A/C z/D/E z/D/F z/D z/G z/G/H z/G/I',
25 cwd + '/z: A, D, G, \n'),
26 ('identical dirs',
27 'z/A z/A z/A z/A',
28 cwd + '/z/A: \n'),
29 ('identical files',
30 'z/A/file z/A/file z/A/file z/A/file',
31 cwd + '/z/A/file: \n'),
32 ('single dir',
33 'z/A',
34 cwd + '/z/A: \n'),
35 ('single file',
36 'z/A/file',
37 cwd + '/z/A/file: \n'),
38 ('URLs',
39 'http://host/A/C http://host/A/C/D http://host/A/B/D',
40 'http://host/A: C, B/D, \n'),
41 ('URLs with no common prefix',
42 'http://host1/A/C http://host2/A/C/D http://host3/A/B/D',
43 ': http://host1/A/C, http://host2/A/C/D, http://host3/A/B/D, \n'),
44 ('file URLs with no common prefix',
45 'file:///A/C file:///B/D',
46 ': file:///A/C, file:///B/D, \n'),
47 ('URLs with mixed protocols',
48 'http://host/A/C file:///B/D gopher://host/A',
49 ': http://host/A/C, file:///B/D, gopher://host/A, \n'),
50 ('mixed paths and URLs',
51 'z/A/B z/A http://host/A/C/D http://host/A/C',
52 ': ' + cwd + '/z/A, http://host/A/C, \n')]
54 # (re)Create the test directory
55 if os.path.exists('z'):
56 shutil.rmtree('z')
57 os.mkdir('z')
58 os.mkdir('z/A')
59 os.mkdir('z/A/B')
60 os.mkdir('z/A/C')
61 os.mkdir('z/D')
62 os.mkdir('z/D/E')
63 os.mkdir('z/D/F')
64 os.mkdir('z/G')
65 os.mkdir('z/G/H')
66 os.mkdir('z/G/I')
67 open('z/A/file', 'w').close()
69 def _run_test(cmdline):
70 if sys.platform == 'win32':
71 progname = '.\\target-test.exe'
72 else:
73 progname = './target-test'
75 infile, outfile, errfile = os.popen3(progname + ' ' + cmdline)
76 stdout_lines = outfile.readlines()
77 stderr_lines = errfile.readlines()
79 outfile.close()
80 infile.close()
81 errfile.close()
83 map(sys.stdout.write, stderr_lines)
84 return len(stderr_lines), string.join(stdout_lines, '')
86 # Run the tests
87 failed = 0
88 for n in range(len(tests)):
89 test_name = 'target-test %d: %s' % (n + 1, tests[n][0])
90 status, output = _run_test(tests[n][1])
91 if status:
92 print 'FAIL:', test_name, '(non-null return)'
93 failed = 1
94 else:
95 if output != tests[n][2]:
96 print 'FAIL:', test_name
97 failed = 1
98 else:
99 print 'PASS:', test_name
100 sys.exit(failed)