Skip to content

More multiline issues: arrays and chained expressions #37

Closed
@joaoe

Description

@joaoe

This snippet should have 100% coverage

#!/usr/bin/env bash

function this_command_runs {
	true
}

function main {
	
	# awk script -> it just a long string passed to the awk.
	# Both the command and arguments should could as covered.

	awk -F, 'NR==1{
	print("Some long script")
}
NR > 1 {
	print("And script continues")
}' /dev/null


	# multiline array specification

	local some_array=( "Some" "values" "${and[@]}"
		"${many}" other $(echo 123)
	)

	local some_array=(
		"Some" "values" "${and[@]}"
		"${many}" other $(echo 123)
	)

	declare -A some_hashmap=(
		[A]="aaa"
		[B]="bbb"
		[C]="..."
	)

	##### multiline with && and ||

	true line 1 \
		line 2 \
		line 3

	true line 1 \
		"$(true && echo line 2)" \
		line 3

	true line 1 \
		"$(false || echo line 2)" \
		line 3

	##### multiline with redirect and boolean operator

	false line 1 \
		line 2 2> >(cat) || this_command_runs

	false line 1 \
		line 2 2> >(cat) || \
		this_command_runs

	true line 1 \
		line 2 2> >(cat) && this_command_runs

	true line 1 \
		line 2 2> >(cat) && \
		this_command_runs

	##### A for loop in multiple lines
	
	for ((k = 1;
	k <= 2;
	k++));
	do
		true
	done

	echo "This test case should have 100% line coverage"

	exit 0
}

main "$@"

Instead I'm getting 60%.

Using bashcov 1.8.2.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions