Skip to content

Commit e815400

Browse files
authored
Add Bashunit (#6)
1 parent 533b1bc commit e815400

8 files changed

Lines changed: 194 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ concurrency:
2020
cancel-in-progress: true
2121

2222
jobs:
23-
sniff:
23+
lint:
2424
runs-on: ubuntu-latest
25-
name: Sniff
25+
name: Lint
2626

2727
steps:
2828
- name: Checkout code
@@ -37,7 +37,7 @@ jobs:
3737
uses: ramsey/composer-install@v3
3838

3939
- name: Analyze source code
40-
run: composer sniff
40+
run: composer lint
4141

4242
analyze:
4343
runs-on: ubuntu-latest
@@ -59,7 +59,7 @@ jobs:
5959
run: composer analyze
6060

6161
test:
62-
needs: [sniff, analyze]
62+
needs: [lint, analyze]
6363
runs-on: ubuntu-latest
6464
name: Test
6565

@@ -83,5 +83,15 @@ jobs:
8383
- name: Install PHP dependencies
8484
uses: ramsey/composer-install@v3
8585

86-
- name: Run test
86+
- name: Install bashunit
87+
run: |
88+
curl -s https://bashunit.typeddevs.com/install.sh > install.sh
89+
chmod +x install.sh
90+
./install.sh
91+
92+
- name: Run PHPUnit test
8793
run: composer test
94+
95+
- name: Run bashunit test
96+
if: matrix.machine != 'windows-latest'
97+
run: ./lib/bashunit ./tests/bashunit/*.sh

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"scripts": {
5858
"analyze": "phpstan",
5959
"format": "phpcbf",
60-
"sniff": "phpcs",
60+
"lint": "phpcs",
6161
"test": "phpunit"
6262
},
6363
"config": {

tests/bashunit/test_eq.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# @data_provider data_equal
2+
function test_equal() {
3+
bin/version eq $1 $2 2>&1
4+
local exit_code=$?
5+
6+
assert_equals 0 $exit_code;
7+
}
8+
9+
# @data_provider data_not_equal
10+
function test_not_equal() {
11+
bin/version eq $1 $2 2>&1
12+
local exit_code=$?
13+
14+
assert_equals 1 $exit_code;
15+
}
16+
17+
function data_not_equal() {
18+
echo "1.0.0" "1.0.1";
19+
echo "v2.0.0" "v2.1.0";
20+
echo "3.5.2-alpha.1" "3.5.2-alpha.2";
21+
}
22+
23+
function data_equal() {
24+
echo "1.0.0" "1.0.0";
25+
echo "v2.0.0" "v2.0.0";
26+
echo "3.5.1-alpha.1" "3.5.1-alpha.1";
27+
echo "4.0.0-beta.2+1" "4.0.0-beta.2+2"; # Build metadata should not affect equality.
28+
echo "4.2.0-beta.2+1" "4.2.0-beta.2+1";
29+
}

tests/bashunit/test_gt.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# @data_provider data_greater_than
2+
function test_greater_than() {
3+
bin/version gt $1 $2 2>&1
4+
local exit_code=$?
5+
6+
assert_equals 0 $exit_code;
7+
}
8+
9+
# @data_provider data_not_greater_than
10+
function test_not_greater_than() {
11+
bin/version gt $1 $2 2>&1
12+
local exit_code=$?
13+
14+
assert_equals 1 $exit_code;
15+
}
16+
17+
function data_not_greater_than() {
18+
echo "1.0.0" "1.0.0"; # Equal.
19+
echo "v2.0.0" "v2.1.0"; # Less than.
20+
echo "3.5.2-alpha.1" "3.5.2-alpha.2"; # Less than with pre-release.
21+
echo "3.5.2-alpha.2+2" "3.5.2-alpha.2+1";
22+
}
23+
24+
function data_greater_than() {
25+
echo "1.0.1" "1.0.0"; # Greater than.
26+
echo "v2.1.0" "v2.0.0"; # Greater than with prefix.
27+
echo "3.5.2-alpha.2" "3.5.2-alpha.1"; # Greater than with pre-release.
28+
}

tests/bashunit/test_increment.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# @data_provider data_increment_patch
2+
function test_increment_patch() {
3+
ver=$(bin/version increment $1);
4+
assert_equals $ver $2;
5+
}
6+
7+
# @data_provider data_increment_minor
8+
function test_increment_minor() {
9+
ver=$(bin/version increment $1 --part minor);
10+
assert_equals $ver $2;
11+
}
12+
13+
# @data_provider data_increment_major
14+
function test_increment_major() {
15+
ver=$(bin/version increment $1 --part major);
16+
assert_equals $ver $2;
17+
}
18+
19+
# @data_provider data_increment_with_pre_release
20+
function test_increment_with_pre_release() {
21+
ver=$(bin/version increment $1 --pre alpha);
22+
assert_equals $ver $2;
23+
}
24+
25+
# @data_provider data_increment_with_build
26+
function test_increment_with_build() {
27+
ver=$(bin/version increment $1 --build 123);
28+
assert_equals $ver $2;
29+
}
30+
31+
# @data_provider data_increment_with_pre_release_and_build
32+
function test_increment_with_pre_release_and_build() {
33+
ver=$(bin/version increment $1 --build 123 --pre alpha);
34+
assert_equals $ver $2;
35+
}
36+
37+
function data_increment_patch() {
38+
echo "0.0.0" "0.0.1";
39+
echo "1.0.0" "1.0.1";
40+
}
41+
42+
function data_increment_minor() {
43+
echo "0.0.0" "0.1.0";
44+
echo "1.0.0" "1.1.0";
45+
}
46+
47+
function data_increment_major() {
48+
echo "0.0.0" "1.0.0";
49+
echo "1.0.0" "2.0.0";
50+
}
51+
52+
function data_increment_with_pre_release() {
53+
echo "0.0.0" "0.0.1-alpha";
54+
echo "1.0.0" "1.0.1-alpha";
55+
}
56+
57+
function data_increment_with_pre_release_and_build() {
58+
echo "0.0.0" "0.0.1-alpha+123";
59+
echo "1.0.0" "1.0.1-alpha+123";
60+
}

tests/bashunit/test_lt.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# @data_provider data_less_than
2+
function test_less_than() {
3+
bin/version lt $1 $2 2>&1
4+
local exit_code=$?
5+
6+
assert_equals 0 $exit_code;
7+
}
8+
9+
# @data_provider data_not_less_than
10+
function test_not_less_than() {
11+
bin/version lt $1 $2 2>&1
12+
local exit_code=$?
13+
14+
assert_equals 1 $exit_code;
15+
}
16+
17+
function data_less_than() {
18+
echo "1.0.0" "1.0.1";
19+
echo "v2.0.0" "v2.1.0";
20+
echo "3.5.2-alpha.1" "3.5.2-alpha.2";
21+
}
22+
23+
function data_not_less_than() {
24+
echo "1.0.0" "1.0.0"; # Equal.
25+
echo "v2.0.0" "v1.0.0"; # Greater than.
26+
echo "3.5.1-alpha.2" "3.5.1-alpha.1"; # Greater than with pre-release.
27+
}

tests/bashunit/test_validate.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# @data_provider data_valid
2+
function test_equal() {
3+
bin/version validate $1 2>&1
4+
local exit_code=$?
5+
6+
assert_equals 0 $exit_code;
7+
}
8+
9+
# @data_provider data_invalid
10+
function test_invalid() {
11+
bin/version validate $1 2>&1
12+
local exit_code=$?
13+
14+
assert_equals 1 $exit_code;
15+
}
16+
17+
function data_valid() {
18+
echo "1.0.0"
19+
echo "v1.0.0"
20+
echo "2.1.7-alpha"
21+
echo "1.0.0-beta.1"
22+
echo "3.4.5+build.78"
23+
echo "0.9.1-alpha.1+exp.sha.5114f85"
24+
}
25+
26+
function data_invalid() {
27+
echo "0"
28+
echo "0.0"
29+
echo "v"
30+
echo "v0"
31+
echo "v0.0"
32+
}

tests/phpunit/Commands/ValidateCommandTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public function testValidVersionArgument(string $version): void
4747

4848
public static function dataInvalidVersionArgument(): iterable
4949
{
50+
yield ['0'];
51+
yield ['0.0'];
5052
yield ['v'];
5153
yield ['v0'];
5254
yield ['v0.0'];

0 commit comments

Comments
 (0)