#!/usr/bin/python3
"""Tests for slpkg.toml_errors.TomlErrors.raise_toml_error_message()."""

from pathlib import Path

import pytest

from slpkg.toml_errors import TomlErrors

# TomlErrors.__init__ has no dependencies — construct directly.


def test_toml_errors_prog_name_hardcoded() -> None:
    """prog_name is always 'slpkg', independent of config_load."""
    te = TomlErrors()
    assert te.prog_name == "slpkg"


def test_raise_toml_error_message_does_not_raise() -> None:
    """raise_toml_error_message prints but does NOT raise SystemExit."""
    te = TomlErrors()
    # Should complete without exception
    te.raise_toml_error_message("invalid key", Path("/fake/file.toml"))


def test_raise_toml_error_message_output_contains_prog_name(capsys: pytest.CaptureFixture) -> None:
    te = TomlErrors()
    te.raise_toml_error_message("invalid key", Path("/fake/file.toml"))
    captured = capsys.readouterr()
    assert "slpkg" in captured.out


def test_raise_toml_error_message_output_contains_error(capsys: pytest.CaptureFixture) -> None:
    te = TomlErrors()
    te.raise_toml_error_message("unexpected value", Path("/etc/slpkg/slpkg.toml"))
    captured = capsys.readouterr()
    assert "unexpected value" in captured.out


def test_raise_toml_error_message_output_contains_file_path(capsys: pytest.CaptureFixture) -> None:
    te = TomlErrors()
    fake_path = Path("/etc/slpkg/repos.toml")
    te.raise_toml_error_message("bad syntax", fake_path)
    captured = capsys.readouterr()
    assert str(fake_path) in captured.out


def test_raise_toml_error_message_mentions_new_configs(capsys: pytest.CaptureFixture) -> None:
    """Output should hint at slpkg_new-configs command."""
    te = TomlErrors()
    te.raise_toml_error_message("some error", Path("/tmp/test.toml"))
    captured = capsys.readouterr()
    assert "slpkg_new-configs" in captured.out


def test_raise_toml_error_message_output_contains_configuration(capsys: pytest.CaptureFixture) -> None:
    te = TomlErrors()
    te.raise_toml_error_message("parse error", Path("/tmp/test.toml"))
    captured = capsys.readouterr()
    assert "configuration" in captured.out
