summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/cmd/debug.py
blob: 6a240a0ca7d6bcec7acb59ec9e58cf19a12d6661 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import os
import os.path
import platform

import pytest

import spack.config
import spack.platforms
from spack.main import SpackCommand, get_version
from spack.util.executable import which

debug = SpackCommand("debug")

pytestmark = pytest.mark.not_on_windows("does not run on windows")


@pytest.mark.db
def test_create_db_tarball(tmpdir, database):
    with tmpdir.as_cwd():
        debug("create-db-tarball")

        # get the first non-dotfile to avoid coverage files in the directory
        files = os.listdir(os.getcwd())
        tarball_name = next(
            f for f in files if not f.startswith(".") and not f.startswith("tests")
        )

        # debug command made an archive
        assert os.path.exists(tarball_name)

        # print contents of archive
        tar = which("tar")
        contents = tar("tzf", tarball_name, output=str)

        # DB file is included
        assert "index.json" in contents

        # specfiles from all installs are included
        for spec in database.query():
            # externals won't have a specfile
            if spec.external:
                continue

            spec_suffix = "%s/.spack/spec.json" % spec.dag_hash()
            assert spec_suffix in contents


def test_report():
    out = debug("report")
    host_platform = spack.platforms.host()
    host_os = host_platform.operating_system("frontend")
    host_target = host_platform.target("frontend")
    architecture = spack.spec.ArchSpec((str(host_platform), str(host_os), str(host_target)))

    assert get_version() in out
    assert platform.python_version() in out
    assert str(architecture) in out
    assert spack.config.get("config:concretizer") in out