Loading tests/completions/completions.py +38 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,13 @@ PROJECT_ELEMENTS = [ "target.bst" ] INVALID_ELEMENTS = [ "target.foo" "target.bst.bar" ] MIXED_ELEMENTS = PROJECT_ELEMENTS + INVALID_ELEMENTS def assert_completion(cli, cmd, word_idx, expected, cwd=None): result = cli.run(cwd=cwd, env={ Loading @@ -85,6 +92,24 @@ def assert_completion(cli, cmd, word_idx, expected, cwd=None): assert words == expected def assert_completion_failed(cli, cmd, word_idx, expected, cwd=None): result = cli.run(cwd=cwd, env={ '_BST_COMPLETION': 'complete', 'COMP_WORDS': cmd, 'COMP_CWORD': str(word_idx) }) words = [] if result.output: words = result.output.splitlines() # The order is meaningless, bash will # take the results and order it by its # own little heuristics words = sorted(words) expected = sorted(expected) assert words != expected @pytest.mark.parametrize("cmd,word_idx,expected", [ ('bst', 0, []), ('bst ', 1, MAIN_COMMANDS), Loading Loading @@ -226,6 +251,19 @@ def test_argument_element(datafiles, cli, project, cmd, word_idx, expected, subd assert_completion(cli, cmd, word_idx, expected, cwd=cwd) @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("project,cmd,word_idx,expected,subdir", [ # When element has invalid suffix ('project', 'bst --directory ../ show ', 4, [e + ' ' for e in MIXED_ELEMENTS], 'files') ]) def test_argument_element_invalid(datafiles, cli, project, cmd, word_idx, expected, subdir): cwd = os.path.join(str(datafiles), project) if subdir: cwd = os.path.join(cwd, subdir) assert_completion_failed(cli, cmd, word_idx, expected, cwd=cwd) @pytest.mark.parametrize("cmd,word_idx,expected", [ ('bst he', 1, ['help ']), ('bst help ', 2, MAIN_COMMANDS), Loading tests/frontend/buildcheckout.py +26 −1 Original line number Diff line number Diff line Loading @@ -60,9 +60,34 @@ def test_build_checkout(datafiles, cli, strict, hardlinks): assert os.path.exists(filename) @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("strict,hardlinks", [ ("non-strict", "hardlinks"), ]) def test_build_invalid_suffix(datafiles, cli, strict, hardlinks): project = os.path.join(datafiles.dirname, datafiles.basename) checkout = os.path.join(cli.directory, 'checkout') result = cli.run(project=project, args=strict_args(['build', 'target.foo'], strict)) result.assert_main_error(ErrorDomain.PLUGIN, "bad-element-suffix") @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("strict,hardlinks", [ ("non-strict", "hardlinks"), ]) def test_build_invalid_suffix_dep(datafiles, cli, strict, hardlinks): project = os.path.join(datafiles.dirname, datafiles.basename) checkout = os.path.join(cli.directory, 'checkout') # target2.bst depends on an element called target.foo result = cli.run(project=project, args=strict_args(['build', 'target2.bst'], strict)) result.assert_main_error(ErrorDomain.PLUGIN, "bad-element-suffix") @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("deps", [("run"), ("none")]) def test_build_checkout_deps(datafiles, cli, deps): def test_build_checkoue_deps(datafiles, cli, deps): project = os.path.join(datafiles.dirname, datafiles.basename) checkout = os.path.join(cli.directory, 'checkout') Loading tests/frontend/project/elements/target.foo 0 → 100644 +4 −0 Original line number Diff line number Diff line kind: stack description: | Main stack target for the bst build test tests/frontend/project/elements/target2.bst 0 → 100644 +7 −0 Original line number Diff line number Diff line kind: stack description: | Main stack target for the bst build test depends: - target.foo tests/frontend/project/project.conf +3 −0 Original line number Diff line number Diff line Loading @@ -2,3 +2,6 @@ name: test element-path: elements fatal-warnings: - bad-element-suffix Loading
tests/completions/completions.py +38 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,13 @@ PROJECT_ELEMENTS = [ "target.bst" ] INVALID_ELEMENTS = [ "target.foo" "target.bst.bar" ] MIXED_ELEMENTS = PROJECT_ELEMENTS + INVALID_ELEMENTS def assert_completion(cli, cmd, word_idx, expected, cwd=None): result = cli.run(cwd=cwd, env={ Loading @@ -85,6 +92,24 @@ def assert_completion(cli, cmd, word_idx, expected, cwd=None): assert words == expected def assert_completion_failed(cli, cmd, word_idx, expected, cwd=None): result = cli.run(cwd=cwd, env={ '_BST_COMPLETION': 'complete', 'COMP_WORDS': cmd, 'COMP_CWORD': str(word_idx) }) words = [] if result.output: words = result.output.splitlines() # The order is meaningless, bash will # take the results and order it by its # own little heuristics words = sorted(words) expected = sorted(expected) assert words != expected @pytest.mark.parametrize("cmd,word_idx,expected", [ ('bst', 0, []), ('bst ', 1, MAIN_COMMANDS), Loading Loading @@ -226,6 +251,19 @@ def test_argument_element(datafiles, cli, project, cmd, word_idx, expected, subd assert_completion(cli, cmd, word_idx, expected, cwd=cwd) @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("project,cmd,word_idx,expected,subdir", [ # When element has invalid suffix ('project', 'bst --directory ../ show ', 4, [e + ' ' for e in MIXED_ELEMENTS], 'files') ]) def test_argument_element_invalid(datafiles, cli, project, cmd, word_idx, expected, subdir): cwd = os.path.join(str(datafiles), project) if subdir: cwd = os.path.join(cwd, subdir) assert_completion_failed(cli, cmd, word_idx, expected, cwd=cwd) @pytest.mark.parametrize("cmd,word_idx,expected", [ ('bst he', 1, ['help ']), ('bst help ', 2, MAIN_COMMANDS), Loading
tests/frontend/buildcheckout.py +26 −1 Original line number Diff line number Diff line Loading @@ -60,9 +60,34 @@ def test_build_checkout(datafiles, cli, strict, hardlinks): assert os.path.exists(filename) @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("strict,hardlinks", [ ("non-strict", "hardlinks"), ]) def test_build_invalid_suffix(datafiles, cli, strict, hardlinks): project = os.path.join(datafiles.dirname, datafiles.basename) checkout = os.path.join(cli.directory, 'checkout') result = cli.run(project=project, args=strict_args(['build', 'target.foo'], strict)) result.assert_main_error(ErrorDomain.PLUGIN, "bad-element-suffix") @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("strict,hardlinks", [ ("non-strict", "hardlinks"), ]) def test_build_invalid_suffix_dep(datafiles, cli, strict, hardlinks): project = os.path.join(datafiles.dirname, datafiles.basename) checkout = os.path.join(cli.directory, 'checkout') # target2.bst depends on an element called target.foo result = cli.run(project=project, args=strict_args(['build', 'target2.bst'], strict)) result.assert_main_error(ErrorDomain.PLUGIN, "bad-element-suffix") @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("deps", [("run"), ("none")]) def test_build_checkout_deps(datafiles, cli, deps): def test_build_checkoue_deps(datafiles, cli, deps): project = os.path.join(datafiles.dirname, datafiles.basename) checkout = os.path.join(cli.directory, 'checkout') Loading
tests/frontend/project/elements/target.foo 0 → 100644 +4 −0 Original line number Diff line number Diff line kind: stack description: | Main stack target for the bst build test
tests/frontend/project/elements/target2.bst 0 → 100644 +7 −0 Original line number Diff line number Diff line kind: stack description: | Main stack target for the bst build test depends: - target.foo
tests/frontend/project/project.conf +3 −0 Original line number Diff line number Diff line Loading @@ -2,3 +2,6 @@ name: test element-path: elements fatal-warnings: - bad-element-suffix