diff options
author | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-12-31 19:49:24 +0000 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-12-31 19:49:24 +0000 |
commit | 560a634256839de4c9e8bcc41215a17c525d0e61 (patch) | |
tree | 08723954650e151d4b34f3a65c2892bcaebc6962 | |
parent | 32a101f67a5a1e751117a1b8976fe72bdd85526f (diff) | |
parent | d7c8b54dd9276c36a4878241cf330c2d66c10a63 (diff) | |
download | buildstream-560a634256839de4c9e8bcc41215a17c525d0e61.tar.gz |
Merge branch 'tristan/junction-tests' into 'master'
Junction test addition
See merge request BuildStream/buildstream!1029
-rw-r--r-- | tests/loader/junctions.py | 78 | ||||
-rw-r--r-- | tests/loader/junctions/invalid/missing-element.bst | 9 |
2 files changed, 47 insertions, 40 deletions
diff --git a/tests/loader/junctions.py b/tests/loader/junctions.py index 66c232b67..d97c9f702 100644 --- a/tests/loader/junctions.py +++ b/tests/loader/junctions.py @@ -3,7 +3,7 @@ import pytest import shutil from buildstream import _yaml, ElementError -from buildstream._exceptions import LoadError, LoadErrorReason +from buildstream._exceptions import ErrorDomain, LoadErrorReason from tests.testutils import cli, create_repo from tests.testutils.site import HAVE_GIT @@ -38,9 +38,9 @@ def test_simple_build(cli, tmpdir, datafiles): # Build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the checkout contains the expected files from both projects assert(os.path.exists(os.path.join(checkoutdir, 'base.txt'))) @@ -54,7 +54,7 @@ def test_build_of_same_junction_used_twice(cli, tmpdir, datafiles): # Check we can build a project that contains the same junction # that is used twice, but named differently result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() @pytest.mark.datafiles(DATA_DIR) @@ -69,9 +69,9 @@ def test_nested_simple(cli, tmpdir, datafiles): # Build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the checkout contains the expected files from all subprojects assert(os.path.exists(os.path.join(checkoutdir, 'base.txt'))) @@ -93,9 +93,9 @@ def test_nested_double(cli, tmpdir, datafiles): # Build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the checkout contains the expected files from all subprojects assert(os.path.exists(os.path.join(checkoutdir, 'base.txt'))) @@ -115,45 +115,46 @@ def test_nested_conflict(cli, datafiles): copy_subprojects(project, datafiles, ['foo', 'bar']) result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, LoadError) - assert result.exception.reason == LoadErrorReason.CONFLICTING_JUNCTION + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.CONFLICTING_JUNCTION) +# Test that we error correctly when the junction element itself is missing @pytest.mark.datafiles(DATA_DIR) -def test_invalid_missing(cli, datafiles): +def test_missing_junction(cli, datafiles): project = os.path.join(str(datafiles), 'invalid') result = cli.run(project=project, args=['build', 'missing.bst']) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, LoadError) - assert result.exception.reason == LoadErrorReason.MISSING_FILE + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE) +# Test that we error correctly when an element is not found in the subproject +@pytest.mark.datafiles(DATA_DIR) +def test_missing_subproject_element(cli, datafiles): + project = os.path.join(str(datafiles), 'invalid') + copy_subprojects(project, datafiles, ['base']) + + result = cli.run(project=project, args=['build', 'missing-element.bst']) + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE) + + +# Test that we error correctly when a junction itself has dependencies @pytest.mark.datafiles(DATA_DIR) def test_invalid_with_deps(cli, datafiles): project = os.path.join(str(datafiles), 'invalid') copy_subprojects(project, datafiles, ['base']) result = cli.run(project=project, args=['build', 'junction-with-deps.bst']) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, ElementError) - assert result.exception.reason == 'element-forbidden-depends' + result.assert_main_error(ErrorDomain.ELEMENT, 'element-forbidden-depends') +# Test that we error correctly when a junction is directly depended on @pytest.mark.datafiles(DATA_DIR) def test_invalid_junction_dep(cli, datafiles): project = os.path.join(str(datafiles), 'invalid') copy_subprojects(project, datafiles, ['base']) result = cli.run(project=project, args=['build', 'junction-dep.bst']) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, LoadError) - assert result.exception.reason == LoadErrorReason.INVALID_DATA + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA) @pytest.mark.datafiles(DATA_DIR) @@ -165,9 +166,9 @@ def test_options_default(cli, tmpdir, datafiles): # Build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() assert(os.path.exists(os.path.join(checkoutdir, 'pony.txt'))) assert(not os.path.exists(os.path.join(checkoutdir, 'horsy.txt'))) @@ -182,9 +183,9 @@ def test_options(cli, tmpdir, datafiles): # Build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() assert(not os.path.exists(os.path.join(checkoutdir, 'pony.txt'))) assert(os.path.exists(os.path.join(checkoutdir, 'horsy.txt'))) @@ -199,9 +200,9 @@ def test_options_inherit(cli, tmpdir, datafiles): # Build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() assert(not os.path.exists(os.path.join(checkoutdir, 'pony.txt'))) assert(os.path.exists(os.path.join(checkoutdir, 'horsy.txt'))) @@ -228,14 +229,11 @@ def test_git_show(cli, tmpdir, datafiles): # Verify that bst show does not implicitly fetch subproject result = cli.run(project=project, args=['show', 'target.bst']) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, LoadError) - assert result.exception.reason == LoadErrorReason.SUBPROJECT_FETCH_NEEDED + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.SUBPROJECT_FETCH_NEEDED) # Explicitly fetch subproject result = cli.run(project=project, args=['source', 'fetch', 'base.bst']) - assert result.exit_code == 0 + result.assert_success() # Check that bst show succeeds now and the pipeline includes the subproject element element_list = cli.get_pipeline(project, ['target.bst']) @@ -263,9 +261,9 @@ def test_git_build(cli, tmpdir, datafiles): # Build (with implicit fetch of subproject), checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the checkout contains the expected files from both projects assert(os.path.exists(os.path.join(checkoutdir, 'base.txt'))) @@ -304,9 +302,9 @@ def test_build_git_cross_junction_names(cli, tmpdir, datafiles): # Build (with implicit fetch of subproject), checkout result = cli.run(project=project, args=['build', 'base.bst:target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'base.bst:target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the checkout contains the expected files from both projects assert(os.path.exists(os.path.join(checkoutdir, 'base.txt'))) diff --git a/tests/loader/junctions/invalid/missing-element.bst b/tests/loader/junctions/invalid/missing-element.bst new file mode 100644 index 000000000..4c29221af --- /dev/null +++ b/tests/loader/junctions/invalid/missing-element.bst @@ -0,0 +1,9 @@ +# This refers to the `foo.bst` element through +# the `base.bst` junction. The `base.bst` junction +# exists but the `foo.bst` element does not exist +# in the subproject. +# +kind: stack +depends: +- junction: base.bst + filename: foo.bst |