diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3b59ea..6fb06d8 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: - needs: [sniff, analyze] + needs: [lint, analyze] runs-on: ubuntu-latest name: Test @@ -83,5 +83,15 @@ jobs: - name: Install PHP dependencies uses: ramsey/composer-install@v3 - - name: Run test + - name: Install bashunit + run: | + curl -s https://bashunit.typeddevs.com/install.sh > install.sh + chmod +x install.sh + ./install.sh + + - name: Run PHPUnit test run: composer test + + - name: Run bashunit test + if: matrix.machine != 'windows-latest' + run: ./lib/bashunit ./tests/bashunit/*.sh 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": { diff --git a/tests/bashunit/test_eq.sh b/tests/bashunit/test_eq.sh new file mode 100644 index 0000000..569d6f6 --- /dev/null +++ b/tests/bashunit/test_eq.sh @@ -0,0 +1,29 @@ +# @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_not_equal +function test_not_equal() { + bin/version eq $1 $2 2>&1 + local exit_code=$? + + assert_equals 1 $exit_code; +} + +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_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'];