|
5 | 5 | from __future__ import absolute_import, division, print_function
|
6 | 6 | import os
|
7 | 7 | import unittest
|
| 8 | +from unittest.mock import patch |
8 | 9 | import tempfile
|
9 | 10 | import hashlib
|
10 | 11 | import sys
|
@@ -99,6 +100,52 @@ def test_same_dates(self):
|
99 | 100 | self.assertFalse(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
|
100 | 101 |
|
101 | 102 |
|
| 103 | +class ParseArgsInConfigure(unittest.TestCase): |
| 104 | + """Test if `parse_args` function in `configure.py` works properly""" |
| 105 | + @patch("configure.err") |
| 106 | + def test_unknown_args(self, err): |
| 107 | + # It should be print an error message if the argument doesn't start with '--' |
| 108 | + configure.parse_args(["enable-full-tools"]) |
| 109 | + err.assert_called_with("Option 'enable-full-tools' is not recognized") |
| 110 | + err.reset_mock() |
| 111 | + # It should be print an error message if the argument is not recognized |
| 112 | + configure.parse_args(["--some-random-flag"]) |
| 113 | + err.assert_called_with("Option '--some-random-flag' is not recognized") |
| 114 | + |
| 115 | + @patch("configure.err") |
| 116 | + def test_need_value_args(self, err): |
| 117 | + """It should print an error message if a required argument value is missing""" |
| 118 | + configure.parse_args(["--target"]) |
| 119 | + err.assert_called_with("Option '--target' needs a value (--target=val)") |
| 120 | + |
| 121 | + @patch("configure.err") |
| 122 | + def test_option_checking(self, err): |
| 123 | + # Options should be checked even if `--enable-option-checking` is not passed |
| 124 | + configure.parse_args(["--target"]) |
| 125 | + err.assert_called_with("Option '--target' needs a value (--target=val)") |
| 126 | + err.reset_mock() |
| 127 | + # Options should be checked if `--enable-option-checking` is passed |
| 128 | + configure.parse_args(["--enable-option-checking", "--target"]) |
| 129 | + err.assert_called_with("Option '--target' needs a value (--target=val)") |
| 130 | + err.reset_mock() |
| 131 | + # Options should not be checked if `--disable-option-checking` is passed |
| 132 | + configure.parse_args(["--disable-option-checking", "--target"]) |
| 133 | + err.assert_not_called() |
| 134 | + |
| 135 | + @patch("configure.parse_example_config", lambda known_args, _: known_args) |
| 136 | + def test_known_args(self): |
| 137 | + # It should contain known and correct arguments |
| 138 | + known_args = configure.parse_args(["--enable-full-tools"]) |
| 139 | + self.assertTrue(known_args["full-tools"][0][1]) |
| 140 | + known_args = configure.parse_args(["--disable-full-tools"]) |
| 141 | + self.assertFalse(known_args["full-tools"][0][1]) |
| 142 | + # It should contain known arguments and their values |
| 143 | + known_args = configure.parse_args(["--target=x86_64-unknown-linux-gnu"]) |
| 144 | + self.assertEqual(known_args["target"][0][1], "x86_64-unknown-linux-gnu") |
| 145 | + known_args = configure.parse_args(["--target", "x86_64-unknown-linux-gnu"]) |
| 146 | + self.assertEqual(known_args["target"][0][1], "x86_64-unknown-linux-gnu") |
| 147 | + |
| 148 | + |
102 | 149 | class GenerateAndParseConfig(unittest.TestCase):
|
103 | 150 | """Test that we can serialize and deserialize a config.toml file"""
|
104 | 151 | def test_no_args(self):
|
|
0 commit comments