[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / native_client_sdk / src / tools / tests / fix_deps_test.py
blobd02f8ac12e136e404a4d65109929723a01659644
1 #!/usr/bin/env python
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.
5 import os
6 import sys
7 import tempfile
8 import unittest
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)
20 import fix_deps
21 import mock
24 class TestFixDeps(unittest.TestCase):
25 def setUp(self):
26 self.tempfile = None
28 def tearDown(self):
29 if self.tempfile:
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__':
89 unittest.main()