blob: 089fb7e7097f8a3015f05aa2b34f1822367cbd5d [file] [log] [blame]
# Copyright 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for"""
from __future__ import print_function
import os
from chromite.lib import cros_test_lib
from chromite.lib import osutils
from chromite.lib import unittest_lib
from chromite.scripts import dep_tracker
# Allow access private members for testing:
# pylint: disable=W0212
class MainTest(cros_test_lib.OutputTestCase):
"""Tests for the main() function."""
def testHelp(self):
"""Test that --help is functioning."""
argv = ['--help']
with self.OutputCapturer() as output:
# Running with --help should exit with code==0.
self.AssertFuncSystemExitZero(dep_tracker.main, argv)
# Verify that a message beginning with "usage: " was printed.
stdout = output.GetStdout()
self.assertTrue(stdout.startswith('usage: '))
class DepTrackerTest(cros_test_lib.TempDirTestCase):
"""Tests for the DepTracker() class."""
def testSimpleDep(self):
unittest_lib.BuildELF(os.path.join(self.tempdir, ''),
['func_a', 'func_b', 'func_c'])
unittest_lib.BuildELF(os.path.join(self.tempdir, 'abc_main'),
dt = dep_tracker.DepTracker(self.tempdir)
self.assertEquals(sorted(dt._files.keys()), ['abc_main', ''])
def testFiletypeSet(self):
"""Tests that the 'ftype' member is set for ELF files first."""
unittest_lib.BuildELF(os.path.join(self.tempdir, ''),
['func_a', 'func_b', 'func_c'])
osutils.WriteFile(os.path.join(self.tempdir, 'pyscript'),
"#!/usr/bin/python\nimport sys\nsys.exit(42)\n")
dt = dep_tracker.DepTracker(self.tempdir)
# ComputeELFFileDeps() should compute the file type of ELF files so we
# don't need to parse them again.
self.assertTrue('ftype' in dt._files[''])
self.assertFalse('ftype' in dt._files['pyscript'])
# ComputeFileTypes() shold compute the file type of every file.
self.assertTrue('ftype' in dt._files[''])
self.assertTrue('ftype' in dt._files['pyscript'])