Skip to content

Commit

Permalink
Better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ssorj committed Jan 19, 2024
1 parent 2e16de6 commit e54b2ac
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 51 deletions.
45 changes: 9 additions & 36 deletions .plano.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
16 changes: 13 additions & 3 deletions external/burly-main/external/plano-main/src/plano/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions install.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
87 changes: 87 additions & 0 deletions python/tests.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions uninstall.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit e54b2ac

Please sign in to comment.