Add a little more to the svn_rangelist_intersect test to test the
[svn.git] / subversion / tests / cmdline / utf8_tests.py
blob8813706a02cfbb1b49cf448d03fa105c31909af8
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # utf8_tests.py: testing the svn client's utf8 (i18n) handling
6 # Subversion is a tool for revision control.
7 # See http://subversion.tigris.org for more information.
9 # ====================================================================
10 # Copyright (c) 2000-2004 CollabNet. All rights reserved.
12 # This software is licensed as described in the file COPYING, which
13 # you should have received as part of this distribution. The terms
14 # are also available at http://subversion.tigris.org/license-1.html.
15 # If newer versions of this license are posted there, you may use a
16 # newer version instead, at your option.
18 ######################################################################
20 # General modules
21 import sys, re, os, locale
23 # Our testing module
24 import svntest
25 from svntest import wc
27 # (abbreviation)
28 Item = wc.StateItem
29 Skip = svntest.testcase.Skip
31 #--------------------------------------------------------------------
32 # Data
34 # Here's a filename and a log message which contain some high-ascii
35 # data. In theory this data has different interpretations when
36 # converting from 2 different charsets into UTF-8.
38 ### "b" in ISO-8859-1 encoding:
39 i18n_filename = 'b\xd4\xe7\xc5'
41 ### "drieëntwintig keer was één keer teveel" in ISO-8859-1 encoding:
42 i18n_logmsg = 'drie\xc3\xabntwintig keer was \xc3\xa9\xc3\xa9n keer teveel'
45 ######################################################################
46 # Tests
48 # Each test must return on success or raise on failure.
51 def basic_utf8_conversion(sbox):
52 "conversion of paths and logs to/from utf8"
54 sbox.build()
55 wc_dir = sbox.wc_dir
57 # Create the new i18n file and schedule it for addition
58 svntest.main.file_append(os.path.join(wc_dir, i18n_filename), "hi")
59 svntest.actions.run_and_verify_svn(
60 "Failed to schedule i18n filename for addition", None, [],
61 'add', os.path.join(wc_dir, i18n_filename))
63 svntest.actions.run_and_verify_svn(
64 "Failed to commit i18n filename", None, [],
65 'commit', '-m', i18n_logmsg, wc_dir)
67 # Here's how the test should really work:
69 # 1. sh LC_ALL=ISO-8859-1 svn commit <filename> -m "<logmsg>"
71 # 2. sh LC_ALL=UTF-8 svn log -rHEAD > output
73 # 3. verify that output is the exact UTF-8 data that we expect.
75 # 4. repeat the process using some other locale other than ISO8859-1,
76 # preferably some locale which will convert the high-ascii data to
77 # *different* UTF-8.
81 #----------------------------------------------------------------------
83 ########################################################################
84 # Run the tests
86 try:
87 # Generic setlocale so that getlocale returns something sensible
88 locale.setlocale(locale.LC_ALL, '')
90 # Try to make these test run in an ISO-8859-1 environment, otherwise
91 # they would run in whatever random locale the testing platform
92 # happens to have, and then we couldn't predict the exact results.
93 if svntest.main.windows:
94 # In this case, it would probably be "english_usa.1252", but you should
95 # be able to set just the encoding by using ".1252" (that's codepage
96 # 1252, which is almost but not quite entirely unlike tea; um, I mean
97 # it's very similar to ISO-8859-1).
98 # -- Branko Čibej <brane@xbc.nu>
99 locale.setlocale(locale.LC_ALL, '.1252')
100 else:
101 locale.setlocale(locale.LC_ALL, 'en_US.ISO8859-1')
103 if os.putenv:
104 # propagate to the svn* executables, so they do the correct translation
105 # the line below works for Linux systems if they have the particular
106 # locale installed
107 os.environ['LC_ALL'] = "en_US.ISO8859-1"
108 except:
109 pass
111 # Check to see if the locale uses ISO-8859-1 encoding. The regex is necessary
112 # because some systems ommit the first hyphen or use lowercase letters for ISO.
113 if sys.platform == 'win32':
114 localematch = 1
115 else:
116 localeenc = locale.getlocale()[1]
117 if localeenc:
118 localeregex = re.compile('^ISO-?8859-1$', re.I)
119 localematch = localeregex.search(localeenc)
120 try:
121 svntest.actions.run_and_verify_svn(None, svntest.SVNAnyOutput, [],"help")
122 except:
123 # We won't be able to run the client; this might be because the
124 # system does not support the iso-8859-1 locale. Anyhow, it makes
125 # no sense to run the test.
126 localematch = None
127 else:
128 localematch = None
130 # Also check that the environment contains the expected locale settings
131 # either by default, or because we set them above.
132 if localematch:
133 localeregex = re.compile('^en_US\.ISO-?8859-1$', re.I)
134 for env in [ 'LC_ALL', 'LC_CTYPE', 'LANG' ]:
135 env_value = os.getenv(env)
136 if env_value:
137 if localeregex.search(env_value):
138 break
139 else:
140 localematch = None
141 break
144 ########################################################################
145 # Run the tests
147 # list all tests here, starting with None:
148 test_list = [ None,
149 Skip(basic_utf8_conversion)
152 if __name__ == '__main__':
153 svntest.main.run_tests(test_list)
154 # NOTREACHED
157 ### End of file.