Alex Klein | 8212d49 | 2018-08-27 07:47:23 -0600 | [diff] [blame] | 1 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Test install_toolchain.""" |
| 6 | |
Alex Klein | 8212d49 | 2018-08-27 07:47:23 -0600 | [diff] [blame] | 7 | import os |
| 8 | |
| 9 | from chromite.lib import cros_test_lib |
| 10 | from chromite.lib import osutils |
| 11 | from chromite.lib import sysroot_lib |
| 12 | from chromite.scripts import install_toolchain |
| 13 | |
| 14 | |
Alex Klein | 8212d49 | 2018-08-27 07:47:23 -0600 | [diff] [blame] | 15 | class ParseArgsTest(cros_test_lib.TempDirTestCase): |
| 16 | """Tests for argument parsing and validation rules.""" |
| 17 | |
| 18 | # pylint: disable=protected-access |
| 19 | def setUp(self): |
| 20 | D = cros_test_lib.Directory |
| 21 | filesystem = ( |
| 22 | D('build', ( |
| 23 | D('board', ( |
| 24 | D('etc', ( |
| 25 | 'make.conf.board_setup', |
| 26 | )), |
| 27 | )), |
| 28 | )), |
| 29 | ) |
| 30 | cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem) |
| 31 | |
| 32 | self.chost_value = 'chost' |
| 33 | osutils.WriteFile(os.path.join(self.tempdir, |
| 34 | 'build/board/etc/make.conf.board_setup'), |
| 35 | 'CHOST="%s"' % self.chost_value) |
| 36 | |
| 37 | self.sysroot_dir = os.path.join(self.tempdir, 'build/board') |
Alex Klein | 8212d49 | 2018-08-27 07:47:23 -0600 | [diff] [blame] | 38 | |
| 39 | def testInvalidArgs(self): |
| 40 | """Test invalid argument parsing.""" |
| 41 | with self.assertRaises(SystemExit): |
| 42 | install_toolchain._ParseArgs([]) |
| 43 | |
| 44 | def testSysrootCreate(self): |
| 45 | """Test the sysroot is correctly built.""" |
| 46 | opts = install_toolchain._ParseArgs(['--sysroot', self.sysroot_dir]) |
| 47 | self.assertIsInstance(opts.sysroot, sysroot_lib.Sysroot) |
| 48 | self.assertEqual(self.sysroot_dir, opts.sysroot.path) |
| 49 | |
| 50 | def testToolchain(self): |
| 51 | """Test toolchain arg precedence/fallback.""" |
| 52 | toolchain = 'toolchain' |
| 53 | opts = install_toolchain._ParseArgs(['--sysroot', self.sysroot_dir, |
| 54 | '--toolchain', toolchain]) |
| 55 | self.assertEqual(toolchain, opts.toolchain) |
| 56 | |
| 57 | opts = install_toolchain._ParseArgs(['--sysroot', self.sysroot_dir]) |
| 58 | self.assertEqual(self.chost_value, opts.toolchain) |