Skip to content

fix: change increment syntax in test library script - #896

Merged
Samruddhi Khandale (samruddhikhandale) merged 1 commit into
devcontainers:mainfrom
koralowiec:fix/test-library-script-increment
Sep 16, 2024
Merged

Samruddhi Khandale (samruddhikhandale) merged 1 commit into
devcontainers:mainfrom
koralowiec:fix/test-library-script-increment

Conversation

@koralowiec

Copy link
Copy Markdown
Contributor

Function checkMultiple which is available in dev-container-features-test-lib (test library script) doesn't work as intended

It exits while looping through the 1st command. For example, execution of this script:

#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

checkMultiple "Test multiple" 2 "echo First" "echo Second"

Results in error:
Pasted image 20240915161640

It seems that it's caused by the way how the PASSED variable is incremented: ((PASSED++)) - The value is returned first, then PASSED is incremented

For the first iteration the value of the expression is 0, so the return status is set to 1

(( expression ))
If the value of the expression is non-zero, the return status is 0; otherwise the return status is 1.
https://www.gnu.org/software/bash/manual/bash.html#Conditional-Constructs

I changed it to ((PASSED+=1)), and tested locally. It fixes the issue:

image

@koralowiec
Arek Kalandyk (koralowiec) requested a review from a team as a code owner September 15, 2024 14:59

@chrmarti Christof Marti (chrmarti) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@samruddhikhandale
Samruddhi Khandale (samruddhikhandale) merged commit 9ba1fda into devcontainers:main Sep 16, 2024
@koralowiec
Arek Kalandyk (koralowiec) deleted the fix/test-library-script-increment branch September 16, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants