|
5 | 5 | work correctly and return expected version information. |
6 | 6 | """ |
7 | 7 |
|
8 | | -from pathlib import Path |
9 | 8 | from typing import Any |
10 | 9 |
|
11 | | -from .utils import run_in_venv |
| 10 | +import pytest |
| 11 | + |
| 12 | +from .utils import run_command |
12 | 13 |
|
13 | 14 |
|
14 | 15 | class TestVersionVerification: # pylint: disable=too-few-public-methods |
15 | 16 | """Test solc-select version verification behavior.""" |
16 | 17 |
|
17 | | - def test_all_versions_work_correctly(self, isolated_python_env: Any) -> None: |
| 18 | + @pytest.mark.parametrize("test_mode", [pytest.param("all", marks=pytest.mark.slow), "some"]) |
| 19 | + def test_all_versions_work_correctly(self, isolated_solc_data: Any, test_mode: str) -> None: |
18 | 20 | """ |
19 | | - Test that all installed Solidity versions work correctly. |
| 21 | + Test that installed Solidity versions work correctly. |
20 | 22 |
|
21 | | - This test installs all available Solidity versions using solc-select, |
| 23 | + This test installs Solidity versions using solc-select (either all or some specific ones), |
22 | 24 | then verifies each version by running `solc --version` and checking |
23 | 25 | that the output contains "solidity compiler" and the correct version number. |
24 | 26 | """ |
25 | | - venv = isolated_python_env |
26 | | - project_root = Path(__file__).parent.parent |
27 | | - |
28 | | - # Install development version of solc-select |
29 | | - run_in_venv(venv, f"pip install -e {project_root}", check=True) |
30 | | - |
31 | | - # Install all available versions |
32 | | - run_in_venv(venv, "solc-select install all", check=True) |
| 27 | + if test_mode == "all": |
| 28 | + # Install all available versions |
| 29 | + run_command("solc-select install all", check=True) |
| 30 | + else: # test_mode == "some" |
| 31 | + # Install specific versions in one call |
| 32 | + specific_versions = ["0.4.11", "0.7.3", "0.8.10", "0.8.30"] |
| 33 | + run_command(f"solc-select install {' '.join(specific_versions)}", check=True) |
33 | 34 |
|
34 | 35 | # Get list of all installed versions |
35 | | - result = run_in_venv(venv, "solc-select versions", check=True) |
| 36 | + result = run_command("solc-select versions", check=True) |
36 | 37 | versions = [line.strip() for line in result.stdout.strip().split("\n") if line.strip()] |
37 | 38 |
|
38 | 39 | assert versions, "No versions found - installation may have failed" |
39 | 40 |
|
40 | 41 | # Test each version |
41 | 42 | for version in versions: |
42 | 43 | # Run solc --version with the specific version set |
43 | | - result = run_in_venv(venv, f"SOLC_VERSION={version} solc --version", check=True) |
| 44 | + result = run_command(f"SOLC_VERSION={version} solc --version", check=True) |
44 | 45 | output = result.stdout.lower() |
45 | 46 |
|
46 | 47 | # Check that output contains "solidity compiler" and the version |
47 | 48 | assert "solidity compiler" in output, ( |
48 | 49 | f"Version {version}: Missing 'solidity compiler' in output" |
49 | 50 | ) |
50 | 51 | assert version in output, f"Version {version}: Version number not found in output" |
| 52 | + |
| 53 | + def test_no_global_version_selected_error(self, isolated_solc_data: Any) -> None: |
| 54 | + """ |
| 55 | + Test that running solc without a global version selected throws an error. |
| 56 | + """ |
| 57 | + # Install at least one version but don't select it globally |
| 58 | + run_command("solc-select install 0.8.10", check=True) |
| 59 | + |
| 60 | + # Try to run solc without setting a global version - this should fail |
| 61 | + result = run_command("solc --version", check=False) |
| 62 | + |
| 63 | + # Should have non-zero exit code and error message about no version selected |
| 64 | + assert result.returncode != 0, "Expected solc to fail when no version is selected" |
| 65 | + error_output = result.stdout.lower() |
| 66 | + assert "no solc version set" in error_output, ( |
| 67 | + f"Expected error about no version selected, got: {result.stdout}" |
| 68 | + ) |
0 commit comments