Home | History | Annotate | Download | only in escaping
      1 #!/usr/bin/env python
      2 
      3 # Copyright (c) 2012 Google Inc. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 """
      8 Tests that filenames that contain colons are handled correctly.
      9 (This is important for absolute paths on Windows.)
     10 """
     11 
     12 import os
     13 import sys
     14 import TestGyp
     15 
     16 # TODO: Make colons in filenames work with make, if required.
     17 test = TestGyp.TestGyp(formats=['!make', '!android'])
     18 CHDIR = 'colon'
     19 
     20 source_name = 'colon/a:b.c'
     21 copies_name = 'colon/a:b.c-d'
     22 if sys.platform == 'win32':
     23   # Windows uses : as drive separator and doesn't allow it in regular filenames.
     24   # Use abspath() to create a path that contains a colon instead.
     25   abs_source = os.path.abspath('colon/file.c')
     26   test.write('colon/test.gyp',
     27              test.read('colon/test.gyp').replace("'a:b.c'", repr(abs_source)))
     28   source_name = abs_source
     29 
     30   abs_copies = os.path.abspath('colon/file.txt')
     31   test.write('colon/test.gyp',
     32              test.read('colon/test.gyp').replace("'a:b.c-d'", repr(abs_copies)))
     33   copies_name = abs_copies
     34 
     35 # Create the file dynamically, Windows is unhappy if a file with a colon in
     36 # its name is checked in.
     37 test.write(source_name, 'int main() {}')
     38 test.write(copies_name, 'foo')
     39 
     40 test.run_gyp('test.gyp', chdir=CHDIR)
     41 test.build('test.gyp', test.ALL, chdir=CHDIR)
     42 test.built_file_must_exist(os.path.basename(copies_name), chdir=CHDIR)
     43 test.pass_test()
     44