about summary refs log tree commit diff
diff options
context:
space:
mode:
authorismailarilik <arilik.ismail@gmail.com>2024-11-12 07:28:23 +0300
committerismailarilik <arilik.ismail@gmail.com>2024-11-12 07:28:23 +0300
commit1ba72db24241d590ea0d009d7e07fe49ea79579c (patch)
tree849a580d2619cdfcc1e99be96a8b2745ca149636
parent6295686a37ed731f1059b07157170c9ac56bf8c3 (diff)
downloadrust-1ba72db24241d590ea0d009d7e07fe49ea79579c.tar.gz
rust-1ba72db24241d590ea0d009d7e07fe49ea79579c.zip
test(configure): cover `parse_args` in `src/bootstrap/configure.py`
-rw-r--r--src/bootstrap/bootstrap_test.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/bootstrap/bootstrap_test.py b/src/bootstrap/bootstrap_test.py
index 706f2c5bf07..70ed12b96e8 100644
--- a/src/bootstrap/bootstrap_test.py
+++ b/src/bootstrap/bootstrap_test.py
@@ -5,6 +5,7 @@ Run these with `x test bootstrap`, or `python -m unittest src/bootstrap/bootstra
 from __future__ import absolute_import, division, print_function
 import os
 import unittest
+from unittest.mock import patch
 import tempfile
 import hashlib
 import sys
@@ -99,6 +100,52 @@ class ProgramOutOfDate(unittest.TestCase):
         self.assertFalse(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
 
 
+class ParseArgsInConfigure(unittest.TestCase):
+    """Test if `parse_args` function in `configure.py` works properly"""
+    @patch("configure.err")
+    def test_unknown_args(self, err):
+        # It should be print an error message if the argument doesn't start with '--'
+        configure.parse_args(["enable-full-tools"])
+        err.assert_called_with("Option 'enable-full-tools' is not recognized")
+        err.reset_mock()
+        # It should be print an error message if the argument is not recognized
+        configure.parse_args(["--some-random-flag"])
+        err.assert_called_with("Option '--some-random-flag' is not recognized")
+
+    @patch("configure.err")
+    def test_need_value_args(self, err):
+        """It should print an error message if a required argument value is missing"""
+        configure.parse_args(["--target"])
+        err.assert_called_with("Option '--target' needs a value (--target=val)")
+
+    @patch("configure.err")
+    def test_option_checking(self, err):
+        # Options should be checked even if `--enable-option-checking` is not passed
+        configure.parse_args(["--target"])
+        err.assert_called_with("Option '--target' needs a value (--target=val)")
+        err.reset_mock()
+        # Options should be checked if `--enable-option-checking` is passed
+        configure.parse_args(["--enable-option-checking", "--target"])
+        err.assert_called_with("Option '--target' needs a value (--target=val)")
+        err.reset_mock()
+        # Options should not be checked if `--disable-option-checking` is passed
+        configure.parse_args(["--disable-option-checking", "--target"])
+        err.assert_not_called()
+
+    @patch("configure.parse_example_config", lambda known_args, _: known_args)
+    def test_known_args(self):
+        # It should contain known and correct arguments
+        known_args = configure.parse_args(["--enable-full-tools"])
+        self.assertTrue(known_args["full-tools"][0][1])
+        known_args = configure.parse_args(["--disable-full-tools"])
+        self.assertFalse(known_args["full-tools"][0][1])
+        # It should contain known arguments and their values
+        known_args = configure.parse_args(["--target=x86_64-unknown-linux-gnu"])
+        self.assertEqual(known_args["target"][0][1], "x86_64-unknown-linux-gnu")
+        known_args = configure.parse_args(["--target", "x86_64-unknown-linux-gnu"])
+        self.assertEqual(known_args["target"][0][1], "x86_64-unknown-linux-gnu")
+
+
 class GenerateAndParseConfig(unittest.TestCase):
     """Test that we can serialize and deserialize a config.toml file"""
     def test_no_args(self):