From a6f0100987c3588d97aa6013470d0b230b4cccdc Mon Sep 17 00:00:00 2001 From: anushkamittal20 Date: Mon, 25 Nov 2024 12:53:40 +0000 Subject: [PATCH 01/11] Modification in bats.yaml Signed-off-by: anushkamittal20 --- bats.yaml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/bats.yaml b/bats.yaml index 2aff175ab1f..fd428edb6a7 100644 --- a/bats.yaml +++ b/bats.yaml @@ -1,7 +1,7 @@ package: name: bats version: 1.11.0 - epoch: 1 + epoch: 0 description: Bash Automated Testing System copyright: - license: MIT @@ -15,6 +15,7 @@ package: environment: contents: packages: + - wget - bash - build-base - busybox @@ -28,14 +29,34 @@ pipeline: expected-commit: 5da66876b8b619235aee1eb3e54954eaca88059b - runs: | - ./install.sh "${{targets.contextdir}}/usr" + ./install.sh "${{targets.contextdir}}/usr" + mkdir -p "${{targets.contextdir}}/tmp/" + mv ./docker "${{targets.contextdir}}/tmp/docker" + ls -la "${{targets.contextdir}}/tmp/docker/" + "${{targets.contextdir}}/tmp/docker/install_libs.sh" support 0.3.0 + "${{targets.contextdir}}/tmp/docker/install_libs.sh" file 0.4.0 + "${{targets.contextdir}}/tmp/docker/install_libs.sh" assert 2.1.0 + "${{targets.contextdir}}/tmp/docker/install_libs.sh" detik 1.3.1 + mkdir -p "${{targets.contextdir}}/usr/local/bin" + ln -s /opt/bats/bin/bats "${{targets.contextdir}}/usr/local/bin/bats" + find "${{targets.contextdir}}" -type f -perm /2000 -exec chmod g-s {} \; + rm -rf "${{targets.contextdir}}/tmp/" subpackages: + - name: bats-compat + pipeline: + - runs: | + mkdir -p "${{targets.contextdir}}/opt/bats/" + find . -maxdepth 1 -not -name '.' -not -name 'melange-out' -not -name '*.tmp' -not -name '*.log' \ + -exec mv {} "${{targets.contextdir}}/opt/bats/" \; + description: bats compatibility package + - name: bats-doc pipeline: - uses: split/manpages description: bats manpages + update: enabled: true github: From 234c90c920ca89e8d96c3fef9265913f9145599e Mon Sep 17 00:00:00 2001 From: anushkamittal20 Date: Mon, 25 Nov 2024 15:10:53 +0000 Subject: [PATCH 02/11] Run yam Signed-off-by: anushkamittal20 --- bats.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bats.yaml b/bats.yaml index fd428edb6a7..e4f87ba497f 100644 --- a/bats.yaml +++ b/bats.yaml @@ -15,11 +15,11 @@ package: environment: contents: packages: - - wget - bash - build-base - busybox - ca-certificates-bundle + - wget pipeline: - uses: git-checkout @@ -56,7 +56,6 @@ subpackages: - uses: split/manpages description: bats manpages - update: enabled: true github: From 1b6f2171f8f65d87fe3a8ddc0bc36b5dd6d7e972 Mon Sep 17 00:00:00 2001 From: anushkamittal20 Date: Tue, 26 Nov 2024 03:12:45 +0000 Subject: [PATCH 03/11] Correct epoch Signed-off-by: anushkamittal20 --- bats.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bats.yaml b/bats.yaml index e4f87ba497f..862dd9641cc 100644 --- a/bats.yaml +++ b/bats.yaml @@ -1,7 +1,7 @@ package: name: bats version: 1.11.0 - epoch: 0 + epoch: 2 description: Bash Automated Testing System copyright: - license: MIT From 59aa98fe613964c3f890157cd90fda03d1168dec Mon Sep 17 00:00:00 2001 From: anushkamittal20 Date: Tue, 26 Nov 2024 08:33:56 +0000 Subject: [PATCH 04/11] Cleanup Signed-off-by: anushkamittal20 --- bats.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/bats.yaml b/bats.yaml index 862dd9641cc..1440d77ab19 100644 --- a/bats.yaml +++ b/bats.yaml @@ -32,7 +32,6 @@ pipeline: ./install.sh "${{targets.contextdir}}/usr" mkdir -p "${{targets.contextdir}}/tmp/" mv ./docker "${{targets.contextdir}}/tmp/docker" - ls -la "${{targets.contextdir}}/tmp/docker/" "${{targets.contextdir}}/tmp/docker/install_libs.sh" support 0.3.0 "${{targets.contextdir}}/tmp/docker/install_libs.sh" file 0.4.0 "${{targets.contextdir}}/tmp/docker/install_libs.sh" assert 2.1.0 From 9da964a66ff4b06c7b3130fbad98b3d5f21faa87 Mon Sep 17 00:00:00 2001 From: anushkamittal20 Date: Tue, 26 Nov 2024 12:53:53 +0000 Subject: [PATCH 05/11] use cp instead of mv Signed-off-by: anushkamittal20 --- bats.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bats.yaml b/bats.yaml index 1440d77ab19..de75f85c012 100644 --- a/bats.yaml +++ b/bats.yaml @@ -31,7 +31,7 @@ pipeline: - runs: | ./install.sh "${{targets.contextdir}}/usr" mkdir -p "${{targets.contextdir}}/tmp/" - mv ./docker "${{targets.contextdir}}/tmp/docker" + cp -r ./docker "${{targets.contextdir}}/tmp/docker" "${{targets.contextdir}}/tmp/docker/install_libs.sh" support 0.3.0 "${{targets.contextdir}}/tmp/docker/install_libs.sh" file 0.4.0 "${{targets.contextdir}}/tmp/docker/install_libs.sh" assert 2.1.0 From a5c1237eb9506870eea702eaf200b3d289e37b4f Mon Sep 17 00:00:00 2001 From: anushkamittal20 Date: Tue, 26 Nov 2024 17:49:00 +0000 Subject: [PATCH 06/11] reduce pkgs Signed-off-by: anushkamittal20 --- bats.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/bats.yaml b/bats.yaml index de75f85c012..5c073b0c8cf 100644 --- a/bats.yaml +++ b/bats.yaml @@ -16,9 +16,6 @@ environment: contents: packages: - bash - - build-base - - busybox - - ca-certificates-bundle - wget pipeline: From a5490c1ebdbb465a77631bd80504afa0598ad9ba Mon Sep 17 00:00:00 2001 From: anushkamittal20 Date: Wed, 27 Nov 2024 13:36:07 +0000 Subject: [PATCH 07/11] replace coreutils Signed-off-by: anushkamittal20 --- bats.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bats.yaml b/bats.yaml index 5c073b0c8cf..54223d3bda4 100644 --- a/bats.yaml +++ b/bats.yaml @@ -8,7 +8,7 @@ package: dependencies: runtime: - bash - - coreutils + - busybox - ncurses - parallel From be1ac6f267cf432761b8e6056295ca1308d4ebfa Mon Sep 17 00:00:00 2001 From: anushkamittal20 Date: Thu, 28 Nov 2024 05:38:27 +0000 Subject: [PATCH 08/11] Add tests Signed-off-by: anushkamittal20 --- bats.yaml | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/bats.yaml b/bats.yaml index 54223d3bda4..902087468d0 100644 --- a/bats.yaml +++ b/bats.yaml @@ -60,6 +60,82 @@ update: test: pipeline: - # AUTOGENERATED - runs: | bats --version + + echo 'add_numbers() {' > /tmp/example.sh + echo ' echo $(( $1 + $2 ))' >> /tmp/example.sh + echo '}' >> /tmp/example.sh + echo '' >> /tmp/example.sh + echo 'file_exists() {' >> /tmp/example.sh + echo ' if [[ -f "$1" ]]; then' >> /tmp/example.sh + echo ' echo "true"' >> /tmp/example.sh + echo ' else' >> /tmp/example.sh + echo ' echo "false"' >> /tmp/example.sh + echo ' fi' >> /tmp/example.sh + echo '}' >> /tmp/example.sh + echo '' >> /tmp/example.sh + echo 'string_contains() {' >> /tmp/example.sh + echo ' if [[ "$1" == *"$2"* ]]; then' >> /tmp/example.sh + echo ' echo "true"' >> /tmp/example.sh + echo ' else' >> /tmp/example.sh + echo ' echo "false"' >> /tmp/example.sh + echo ' fi' >> /tmp/example.sh + echo '}' >> /tmp/example.sh + + # Write the bats test script + echo '#!/usr/bin/env bats' > /tmp/inline_test.bats + echo '' >> /tmp/inline_test.bats + echo 'load_file() {' >> /tmp/inline_test.bats + echo ' source "/tmp/example.sh"' >> /tmp/inline_test.bats + echo '}' >> /tmp/inline_test.bats + echo '' >> /tmp/inline_test.bats + echo 'setup() {' >> /tmp/inline_test.bats + echo ' load_file' >> /tmp/inline_test.bats + echo '}' >> /tmp/inline_test.bats + echo '' >> /tmp/inline_test.bats + echo 'teardown() {' >> /tmp/inline_test.bats + echo ' rm -f testfile.txt' >> /tmp/inline_test.bats + echo '}' >> /tmp/inline_test.bats + echo '' >> /tmp/inline_test.bats + echo '@test "add_numbers should correctly add two numbers" {' >> /tmp/inline_test.bats + echo ' run add_numbers 3 5' >> /tmp/inline_test.bats + echo ' [ "$status" -eq 0 ]' >> /tmp/inline_test.bats + echo ' [ "$output" -eq 8 ]' >> /tmp/inline_test.bats + echo '}' >> /tmp/inline_test.bats + echo '' >> /tmp/inline_test.bats + echo '@test "file_exists should return true for existing file" {' >> /tmp/inline_test.bats + echo ' touch testfile.txt' >> /tmp/inline_test.bats + echo ' run file_exists testfile.txt' >> /tmp/inline_test.bats + echo ' [ "$status" -eq 0 ]' >> /tmp/inline_test.bats + echo ' [ "$output" = "true" ]' >> /tmp/inline_test.bats + echo '}' >> /tmp/inline_test.bats + echo '' >> /tmp/inline_test.bats + echo '@test "file_exists should return false for non-existing file" {' >> /tmp/inline_test.bats + echo ' run file_exists non_existing_file.txt' >> /tmp/inline_test.bats + echo ' [ "$status" -eq 0 ]' >> /tmp/inline_test.bats + echo ' [ "$output" = "false" ]' >> /tmp/inline_test.bats + echo '}' >> /tmp/inline_test.bats + echo '' >> /tmp/inline_test.bats + echo '@test "string_contains should return true if substring is found" {' >> /tmp/inline_test.bats + echo ' run string_contains "hello world" "hello"' >> /tmp/inline_test.bats + echo ' [ "$status" -eq 0 ]' >> /tmp/inline_test.bats + echo ' [ "$output" = "true" ]' >> /tmp/inline_test.bats + echo '}' >> /tmp/inline_test.bats + echo '' >> /tmp/inline_test.bats + echo '@test "string_contains should return false if substring is not found" {' >> /tmp/inline_test.bats + echo ' run string_contains "hello world" "bye"' >> /tmp/inline_test.bats + echo ' [ "$status" -eq 0 ]' >> /tmp/inline_test.bats + echo ' [ "$output" = "false" ]' >> /tmp/inline_test.bats + echo '}' >> /tmp/inline_test.bats + + # Make the scripts executable + chmod +x /tmp/example.sh + chmod +x /tmp/inline_test.bats + + # Run the bats tests + bats /tmp/inline_test.bats + + # Clean up + rm -f /tmp/example.sh + rm -f /tmp/inline_test.bats From fd54340310f6c89381e2a0e15885bac8e9b506c6 Mon Sep 17 00:00:00 2001 From: anushkamittal20 Date: Thu, 28 Nov 2024 12:19:17 +0000 Subject: [PATCH 09/11] shift ln to compat Signed-off-by: anushkamittal20 --- bats.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bats.yaml b/bats.yaml index 902087468d0..c881373c8ac 100644 --- a/bats.yaml +++ b/bats.yaml @@ -33,8 +33,6 @@ pipeline: "${{targets.contextdir}}/tmp/docker/install_libs.sh" file 0.4.0 "${{targets.contextdir}}/tmp/docker/install_libs.sh" assert 2.1.0 "${{targets.contextdir}}/tmp/docker/install_libs.sh" detik 1.3.1 - mkdir -p "${{targets.contextdir}}/usr/local/bin" - ln -s /opt/bats/bin/bats "${{targets.contextdir}}/usr/local/bin/bats" find "${{targets.contextdir}}" -type f -perm /2000 -exec chmod g-s {} \; rm -rf "${{targets.contextdir}}/tmp/" @@ -45,6 +43,8 @@ subpackages: mkdir -p "${{targets.contextdir}}/opt/bats/" find . -maxdepth 1 -not -name '.' -not -name 'melange-out' -not -name '*.tmp' -not -name '*.log' \ -exec mv {} "${{targets.contextdir}}/opt/bats/" \; + mkdir -p "${{targets.contextdir}}/usr/local/bin" + ln -s /opt/bats/bin/bats "${{targets.contextdir}}/usr/local/bin/bats" description: bats compatibility package - name: bats-doc From 56346e6067df6298d54f17656316936838503ffd Mon Sep 17 00:00:00 2001 From: anushkamittal20 Date: Thu, 28 Nov 2024 14:04:39 +0000 Subject: [PATCH 10/11] Refactor Signed-off-by: anushkamittal20 --- bats.yaml | 143 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 75 insertions(+), 68 deletions(-) diff --git a/bats.yaml b/bats.yaml index c881373c8ac..6709b7a8747 100644 --- a/bats.yaml +++ b/bats.yaml @@ -1,7 +1,7 @@ package: name: bats version: 1.11.0 - epoch: 2 + epoch: 4 description: Bash Automated Testing System copyright: - license: MIT @@ -41,7 +41,9 @@ subpackages: pipeline: - runs: | mkdir -p "${{targets.contextdir}}/opt/bats/" - find . -maxdepth 1 -not -name '.' -not -name 'melange-out' -not -name '*.tmp' -not -name '*.log' \ + find . -maxdepth 1 \ + -not -name '.*' \ + -not -name 'melange-out' \ -exec mv {} "${{targets.contextdir}}/opt/bats/" \; mkdir -p "${{targets.contextdir}}/usr/local/bin" ln -s /opt/bats/bin/bats "${{targets.contextdir}}/usr/local/bin/bats" @@ -63,71 +65,76 @@ test: - runs: | bats --version - echo 'add_numbers() {' > /tmp/example.sh - echo ' echo $(( $1 + $2 ))' >> /tmp/example.sh - echo '}' >> /tmp/example.sh - echo '' >> /tmp/example.sh - echo 'file_exists() {' >> /tmp/example.sh - echo ' if [[ -f "$1" ]]; then' >> /tmp/example.sh - echo ' echo "true"' >> /tmp/example.sh - echo ' else' >> /tmp/example.sh - echo ' echo "false"' >> /tmp/example.sh - echo ' fi' >> /tmp/example.sh - echo '}' >> /tmp/example.sh - echo '' >> /tmp/example.sh - echo 'string_contains() {' >> /tmp/example.sh - echo ' if [[ "$1" == *"$2"* ]]; then' >> /tmp/example.sh - echo ' echo "true"' >> /tmp/example.sh - echo ' else' >> /tmp/example.sh - echo ' echo "false"' >> /tmp/example.sh - echo ' fi' >> /tmp/example.sh - echo '}' >> /tmp/example.sh - - # Write the bats test script - echo '#!/usr/bin/env bats' > /tmp/inline_test.bats - echo '' >> /tmp/inline_test.bats - echo 'load_file() {' >> /tmp/inline_test.bats - echo ' source "/tmp/example.sh"' >> /tmp/inline_test.bats - echo '}' >> /tmp/inline_test.bats - echo '' >> /tmp/inline_test.bats - echo 'setup() {' >> /tmp/inline_test.bats - echo ' load_file' >> /tmp/inline_test.bats - echo '}' >> /tmp/inline_test.bats - echo '' >> /tmp/inline_test.bats - echo 'teardown() {' >> /tmp/inline_test.bats - echo ' rm -f testfile.txt' >> /tmp/inline_test.bats - echo '}' >> /tmp/inline_test.bats - echo '' >> /tmp/inline_test.bats - echo '@test "add_numbers should correctly add two numbers" {' >> /tmp/inline_test.bats - echo ' run add_numbers 3 5' >> /tmp/inline_test.bats - echo ' [ "$status" -eq 0 ]' >> /tmp/inline_test.bats - echo ' [ "$output" -eq 8 ]' >> /tmp/inline_test.bats - echo '}' >> /tmp/inline_test.bats - echo '' >> /tmp/inline_test.bats - echo '@test "file_exists should return true for existing file" {' >> /tmp/inline_test.bats - echo ' touch testfile.txt' >> /tmp/inline_test.bats - echo ' run file_exists testfile.txt' >> /tmp/inline_test.bats - echo ' [ "$status" -eq 0 ]' >> /tmp/inline_test.bats - echo ' [ "$output" = "true" ]' >> /tmp/inline_test.bats - echo '}' >> /tmp/inline_test.bats - echo '' >> /tmp/inline_test.bats - echo '@test "file_exists should return false for non-existing file" {' >> /tmp/inline_test.bats - echo ' run file_exists non_existing_file.txt' >> /tmp/inline_test.bats - echo ' [ "$status" -eq 0 ]' >> /tmp/inline_test.bats - echo ' [ "$output" = "false" ]' >> /tmp/inline_test.bats - echo '}' >> /tmp/inline_test.bats - echo '' >> /tmp/inline_test.bats - echo '@test "string_contains should return true if substring is found" {' >> /tmp/inline_test.bats - echo ' run string_contains "hello world" "hello"' >> /tmp/inline_test.bats - echo ' [ "$status" -eq 0 ]' >> /tmp/inline_test.bats - echo ' [ "$output" = "true" ]' >> /tmp/inline_test.bats - echo '}' >> /tmp/inline_test.bats - echo '' >> /tmp/inline_test.bats - echo '@test "string_contains should return false if substring is not found" {' >> /tmp/inline_test.bats - echo ' run string_contains "hello world" "bye"' >> /tmp/inline_test.bats - echo ' [ "$status" -eq 0 ]' >> /tmp/inline_test.bats - echo ' [ "$output" = "false" ]' >> /tmp/inline_test.bats - echo '}' >> /tmp/inline_test.bats + # Create the example.sh script using heredocs + cat << 'EOF' > /tmp/example.sh + add_numbers() { + echo $(( $1 + $2 )) + } + + file_exists() { + if [[ -f "$1" ]]; then + echo "true" + else + echo "false" + fi + } + + string_contains() { + if [[ "$1" == *"$2"* ]]; then + echo "true" + else + echo "false" + fi + } + EOF + + # Create the inline_test.bats script using heredocs + cat << 'EOF' > /tmp/inline_test.bats + #!/usr/bin/env bats + + load_file() { + source "/tmp/example.sh" + } + + setup() { + load_file + } + + teardown() { + rm -f testfile.txt + } + + @test "add_numbers should correctly add two numbers" { + run add_numbers 3 5 + [ "$status" -eq 0 ] + [ "$output" -eq 8 ] + } + + @test "file_exists should return true for existing file" { + touch testfile.txt + run file_exists testfile.txt + [ "$status" -eq 0 ] + [ "$output" = "true" ] + } + + @test "file_exists should return false for non-existing file" { + run file_exists non_existing_file.txt + [ "$status" -eq 0 ] + [ "$output" = "false" ] + } + + @test "string_contains should return true if substring is found" { + run string_contains "hello world" "hello" + [ "$status" -eq 0 ] + [ "$output" = "true" ] + } + + @test "string_contains should return false if substring is not found" { + run string_contains "hello world" "bye" + [ "$status" -eq 0 ] + [ "$output" = "false" ] + } + EOF # Make the scripts executable chmod +x /tmp/example.sh @@ -138,4 +145,4 @@ test: # Clean up rm -f /tmp/example.sh - rm -f /tmp/inline_test.bats + rm -f /tmp/inline_test.bats \ No newline at end of file From 067e197176c807d7cbd5f7574a7c1ab0f788fe43 Mon Sep 17 00:00:00 2001 From: Anushka Mittal <55237170+anushkamittal20@users.noreply.github.com> Date: Thu, 28 Nov 2024 19:51:29 +0530 Subject: [PATCH 11/11] Reset epoch Signed-off-by: Anushka Mittal <55237170+anushkamittal20@users.noreply.github.com> --- bats.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bats.yaml b/bats.yaml index 6709b7a8747..4651daee363 100644 --- a/bats.yaml +++ b/bats.yaml @@ -1,7 +1,7 @@ package: name: bats version: 1.11.0 - epoch: 4 + epoch: 2 description: Bash Automated Testing System copyright: - license: MIT @@ -145,4 +145,4 @@ test: # Clean up rm -f /tmp/example.sh - rm -f /tmp/inline_test.bats \ No newline at end of file + rm -f /tmp/inline_test.bats