DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Line Code
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 64 65 66 67 68 69 70 71
#!/usr/bin/env python

from __future__ import absolute_import

import os

import mozunit
import pytest

from conftest import fspath


def test_save_path_not_present(check_for_crashes, minidump_files, tmpdir):
    """Test that dump_save_path works when the directory doesn't exist."""
    save_path = tmpdir.join("saved")

    assert 1 == check_for_crashes(dump_save_path=fspath(save_path))

    assert save_path.join(minidump_files[0]["dmp"].basename).check()
    assert save_path.join(minidump_files[0]["extra"].basename).check()


def test_save_path(check_for_crashes, minidump_files, tmpdir):
    """Test that dump_save_path works."""
    save_path = tmpdir.mkdir("saved")

    assert 1 == check_for_crashes(dump_save_path=fspath(save_path))

    assert save_path.join(minidump_files[0]["dmp"].basename).check()
    assert save_path.join(minidump_files[0]["extra"].basename).check()


def test_save_path_isfile(check_for_crashes, minidump_files, tmpdir):
    """Test that dump_save_path works when the path is a file and not a directory."""
    save_path = tmpdir.join("saved")
    save_path.write("junk")

    assert 1 == check_for_crashes(dump_save_path=fspath(save_path))

    assert save_path.join(minidump_files[0]["dmp"].basename).check()
    assert save_path.join(minidump_files[0]["extra"].basename).check()


def test_save_path_envvar(check_for_crashes, minidump_files, tmpdir):
    """Test that the MINDUMP_SAVE_PATH environment variable works."""
    save_path = tmpdir.mkdir("saved")

    os.environ['MINIDUMP_SAVE_PATH'] = fspath(save_path)
    try:
        assert 1 == check_for_crashes(dump_save_path=None)
    finally:
        del os.environ['MINIDUMP_SAVE_PATH']

    assert save_path.join(minidump_files[0]["dmp"].basename).check()
    assert save_path.join(minidump_files[0]["extra"].basename).check()


@pytest.mark.parametrize('minidump_files', [3], indirect=True)
def test_save_multiple(check_for_crashes, minidump_files, tmpdir):
    """Test that all minidumps are saved."""
    save_path = tmpdir.mkdir("saved")

    assert 3 == check_for_crashes(dump_save_path=fspath(save_path))

    for i in range(3):
        assert save_path.join(minidump_files[i]["dmp"].basename).check()
        assert save_path.join(minidump_files[i]["extra"].basename).check()


if __name__ == '__main__':
    mozunit.main()