Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(configure): cover parse_args in src/bootstrap/configure.py #132771

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/bootstrap/bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import absolute_import, division, print_function
import os
import unittest
from unittest.mock import patch
import tempfile
import hashlib
import sys
Expand Down Expand Up @@ -99,6 +100,52 @@ def test_same_dates(self):
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):
Expand Down
Loading