Commit ca547f19 authored by Chandan Singh's avatar Chandan Singh Committed by Chandan Singh
Browse files

tests/frontend/buildcheckout.py: Fix bad filename issue for Windows

In BuildStream/buildstream!1028, we added a test specifically to test
that BuildStream correctly raises an warning when the name of an element
contains characters that are invalid on Windows. Unfortunately, we
didn't see it coming that it would make it impossible to checkout this
branch on Windows.

Fix it by generating this file, only if we are not running on Windows.

* tests/testutils/site.py: Add `IS_WINDOWS` check
* tests/frontend/buildcheckout.py: Generate file with invalid filename
  on the fly
* Remove tests/frontend/project/elements/invalid-chars.

Fixes #842.

Note that this may still cause issues on WSL when running tests on a
shared filesystem, but that seems to be a generic issue on WSL with
`os.rename`.
parent 669b55b0
Loading
Loading
Loading
Loading
Loading
+23 −1
Original line number Original line Diff line number Diff line
@@ -3,6 +3,7 @@ import tarfile
import hashlib
import hashlib
import pytest
import pytest
from tests.testutils import cli, create_repo, ALL_REPO_KINDS, generate_junction
from tests.testutils import cli, create_repo, ALL_REPO_KINDS, generate_junction
from tests.testutils.site import IS_WINDOWS


from buildstream import _yaml
from buildstream import _yaml
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from buildstream._exceptions import ErrorDomain, LoadErrorReason
@@ -85,16 +86,37 @@ def test_build_invalid_suffix_dep(datafiles, cli, strict, hardlinks):
    result.assert_main_error(ErrorDomain.LOAD, "bad-element-suffix")
    result.assert_main_error(ErrorDomain.LOAD, "bad-element-suffix")




@pytest.mark.skipif(IS_WINDOWS, reason='Not available on Windows')
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.datafiles(DATA_DIR)
def test_build_invalid_filename_chars(datafiles, cli):
def test_build_invalid_filename_chars(datafiles, cli):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    project = os.path.join(datafiles.dirname, datafiles.basename)
    result = cli.run(project=project, args=strict_args(['build', 'invalid-chars|<>-in-name.bst'], 'non-strict'))
    element_name = 'invalid-chars|<>-in-name.bst'

    # The name of this file contains characters that are not allowed by
    # BuildStream, using it should raise a warning.
    element = {
        'kind': 'stack',
    }
    _yaml.dump(element, os.path.join(project, 'elements', element_name))

    result = cli.run(project=project, args=strict_args(['build', element_name], 'non-strict'))
    result.assert_main_error(ErrorDomain.LOAD, "bad-characters-in-name")
    result.assert_main_error(ErrorDomain.LOAD, "bad-characters-in-name")




@pytest.mark.skipif(IS_WINDOWS, reason='Not available on Windows')
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.datafiles(DATA_DIR)
def test_build_invalid_filename_chars_dep(datafiles, cli):
def test_build_invalid_filename_chars_dep(datafiles, cli):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    project = os.path.join(datafiles.dirname, datafiles.basename)
    element_name = 'invalid-chars|<>-in-name.bst'

    # The name of this file contains characters that are not allowed by
    # BuildStream, and is listed as a dependency of 'invalid-chars-in-dep.bst'.
    # This should also raise a warning.
    element = {
        'kind': 'stack',
    }
    _yaml.dump(element, os.path.join(project, 'elements', element_name))

    result = cli.run(project=project, args=strict_args(['build', 'invalid-chars-in-dep.bst'], 'non-strict'))
    result = cli.run(project=project, args=strict_args(['build', 'invalid-chars-in-dep.bst'], 'non-strict'))
    result.assert_main_error(ErrorDomain.LOAD, "bad-characters-in-name")
    result.assert_main_error(ErrorDomain.LOAD, "bad-characters-in-name")


+0 −4
Original line number Original line Diff line number Diff line
kind: stack
description: |
  The name of this files contains characters that are not allowed by
  BuildStream, using it should raise a warning.
+1 −0
Original line number Original line Diff line number Diff line
@@ -52,5 +52,6 @@ except ImportError:
    HAVE_ARPY = False
    HAVE_ARPY = False


IS_LINUX = os.getenv('BST_FORCE_BACKEND', sys.platform).startswith('linux')
IS_LINUX = os.getenv('BST_FORCE_BACKEND', sys.platform).startswith('linux')
IS_WINDOWS = (os.name == 'nt')


MACHINE_ARCH = Platform.get_host_arch()
MACHINE_ARCH = Platform.get_host_arch()