|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# |
| 4 | +# CDDL HEADER START |
| 5 | +# |
| 6 | +# The contents of this file are subject to the terms of the |
| 7 | +# Common Development and Distribution License (the "License"). |
| 8 | +# You may not use this file except in compliance with the License. |
| 9 | +# |
| 10 | +# See LICENSE.txt included in this distribution for the specific |
| 11 | +# language governing permissions and limitations under the License. |
| 12 | +# |
| 13 | +# When distributing Covered Code, include this CDDL HEADER in each |
| 14 | +# file and include the License file at LICENSE.txt. |
| 15 | +# If applicable, add the following below this CDDL HEADER, with the |
| 16 | +# fields enclosed by brackets "[]" replaced with your own identifying |
| 17 | +# information: Portions Copyright [yyyy] [name of copyright owner] |
| 18 | +# |
| 19 | +# CDDL HEADER END |
| 20 | +# |
| 21 | + |
| 22 | +# |
| 23 | +# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
| 24 | +# |
| 25 | + |
| 26 | +import os |
| 27 | + |
| 28 | +import pytest |
| 29 | + |
| 30 | +from opengrok_tools.utils.commandsequence import CommandSequence, \ |
| 31 | + CommandSequenceBase |
| 32 | + |
| 33 | + |
| 34 | +def test_str(): |
| 35 | + cmds = CommandSequence(CommandSequenceBase("opengrok-master", |
| 36 | + [{"command": ['foo']}, |
| 37 | + {"command": ["bar"]}])) |
| 38 | + assert str(cmds) == "opengrok-master" |
| 39 | + |
| 40 | + |
| 41 | +@pytest.mark.skipif(not os.path.exists('/bin/sh') |
| 42 | + or not os.path.exists('/bin/echo'), |
| 43 | + reason="requires Unix") |
| 44 | +def test_run_retcodes(): |
| 45 | + cmd_list = [{"command": ["/bin/echo"]}, |
| 46 | + {"command": ["/bin/sh", "-c", |
| 47 | + "echo " + CommandSequence.PROJECT_SUBST + "; exit 0"]}, |
| 48 | + {"command": ["/bin/sh", "-c", |
| 49 | + "echo " + CommandSequence.PROJECT_SUBST + "; exit 1"]}] |
| 50 | + cmds = CommandSequence(CommandSequenceBase("opengrok-master", cmd_list)) |
| 51 | + cmds.run() |
| 52 | + assert cmds.retcodes == { |
| 53 | + '/bin/echo opengrok-master': 0, |
| 54 | + '/bin/sh -c echo opengrok-master; exit 0': 0, |
| 55 | + '/bin/sh -c echo opengrok-master; exit 1': 1 |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | +@pytest.mark.skipif(not os.path.exists('/bin/sh') |
| 60 | + or not os.path.exists('/bin/echo'), |
| 61 | + reason="requires Unix") |
| 62 | +def test_terminate_after_non_zero_code(): |
| 63 | + cmd_list = [{"command": ["/bin/sh", "-c", |
| 64 | + "echo " + CommandSequence.PROJECT_SUBST + "; exit 255"]}, |
| 65 | + {"command": ["/bin/echo"]}] |
| 66 | + cmds = CommandSequence(CommandSequenceBase("opengrok-master", cmd_list)) |
| 67 | + cmds.run() |
| 68 | + assert cmds.retcodes == { |
| 69 | + '/bin/sh -c echo opengrok-master; exit 255': 255 |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | +@pytest.mark.skipif(not os.path.exists('/bin/sh') |
| 74 | + or not os.path.exists('/bin/echo'), |
| 75 | + reason="requires Unix") |
| 76 | +def test_exit_2_handling(): |
| 77 | + cmd_list = [{"command": ["/bin/sh", "-c", |
| 78 | + "echo " + CommandSequence.PROJECT_SUBST + "; exit 2"]}, |
| 79 | + {"command": ["/bin/echo"]}] |
| 80 | + cmds = CommandSequence(CommandSequenceBase("opengrok-master", cmd_list)) |
| 81 | + cmds.run() |
| 82 | + assert cmds.retcodes == { |
| 83 | + '/bin/sh -c echo opengrok-master; exit 2': 2 |
| 84 | + } |
| 85 | + assert not cmds.failed |
| 86 | + |
| 87 | + |
| 88 | +@pytest.mark.skipif(not os.path.exists('/bin/sh') |
| 89 | + or not os.path.exists('/bin/echo'), |
| 90 | + reason="requires Unix") |
| 91 | +def test_driveon_flag(): |
| 92 | + cmd_list = [{"command": ["/bin/sh", "-c", |
| 93 | + "echo " + CommandSequence.PROJECT_SUBST + "; exit 2"]}, |
| 94 | + {"command": ["/bin/echo"]}, |
| 95 | + {"command": ["/bin/sh", "-c", |
| 96 | + "echo " + CommandSequence.PROJECT_SUBST + |
| 97 | + "; exit 1"]}, |
| 98 | + {"command": ["/bin/sh", "-c", |
| 99 | + "echo " + CommandSequence.PROJECT_SUBST]}] |
| 100 | + cmds = CommandSequence(CommandSequenceBase("opengrok-master", |
| 101 | + cmd_list, driveon=True)) |
| 102 | + cmds.run() |
| 103 | + assert cmds.retcodes == { |
| 104 | + '/bin/sh -c echo opengrok-master; exit 2': 2, |
| 105 | + '/bin/echo opengrok-master': 0, |
| 106 | + '/bin/sh -c echo opengrok-master; exit 1': 1 |
| 107 | + } |
| 108 | + assert cmds.failed |
| 109 | + |
| 110 | + |
| 111 | +@pytest.mark.skipif(not os.path.exists('/bin/echo'), |
| 112 | + reason="requires Unix") |
| 113 | +def test_project_subst(): |
| 114 | + cmd_list = [{"command": ["/bin/echo", CommandSequence.PROJECT_SUBST]}] |
| 115 | + cmds = CommandSequence(CommandSequenceBase("test-subst", cmd_list)) |
| 116 | + cmds.run() |
| 117 | + |
| 118 | + assert cmds.outputs['/bin/echo test-subst'] == ['test-subst\n'] |
0 commit comments