diff --git a/.plano.py b/.plano.py index 15a3c39..04477fe 100644 --- a/.plano.py +++ b/.plano.py @@ -71,47 +71,20 @@ def build(): write("install.sh", install_sh) write("uninstall.sh", uninstall_sh) -@command -def clean(): - remove(find(".", "__pycache__")) - -@command -def test(shell="sh", verbose=False, debug=False): - check_program(shell) - +@command(passthrough=True) +def test(verbose=False, passthrough_args=[]): build() - if debug: - ENV["DEBUG"] = "1" + if verbose: + passthrough_args.append("--verbose") - try: - run(f"{shell} {'-o igncr' if WINDOWS else ''} install.sh {'--verbose' if verbose else ''}".strip()) - run(f"{shell} {'-o igncr' if WINDOWS else ''} uninstall.sh {'--verbose' if verbose else ''}".strip()) - finally: - if debug: - del ENV["DEBUG"] + import tests -@command -def big_test(verbose=False, debug=False): - """ - Run the tests against a range of shell interpreters - """ - test(verbose=True, debug=debug) - test(verbose=False, debug=debug) - - test(verbose=verbose, debug=True) - test(verbose=verbose, debug=False) - - for shell in "ash", "bash", "dash", "ksh", "mksh", "yash", "zsh": - if which(shell): - test(shell=shell, verbose=verbose, debug=debug) - - with working_env(): - run(f"sh install.sh") # No existing installation and no existing backup - run(f"sh install.sh") # Creates a backup - run(f"sh install.sh") # Backs up the backup + PlanoTestCommand(tests).main(passthrough_args) - run(f"sh uninstall.sh") +@command +def clean(): + remove(find(".", "__pycache__")) @command def lint(): diff --git a/external/burly-main/external/plano-main/src/plano/test.py b/external/burly-main/external/plano-main/src/plano/test.py index 0c2c6ae..fb87d8d 100644 --- a/external/burly-main/external/plano-main/src/plano/test.py +++ b/external/burly-main/external/plano-main/src/plano/test.py @@ -23,8 +23,10 @@ import argparse as _argparse import asyncio as _asyncio import fnmatch as _fnmatch +import functools as _functools import importlib as _importlib import inspect as _inspect +import sys as _sys import traceback as _traceback class PlanoTestCommand(BaseCommand): @@ -103,15 +105,20 @@ def run(self): class PlanoTestSkipped(Exception): pass -def test(_function=None, name=None, timeout=None, disabled=False): +def test(_function=None, name=None, module=None, timeout=None, disabled=False): class Test: def __init__(self, function): self.function = function - self.name = nvl(name, self.function.__name__.rstrip("_").replace("_", "-")) + self.name = name + self.module = module self.timeout = timeout self.disabled = disabled - self.module = _inspect.getmodule(self.function) + if self.name is None: + self.name = self.function.__name__.strip("_").replace("_", "-") + + if self.module is None: + self.module = _inspect.getmodule(self.function) if not hasattr(self.module, "_plano_tests"): self.module._plano_tests = list() @@ -136,6 +143,9 @@ def __repr__(self): else: return Test(_function) +def add_test(name, func, *args, **kwargs): + test(_functools.partial(func, *args, **kwargs), name=name, module=_inspect.getmodule(func)) + def skip_test(reason=None): if _inspect.stack()[2].frame.f_locals["unskipped"]: return diff --git a/install.sh b/install.sh index 443e8ff..53d4058 100644 --- a/install.sh +++ b/install.sh @@ -509,12 +509,12 @@ main() { esac case "${scheme}" in - home) local skupper_bin_dir="${HOME}/.local/bin" ;; - opt) local skupper_bin_dir="/opt/skupper/bin" ;; + home) local skupper_bin_dir="${TEST_INSTALL_PREFIX:-}${HOME}/.local/bin" ;; + opt) local skupper_bin_dir="${TEST_INSTALL_PREFIX:-}/opt/skupper/bin" ;; *) usage "Unknown installation scheme: ${scheme}" ;; esac - local work_dir="${HOME}/.cache/skupper-install-script" + local work_dir="${TEST_INSTALL_PREFIX:-}${HOME}/.cache/skupper-install-script" local log_file="${work_dir}/install.log" local backup_dir="${work_dir}/backup" diff --git a/install.sh.in b/install.sh.in index 4346917..3a4c990 100644 --- a/install.sh.in +++ b/install.sh.in @@ -202,12 +202,12 @@ main() { esac case "${scheme}" in - home) local skupper_bin_dir="${HOME}/.local/bin" ;; - opt) local skupper_bin_dir="/opt/skupper/bin" ;; + home) local skupper_bin_dir="${TEST_INSTALL_PREFIX:-}${HOME}/.local/bin" ;; + opt) local skupper_bin_dir="${TEST_INSTALL_PREFIX:-}/opt/skupper/bin" ;; *) usage "Unknown installation scheme: ${scheme}" ;; esac - local work_dir="${HOME}/.cache/skupper-install-script" + local work_dir="${TEST_INSTALL_PREFIX:-}${HOME}/.cache/skupper-install-script" local log_file="${work_dir}/install.log" local backup_dir="${work_dir}/backup" diff --git a/python/tests.py b/python/tests.py new file mode 100644 index 0000000..1f28d77 --- /dev/null +++ b/python/tests.py @@ -0,0 +1,87 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from plano import * + +ENV["TEST_INSTALL_PREFIX"] = make_temp_dir(prefix="skupper-install-script-") + +@test +def install(): + run(f"sh install.sh") + +@test +def uninstall(): + run(f"sh install.sh") + run(f"sh uninstall.sh") + +@test +def option_help(): + run(f"sh install.sh -h") + run(f"sh install.sh --help") + run(f"sh uninstall.sh -h") + run(f"sh uninstall.sh --help") + + with expect_error(): + run(f"sh install.sh --nope") + + with expect_error(): + run(f"sh uninstall.sh --not-at-all") + + with expect_error(): + run(f"sh install.sh nope") + + with expect_error(): + run(f"sh uninstall.sh not-at-all") + +@test +def option_interactive(): + run(f"echo yes | sh install.sh --interactive", shell=True) + run(f"echo no | sh install.sh --interactive", shell=True) + run(f"echo yes | sh uninstall.sh --interactive", shell=True) + run(f"echo no | sh uninstall.sh --interactive", shell=True) + +@test +def option_verbose(): + run(f"sh install.sh --verbose") + run(f"sh uninstall.sh --verbose") + +def test_shell(shell): + if not which(shell): + skip_test(f"Shell '{shell}' is not available") + + run(f"{shell} install.sh") # No existing installation and no existing backup + run(f"{shell} install.sh") # Creates a backup + run(f"{shell} install.sh") # Backs up the backup + run(f"{shell} uninstall.sh") + +def test_version(version): + run(f"sh install.sh --version {version}") + +def test_scheme(scheme): + run(f"sh install.sh --scheme {scheme}") + run(f"sh uninstall.sh --scheme {scheme}") + +for shell in "ash", "bash", "dash", "ksh", "mksh", "yash", "zsh": + add_test(f"shell-{shell}", test_shell, shell) + +for version in "latest", "main", "1.5.3": + add_test(f"version-{version}", test_version, version) + +for scheme in "home", "opt": + add_test(f"scheme-{scheme}", test_scheme, scheme) diff --git a/uninstall.sh b/uninstall.sh index 5d44884..116234b 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -336,12 +336,12 @@ main() { done case "${scheme}" in - home) local skupper_bin_dir="${HOME}/.local/bin" ;; - opt) local skupper_bin_dir="/opt/skupper/bin" ;; + home) local skupper_bin_dir="${TEST_INSTALL_PREFIX:-}${HOME}/.local/bin" ;; + opt) local skupper_bin_dir="${TEST_INSTALL_PREFIX:-}/opt/skupper/bin" ;; *) usage "Unknown installation scheme: ${scheme}" ;; esac - local work_dir="${HOME}/.cache/skupper-install-script" + local work_dir="${TEST_INSTALL_PREFIX:-}${HOME}/.cache/skupper-install-script" local log_file="${work_dir}/install.log" local backup_dir="${work_dir}/backup" diff --git a/uninstall.sh.in b/uninstall.sh.in index 711ae12..d32467a 100644 --- a/uninstall.sh.in +++ b/uninstall.sh.in @@ -99,12 +99,12 @@ main() { done case "${scheme}" in - home) local skupper_bin_dir="${HOME}/.local/bin" ;; - opt) local skupper_bin_dir="/opt/skupper/bin" ;; + home) local skupper_bin_dir="${TEST_INSTALL_PREFIX:-}${HOME}/.local/bin" ;; + opt) local skupper_bin_dir="${TEST_INSTALL_PREFIX:-}/opt/skupper/bin" ;; *) usage "Unknown installation scheme: ${scheme}" ;; esac - local work_dir="${HOME}/.cache/skupper-install-script" + local work_dir="${TEST_INSTALL_PREFIX:-}${HOME}/.cache/skupper-install-script" local log_file="${work_dir}/install.log" local backup_dir="${work_dir}/backup"