Repository navigation
β¨ Add test-suite, add test workflow #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bedad51
β¨ Add test suite
ff5cb51
β
Add test for user::get_home
fcfffd7
π§ Conditionally add -ti flag based on TTY availability
5272128
π· Test functions, don't publish packages with failed tests
be144ca
β»οΈ Split into two workflows
5c394a1
βοΈ Fix typo
57b3664
π Fix typo
4caad61
π¬ Fix language issue
5cf90b5
π¬ Fix language issue
a156da2
β»οΈ Use camelCase for variables
9561066
π¬ Fix language issues
46d2047
π©Ή Ensure we are using seconds
b24d7f3
β»οΈ Simplify
d569ccd
βοΈ Fix typos
aba3d59
β»οΈ Simplify reading the code
6cb74b9
π Use the correct key/value, it is an object
4f41849
π¨ Remove trailing newline
7c3702a
π Capture and provide output when prep step fails
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| name: Test Functions | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| paths: | ||
| - 'libs/**' | ||
| workflow_call: | ||
| outputs: | ||
| packages: | ||
| description: All packages | ||
| value: ${{ jobs.setup.outputs.packages }} | ||
| functions: | ||
| description: All functions with tests | ||
| value: ${{ jobs.setup.outputs.functions }} | ||
| results: | ||
| description: Packages with some failed tests | ||
| value: ${{ jobs.test.outputs.results }} | ||
|
|
||
| jobs: | ||
| setup: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| packages: ${{ steps.packages.outputs.matrix }} | ||
| functions: ${{ steps.functions.outputs.matrix }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Get all packages | ||
| id: packages | ||
| shell: bash | ||
| run: | | ||
| json=$( | ||
| ( | ||
| for directory in $(find libs/ -mindepth 1 -maxdepth 1 -type d); do | ||
| echo -n '"'"${directory#*/}"'",' | ||
| done | ||
| echo '""' | ||
| ) | sed -E 's/,?""$//' | ||
| ) | ||
| echo "matrix={\"package\":[$json]}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Get all functions | ||
| id: functions | ||
| shell: bash | ||
| run: | | ||
| json=$( | ||
| ( | ||
| for directory in $(find libs/ -mindepth 1 -maxdepth 1 -type d); do | ||
| package="${directory#*/}" | ||
|
|
||
| for file in $(find "libs/$package" -type f -and \ | ||
| ! -name '\*' -and \ | ||
|
DanielRuthardt marked this conversation as resolved.
DanielRuthardt marked this conversation as resolved.
|
||
| ! -wholename '*/tests/*'); do | ||
| directory=$(dirname "$file") | ||
| fileName=$(basename "$file") | ||
| if [[ ! -d "$directory/tests/$fileName" || ! -f "$directory/tests/$fileName/test" ]]; then | ||
| continue | ||
| fi | ||
|
|
||
| functionName=${file#libs/*} | ||
| functionName=${functionName//\//::} | ||
|
|
||
| echo -n '{"package":"'"$package"'","function":"'"$functionName"'"},' | ||
| done | ||
| done | ||
| echo '""' | ||
| ) | sed -E 's/,?""$//' | ||
| ) | ||
|
|
||
| echo "matrix={\"function\":[$json]}" >> $GITHUB_OUTPUT | ||
|
|
||
| test: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| results: ${{ toJson(steps.test.outputs) }} | ||
| needs: [setup] | ||
| if: needs.setup.outputs.functions != '{"function":[]}' | ||
| strategy: | ||
| matrix: ${{ fromJson(needs.setup.outputs.functions) }} | ||
| fail-fast: false | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Test function | ||
| id: test | ||
| shell: bash | ||
| run: | | ||
| export PATH=".:$PATH" | ||
| export BASHP_INCLUDE_DIRS="libs" | ||
|
|
||
| set +e | ||
| output=$(bashpt "${{ matrix.function.function }}" 2>&1) | ||
| exitCode=$? | ||
| echo "$output" | ||
|
|
||
| if [[ $exitCcode -eq 0 ]]; then | ||
| echo "β Test passed for ${{ matrix.function.function }}" | ||
| elif [[ $exitCcode -eq 127 ]]; then | ||
| echo "π No test defined for ${{ matrix.function.function }} (acceptable)" | ||
| else | ||
| echo "β Test failed for ${{ matrix.function.function }} (exit code: $exitCcode)" | ||
| echo "${{ matrix.function.package }}=false" >> $GITHUB_OUTPUT | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Copyright 2025 The Linux Foundation | ||
| # | ||
| # Licensed 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. | ||
| # | ||
| set -eo pipefail | ||
|
|
||
| functionName=${1:?function to be tested must be set} | ||
| path=libs/${functionName//::/\/} | ||
| testPath=$(dirname "$path")/tests/${functionName##*::} | ||
| testFunction=${functionName%::*}::tests::${functionName##*::}::test | ||
|
|
||
| if [[ -d "$testPath" && -f "$testPath/test" ]]; then | ||
| test=$(bashpc <<<"set -euo pipefail; $testFunction") || { | ||
| echo "β Failed to prepare test script for '$testFunction'" >&2 | ||
| exit 2 | ||
| } | ||
|
|
||
| returnCode=0 | ||
| if [[ "${BASHPT_LOCAL:-false}" == "true" ]]; then | ||
| # Run tests locally | ||
| bash -c "$test" || returnCode=$? | ||
| else | ||
| # Run tests in Docker container | ||
| arguments=(--rm) | ||
|
|
||
| # Only add -ti if we have a TTY (not in CI) | ||
| if [ -t 0 ]; then | ||
|
DanielRuthardt marked this conversation as resolved.
|
||
| arguments+=(-ti) | ||
| fi | ||
|
|
||
| image="${BASHPT_IMAGE:-ubuntu:latest}" | ||
|
|
||
| # Add user override if specified | ||
| if [[ -n "${BASHPT_USER:-}" ]]; then | ||
| arguments+=(-u "$BASHPT_USER") | ||
| fi | ||
|
|
||
| docker run "${arguments[@]}" "$image" bash -c "$test" || returnCode=$? | ||
| fi | ||
|
|
||
| if [[ $returnCode -eq 0 ]]; then | ||
| echo "β All assertions passed: '$testFunction' passed" | ||
| exit 0 | ||
| else | ||
| echo "β Some assertions failed: '$testFunction' failed" >&2 | ||
| exit 1 | ||
| fi | ||
| else | ||
| echo "π« No test $testFunction defined for $functionName, skipping." | ||
| exit 127 | ||
|
DanielRuthardt marked this conversation as resolved.
|
||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.