blob: e340b11366aa2b4071967c7d975ef62fb6b4b2a9 [file] [log] [blame]
Alex Deymo3cfb9cd2014-08-18 15:56:35 -07001#!/usr/bin/python
2# Copyright 2014 The Chromium OS 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
6"""Unit tests for dep_tracker.py."""
7
8import os
9
10from chromite.lib import cros_test_lib
11from chromite.lib import unittest_lib
12from chromite.scripts import dep_tracker
13
14# Allow access private members for testing:
15# pylint: disable=W0212
16
17
18class MainTest(cros_test_lib.MoxOutputTestCase):
19 """Tests for the main() function."""
20
21 def testHelp(self):
22 """Test that --help is functioning."""
23 argv = [ '--help' ]
24
25 with self.OutputCapturer() as output:
26 # Running with --help should exit with code==0.
27 self.AssertFuncSystemExitZero(dep_tracker.main, argv)
28
29 # Verify that a message beginning with "usage: " was printed.
30 stdout = output.GetStdout()
31 self.assertTrue(stdout.startswith('usage: '))
32
33
34class DepTrackerTest(cros_test_lib.TempDirTestCase):
35 """Tests for the DepTracker() class."""
36
37 def testSimpleDep(self):
38 unittest_lib.BuildELF(os.path.join(self.tempdir, 'libabc.so'),
39 ['func_a', 'func_b', 'func_c'])
40 unittest_lib.BuildELF(os.path.join(self.tempdir, 'abc_main'),
41 undefined_symbols=['func_b'],
42 used_libs=['abc'],
43 executable=True)
44 dt = dep_tracker.DepTracker(self.tempdir)
45 dt.Init()
46 dt.ComputeELFFileDeps()
47
48 self.assertEquals(sorted(dt._files.keys()), ['abc_main', 'libabc.so'])
49
50
51if __name__ == '__main__':
52 cros_test_lib.main()