2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
10 SCRIPT_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
11 PARENT_DIR
= os
.path
.dirname(SCRIPT_DIR
)
12 DATA_DIR
= os
.path
.join(SCRIPT_DIR
, 'data')
13 CHROME_SRC
= os
.path
.dirname(os
.path
.dirname(os
.path
.dirname(PARENT_DIR
)))
14 MOCK_DIR
= os
.path
.join(CHROME_SRC
, "third_party", "pymock")
16 # For the mock library
17 sys
.path
.append(MOCK_DIR
)
18 sys
.path
.append(PARENT_DIR
)
24 class TestFixDeps(unittest
.TestCase
):
30 os
.remove(self
.tempfile
)
32 def testRequiresFile(self
):
33 with mock
.patch('sys.stderr'):
34 self
.assertRaises(SystemExit, fix_deps
.main
, [])
36 def testInvalidOption(self
):
37 with mock
.patch('sys.stderr'):
38 self
.assertRaises(SystemExit, fix_deps
.main
, ['--foo', 'bar'])
40 def testMissingFile(self
):
41 with mock
.patch('sys.stderr'):
42 self
.assertRaises(fix_deps
.Error
, fix_deps
.main
, ['nonexistent.file'])
44 def testAddsDeps(self
):
45 self
.tempfile
= tempfile
.mktemp("_sdktest")
46 with
open(self
.tempfile
, 'w') as out
:
47 out
.write('foo.o: foo.c foo.h bar.h\n')
48 fix_deps
.FixupDepFile(self
.tempfile
)
49 with
open(self
.tempfile
) as infile
:
50 contents
= infile
.read()
51 lines
= contents
.splitlines()
52 self
.assertEqual(len(lines
), 5)
53 self
.assertTrue('foo.c:' in lines
)
54 self
.assertTrue('foo.h:' in lines
)
55 self
.assertTrue('bar.h:' in lines
)
57 def testSpacesInFilenames(self
):
58 self
.tempfile
= tempfile
.mktemp("_sdktest")
59 with
open(self
.tempfile
, 'w') as out
:
60 out
.write('foo.o: foo\\ bar.h\n')
61 fix_deps
.FixupDepFile(self
.tempfile
)
62 with
open(self
.tempfile
) as infile
:
63 contents
= infile
.read()
64 lines
= contents
.splitlines()
65 self
.assertEqual(len(lines
), 3)
66 self
.assertEqual(lines
[2], 'foo\\ bar.h:')
68 def testColonInFilename(self
):
69 self
.tempfile
= tempfile
.mktemp("_sdktest")
70 with
open(self
.tempfile
, 'w') as out
:
71 out
.write('foo.o: c:foo.c\\\n c:bar.h\n')
72 fix_deps
.FixupDepFile(self
.tempfile
)
73 with
open(self
.tempfile
) as infile
:
74 contents
= infile
.read()
75 lines
= contents
.splitlines()
76 self
.assertEqual(len(lines
), 5)
77 self
.assertEqual(lines
[3], 'c:foo.c:')
78 self
.assertEqual(lines
[4], 'c:bar.h:')
80 def testDoubleInvoke(self
):
81 self
.tempfile
= tempfile
.mktemp("_sdktest")
82 with
open(self
.tempfile
, 'w') as out
:
83 out
.write('foo.o: foo\\ bar.h\n')
84 fix_deps
.FixupDepFile(self
.tempfile
)
85 self
.assertRaises(fix_deps
.Error
, fix_deps
.FixupDepFile
, self
.tempfile
)
88 if __name__
== '__main__':