From 2ad425b3e9e4bf02f926668f12285842b3dfffd4 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Tue, 29 Jul 2025 13:40:58 +0700 Subject: [PATCH 1/8] Init bashunit --- tests/bashunit/test_eq.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/bashunit/test_eq.sh diff --git a/tests/bashunit/test_eq.sh b/tests/bashunit/test_eq.sh new file mode 100644 index 0000000..917dc87 --- /dev/null +++ b/tests/bashunit/test_eq.sh @@ -0,0 +1,29 @@ +# @data_provider data_sucess +function test_success() { + bin/version eq $1 $2 2>&1 + local exit_code=$? + + assert_equals 0 $exit_code; +} + +# @data_provider data_failure +function test_failure() { + bin/version eq $1 $2 2>&1 + local exit_code=$? + + assert_equals 1 $exit_code; +} + +function data_failure() { + echo "1.0.0 1.0.1"; + echo "v2.0.0 v2.1.0"; + echo "3.5.2-alpha.1 3.5.2-alpha.2"; +} + +function data_sucess() { + echo "1.0.0 1.0.0"; + echo "v2.0.0 v2.0.0"; + echo "3.5.1-alpha.1 3.5.1-alpha.1"; + echo "4.0.0-beta.2+1 4.0.0-beta.2+2"; // Build metadata should not affect equality. + echo "4.2.0-beta.2+1 4.2.0-beta.2+1"; +} From 8474b54b69b46bca4047d8dae52a3a2aa06dc0b9 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:30:58 +0700 Subject: [PATCH 2/8] Update bashunit tests --- tests/bashunit/test_eq.sh | 28 ++++----- tests/bashunit/test_gt.sh | 28 +++++++++ tests/bashunit/test_increment.sh | 60 +++++++++++++++++++ tests/bashunit/test_lt.sh | 27 +++++++++ tests/bashunit/test_validate.sh | 32 ++++++++++ .../phpunit/Commands/ValidateCommandTest.php | 2 + 6 files changed, 163 insertions(+), 14 deletions(-) create mode 100644 tests/bashunit/test_gt.sh create mode 100644 tests/bashunit/test_increment.sh create mode 100644 tests/bashunit/test_lt.sh create mode 100644 tests/bashunit/test_validate.sh diff --git a/tests/bashunit/test_eq.sh b/tests/bashunit/test_eq.sh index 917dc87..569d6f6 100644 --- a/tests/bashunit/test_eq.sh +++ b/tests/bashunit/test_eq.sh @@ -1,29 +1,29 @@ -# @data_provider data_sucess -function test_success() { +# @data_provider data_equal +function test_equal() { bin/version eq $1 $2 2>&1 local exit_code=$? assert_equals 0 $exit_code; } -# @data_provider data_failure -function test_failure() { +# @data_provider data_not_equal +function test_not_equal() { bin/version eq $1 $2 2>&1 local exit_code=$? assert_equals 1 $exit_code; } -function data_failure() { - echo "1.0.0 1.0.1"; - echo "v2.0.0 v2.1.0"; - echo "3.5.2-alpha.1 3.5.2-alpha.2"; +function data_not_equal() { + echo "1.0.0" "1.0.1"; + echo "v2.0.0" "v2.1.0"; + echo "3.5.2-alpha.1" "3.5.2-alpha.2"; } -function data_sucess() { - echo "1.0.0 1.0.0"; - echo "v2.0.0 v2.0.0"; - echo "3.5.1-alpha.1 3.5.1-alpha.1"; - echo "4.0.0-beta.2+1 4.0.0-beta.2+2"; // Build metadata should not affect equality. - echo "4.2.0-beta.2+1 4.2.0-beta.2+1"; +function data_equal() { + echo "1.0.0" "1.0.0"; + echo "v2.0.0" "v2.0.0"; + echo "3.5.1-alpha.1" "3.5.1-alpha.1"; + echo "4.0.0-beta.2+1" "4.0.0-beta.2+2"; # Build metadata should not affect equality. + echo "4.2.0-beta.2+1" "4.2.0-beta.2+1"; } diff --git a/tests/bashunit/test_gt.sh b/tests/bashunit/test_gt.sh new file mode 100644 index 0000000..5b7a7a5 --- /dev/null +++ b/tests/bashunit/test_gt.sh @@ -0,0 +1,28 @@ +# @data_provider data_greater_than +function test_greater_than() { + bin/version gt $1 $2 2>&1 + local exit_code=$? + + assert_equals 0 $exit_code; +} + +# @data_provider data_not_greater_than +function test_not_greater_than() { + bin/version gt $1 $2 2>&1 + local exit_code=$? + + assert_equals 1 $exit_code; +} + +function data_not_greater_than() { + echo "1.0.0" "1.0.0"; # Equal. + echo "v2.0.0" "v2.1.0"; # Less than. + echo "3.5.2-alpha.1" "3.5.2-alpha.2"; # Less than with pre-release. + echo "3.5.2-alpha.2+2" "3.5.2-alpha.2+1"; +} + +function data_greater_than() { + echo "1.0.1" "1.0.0"; # Greater than. + echo "v2.1.0" "v2.0.0"; # Greater than with prefix. + echo "3.5.2-alpha.2" "3.5.2-alpha.1"; # Greater than with pre-release. +} diff --git a/tests/bashunit/test_increment.sh b/tests/bashunit/test_increment.sh new file mode 100644 index 0000000..e527c7c --- /dev/null +++ b/tests/bashunit/test_increment.sh @@ -0,0 +1,60 @@ +# @data_provider data_increment_patch +function test_increment_patch() { + ver=$(bin/version increment $1); + assert_equals $ver $2; +} + +# @data_provider data_increment_minor +function test_increment_minor() { + ver=$(bin/version increment $1 --part minor); + assert_equals $ver $2; +} + +# @data_provider data_increment_major +function test_increment_major() { + ver=$(bin/version increment $1 --part major); + assert_equals $ver $2; +} + +# @data_provider data_increment_with_pre_release +function test_increment_with_pre_release() { + ver=$(bin/version increment $1 --pre alpha); + assert_equals $ver $2; +} + +# @data_provider data_increment_with_build +function test_increment_with_build() { + ver=$(bin/version increment $1 --build 123); + assert_equals $ver $2; +} + +# @data_provider data_increment_with_pre_release_and_build +function test_increment_with_pre_release_and_build() { + ver=$(bin/version increment $1 --build 123 --pre alpha); + assert_equals $ver $2; +} + +function data_increment_patch() { + echo "0.0.0" "0.0.1"; + echo "1.0.0" "1.0.1"; +} + +function data_increment_minor() { + echo "0.0.0" "0.1.0"; + echo "1.0.0" "1.1.0"; +} + +function data_increment_major() { + echo "0.0.0" "1.0.0"; + echo "1.0.0" "2.0.0"; +} + +function data_increment_with_pre_release() { + echo "0.0.0" "0.0.1-alpha"; + echo "1.0.0" "1.0.1-alpha"; +} + +function data_increment_with_pre_release_and_build() { + echo "0.0.0" "0.0.1-alpha+123"; + echo "1.0.0" "1.0.1-alpha+123"; +} diff --git a/tests/bashunit/test_lt.sh b/tests/bashunit/test_lt.sh new file mode 100644 index 0000000..ba4e83b --- /dev/null +++ b/tests/bashunit/test_lt.sh @@ -0,0 +1,27 @@ +# @data_provider data_less_than +function test_less_than() { + bin/version lt $1 $2 2>&1 + local exit_code=$? + + assert_equals 0 $exit_code; +} + +# @data_provider data_not_less_than +function test_not_less_than() { + bin/version lt $1 $2 2>&1 + local exit_code=$? + + assert_equals 1 $exit_code; +} + +function data_less_than() { + echo "1.0.0" "1.0.1"; + echo "v2.0.0" "v2.1.0"; + echo "3.5.2-alpha.1" "3.5.2-alpha.2"; +} + +function data_not_less_than() { + echo "1.0.0" "1.0.0"; # Equal. + echo "v2.0.0" "v1.0.0"; # Greater than. + echo "3.5.1-alpha.2" "3.5.1-alpha.1"; # Greater than with pre-release. +} diff --git a/tests/bashunit/test_validate.sh b/tests/bashunit/test_validate.sh new file mode 100644 index 0000000..63097a8 --- /dev/null +++ b/tests/bashunit/test_validate.sh @@ -0,0 +1,32 @@ +# @data_provider data_valid +function test_equal() { + bin/version validate $1 2>&1 + local exit_code=$? + + assert_equals 0 $exit_code; +} + +# @data_provider data_invalid +function test_invalid() { + bin/version validate $1 2>&1 + local exit_code=$? + + assert_equals 1 $exit_code; +} + +function data_valid() { + echo "1.0.0" + echo "v1.0.0" + echo "2.1.7-alpha" + echo "1.0.0-beta.1" + echo "3.4.5+build.78" + echo "0.9.1-alpha.1+exp.sha.5114f85" +} + +function data_invalid() { + echo "0" + echo "0.0" + echo "v" + echo "v0" + echo "v0.0" +} diff --git a/tests/phpunit/Commands/ValidateCommandTest.php b/tests/phpunit/Commands/ValidateCommandTest.php index 823782d..18d0e01 100644 --- a/tests/phpunit/Commands/ValidateCommandTest.php +++ b/tests/phpunit/Commands/ValidateCommandTest.php @@ -47,6 +47,8 @@ public function testValidVersionArgument(string $version): void public static function dataInvalidVersionArgument(): iterable { + yield ['0']; + yield ['0.0']; yield ['v']; yield ['v0']; yield ['v0.0']; From a38319ede25ce32aaba374da3203f54c8500b222 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:34:36 +0700 Subject: [PATCH 3/8] Rename to `lint` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5984915..1a984f4 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "scripts": { "analyze": "phpstan", "format": "phpcbf", - "sniff": "phpcs", + "lint": "phpcs", "test": "phpunit" }, "config": { From 1d6261326356cf9eb49d39ba1dad1165ccb4f6c9 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:34:50 +0700 Subject: [PATCH 4/8] Add Github Action for running `bashunit` --- .github/workflows/ci.yml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3b59ea..2145f16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,10 +58,10 @@ jobs: - name: Analyze source code run: composer analyze - test: + test-phpunit: needs: [sniff, analyze] runs-on: ubuntu-latest - name: Test + name: Test (phpunit) strategy: fail-fast: true @@ -85,3 +85,21 @@ jobs: - name: Run test run: composer test + + test-bashunit: + needs: [test-phpunit] + runs-on: ubuntu-latest + name: Test (bashunit) + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install bashunit + run: | + curl -s https://bashunit.typeddevs.com/install.sh > install.sh + chmod +x install.sh + ./install.sh + + - name: Run test + run: ./lib/bashunit ./tests/bashunit/*.sh From 1519744bf5d418528a58b6ef7a830bbcb3cd2985 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:37:25 +0700 Subject: [PATCH 5/8] Rename to `lint` --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2145f16..c73fd5e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,9 +20,9 @@ concurrency: cancel-in-progress: true jobs: - sniff: + lint: runs-on: ubuntu-latest - name: Sniff + name: lint steps: - name: Checkout code @@ -37,7 +37,7 @@ jobs: uses: ramsey/composer-install@v3 - name: Analyze source code - run: composer sniff + run: composer lint analyze: runs-on: ubuntu-latest @@ -59,7 +59,7 @@ jobs: run: composer analyze test-phpunit: - needs: [sniff, analyze] + needs: [lint, analyze] runs-on: ubuntu-latest name: Test (phpunit) From 11118d41b494eae4e16a9ee32eb674ec6a3e11c0 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:38:19 +0700 Subject: [PATCH 6/8] Update job name to use title case --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c73fd5e..8cd53ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ concurrency: jobs: lint: runs-on: ubuntu-latest - name: lint + name: Lint steps: - name: Checkout code From 339cd7cd8833ab2df54dde6411dba53b9fb05f66 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Tue, 29 Jul 2025 15:03:11 +0700 Subject: [PATCH 7/8] Update test workflows --- .github/workflows/ci.yml | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cd53ac..973442d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,10 +58,10 @@ jobs: - name: Analyze source code run: composer analyze - test-phpunit: + test: needs: [lint, analyze] runs-on: ubuntu-latest - name: Test (phpunit) + name: Test strategy: fail-fast: true @@ -83,23 +83,15 @@ jobs: - name: Install PHP dependencies uses: ramsey/composer-install@v3 - - name: Run test - run: composer test - - test-bashunit: - needs: [test-phpunit] - runs-on: ubuntu-latest - name: Test (bashunit) - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Install bashunit run: | curl -s https://bashunit.typeddevs.com/install.sh > install.sh chmod +x install.sh ./install.sh - - name: Run test + - name: Run PHPUnit test + run: composer test + + - name: Run bashunit tests + if: matrix.machine != 'windows-latest' run: ./lib/bashunit ./tests/bashunit/*.sh From c553d19d1f85760563cf12a9ca6ff6596777aa16 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Tue, 29 Jul 2025 15:04:39 +0700 Subject: [PATCH 8/8] Update test workflows --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 973442d..6fb06d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,6 +92,6 @@ jobs: - name: Run PHPUnit test run: composer test - - name: Run bashunit tests + - name: Run bashunit test if: matrix.machine != 'windows-latest' run: ./lib/bashunit ./tests/bashunit/*.sh