Changeset - ac8884ab98ca
[Not reviewed]
0 1 0
Branko Majic (branko) - 18 days ago 2024-09-09 22:21:31
branko@majic.rs
MAR-218: Fix some minor issues for the test runner script:

- No need to use the $ variable syntax for arithmetic operations.
- Use correct form when printing the list of roles (@ -> *).
- Fix missing quote when assembling the list of roles.
1 file changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
scripts/run_tests.sh
Show inline comments
 
@@ -88,25 +88,25 @@ $program
 
| GNU General Public License for more details.                          |
 
|                                                                       |
 
| You should have received a copy of the GNU General Public License     |
 
| along with this program.  If not, see <http://www.gnu.org/licenses/>. |
 
+-----------------------------------------------------------------------+
 

	
 
EOF
 
}
 

	
 
# Set-up colours for message printing if we're not piping and terminal is
 
# capable of outputting the colors.
 
_color_terminal=$(tput colors 2>&1)
 
if [[ -t 1 ]] && (( ${_color_terminal} > 0 )); then
 
if [[ -t 1 ]] && (( _color_terminal > 0 )); then
 
    _text_bold=$(tput bold)
 
    _text_white=$(tput setaf 7)
 
    _text_blue=$(tput setaf 6)
 
    _text_green=$(tput setaf 2)
 
    _text_yellow=$(tput setaf 3)
 
    _text_red=$(tput setaf 1)
 
    _text_reset=$(tput sgr0)
 
else
 
    _text_bold=""
 
    _text_white=""
 
    _text_blue=""
 
    _text_green=""
 
@@ -165,25 +165,25 @@ while getopts "rl:qdvh" opt; do
 
        r) report=1;;
 
        l) tests="$OPTARG";;
 
	d) debug=1;;
 
        v) version
 
           exit "$SUCCESS";;
 
        h) usage
 
           exit "$SUCCESS";;
 
        *) usage
 
           exit "$ERROR_ARGUMENTS";;
 
    esac
 
done
 
i=$OPTIND
 
shift $(($i-1))
 
shift $(( i-1 ))
 

	
 
# Test if the necessary binaries are available.
 
if ! type molecule > /dev/null 2>&1; then
 
    error "Could not locate binary: molecule. Please ensure you are running the script from within correctly set-up Python virtual environment."
 
    exit $ERROR_MISSING_BINARY
 
fi
 

	
 
# Assume success.
 
test_result=0
 

	
 
# Verify arguments.
 
if [[ $tests != "all" && $tests != "lint" ]]; then
 
@@ -202,25 +202,25 @@ if [[ $1 == "all" ]]; then
 

	
 
    # Traverse directory.
 
    for role_dir in roles/*; do
 
        if [[ -d $role_dir ]]; then
 
            debug "Located candiate role in directory $role_dir"
 
            roles+=("${role_dir#roles/}")
 
        else
 
            debug "Ignoring non-directory $role_dir"
 
        fi
 
    done
 
else
 
    while [[ -n $1 ]]; do
 
        roles+=($1)
 
        roles+=("$1")
 
        shift 1
 
    done
 
fi
 

	
 
if [[ ${#roles[@]} == 0 ]]; then
 
    error "No role has been specified for testing."
 
    exit $ERROR_ARGUMENTS
 
fi
 

	
 
# Determine which roles have available tests.
 
for role in "${roles[@]}"; do
 
    role_dir="roles/$role"
 
@@ -229,31 +229,31 @@ for role in "${roles[@]}"; do
 
        roles_to_skip+=("$role")
 
    elif [[ -f "$role_dir/molecule/default/molecule.yml" ]]; then
 
        debug "Role $role contains Molecule configuration."
 
         roles_to_test+=("$role")
 
    else
 
        warning "Role $role cannot be tested - missing Molecule configuration."
 
        roles_to_skip+=("$role")
 
    fi
 
done
 

	
 
# Output some helpful info, and ensure we can actually run tests against
 
# something.
 
info "Testing requested for roles: ${roles[@]}"
 
[[ ${#roles_to_skip[@]} != 0 ]] && info "The following roles will not be tested: ${roles_to_skip[@]}"
 
info "Testing requested for roles: ${roles[*]}"
 
[[ ${#roles_to_skip[@]} != 0 ]] && info "The following roles will not be tested: ${roles_to_skip[*]}"
 
if [[ ${#roles_to_test[@]} == 0 ]]; then
 
    error "No roles can be tested."
 
    exit $ERROR_NO_ROLES
 
fi
 
info "The following roles will be tested: ${roles_to_test[@]}"
 
info "The following roles will be tested: ${roles_to_test[*]}"
 

	
 
# Prepare directory for storing reports.
 
if [[ $report == 1 ]]; then
 
    report_directory="$(pwd)/test_report-$(date +%Y_%m_%d-%H_%M_%S)"
 
    report_summary="${report_directory}/summary.txt"
 
    if ! mkdir "$report_directory"; then
 
        error "Failed to create report directory $report_directory"
 
        exit $ERROR_REPORT
 
    fi
 
    touch "$report_summary"
 
    debug "Created report directory $report_directory."
 

	
0 comments (0 inline, 0 general)