diff --git a/.github/workflows/prove.yml b/.github/workflows/prove.yml new file mode 100644 index 00000000..78623d22 --- /dev/null +++ b/.github/workflows/prove.yml @@ -0,0 +1,117 @@ +name: PerlProve + +on: + push: + branches: [master] + paths: + - "prove/**" + pull_request: + paths: + - "prove/**" + +env: + LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_PROVE }} + LAUNCHABLE_DEBUG: 1 + LAUNCHABLE_REPORT_ERROR: 1 + +jobs: + tests: + runs-on: ubuntu-latest + defaults: + run: + working-directory: prove + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + pip install wheel setuptools_scm + # pip install launchable + git clone https://github.com/launchableinc/cli.git + cd cli + git checkout fix-remove_teardown + python3 setup.py install + - uses: shogo82148/actions-setup-perl@v1 + with: + perl-version: '5.34' + - name: Install dependencies + run: | + cpan Carton + cpm install + carton install + cpan namespace::autoclean + - run: "launchable verify" + - name: Record commits and build + run: 'launchable record build --name "$GITHUB_RUN_ID" --source ..' # care for working-directory path + - name: Test + continue-on-error: true + run: carton exec prove -Ilib --formatter TAP::Formatter::JUnit -r -j4 --verbose --timer t > junit_output.xml + - name: Record + run: | + cat junit_output.xml + launchable record tests --build "$GITHUB_RUN_ID" prove junit_output.xml + if: always() + - name: Subset + continue-on-error: true + run: | + find ./t -name '*.t' | launchable subset --target 50% --build "$GITHUB_RUN_ID" --rest rest.txt prove > subset.txt + carton exec prove -Ilib --formatter TAP::Formatter::JUnit -r -j4 --verbose --timer $(cat subset.txt) + docker_tests: + runs-on: ubuntu-latest + defaults: + run: + working-directory: prove + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + pip install wheel setuptools_scm + pip install launchable + - run: "launchable verify" + - name: Record commits and build + run: 'launchable record build --name "$GITHUB_RUN_ID" --source ..' # care for working-directory path + - name: Build Docker + run: | + docker build -t test:latest . + - name: Run Docker + continue-on-error: true + run: | + docker run -t --name test -e GITHUB_RUN_ID -e LAUNCHABLE_TOKEN -v ${pwd}:/opt/ test:latest /bin/sh -c "./run.sh" + docker_centos_tests: + runs-on: ubuntu-latest + defaults: + run: + working-directory: prove + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + pip install wheel setuptools_scm + pip install launchable + - run: "launchable verify" + - name: Record commits and build + run: 'launchable record build --name "$GITHUB_RUN_ID" --source ..' # care for working-directory path + - name: Build Docker + run: | + docker build -t test:latest -f Dockerfile.centos . + - name: Run Docker + continue-on-error: true + run: | + docker run -t --name test -e GITHUB_RUN_ID -e LAUNCHABLE_TOKEN -v ${pwd}:/opt/ test:latest /bin/sh -c "./run.sh" diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..4b0384f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +.vscode/* +.python-version diff --git a/prove/.gitignore b/prove/.gitignore index 1b829f59..f6d4fbff 100644 --- a/prove/.gitignore +++ b/prove/.gitignore @@ -34,3 +34,4 @@ cpanfile.snapshot .launchable subset.txt rest.txt +*.xml diff --git a/prove/Dockerfile b/prove/Dockerfile new file mode 100644 index 00000000..3ded2768 --- /dev/null +++ b/prove/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu:latest + +COPY . /opt/ +WORKDIR /opt/ +RUN apt -y update && \ + apt -y install python3 python3-pip git zstd default-jdk cpm build-essential && \ + python3 -m pip install --upgrade pip && \ + pip install wheel setuptools_scm && \ + git clone https://github.com/launchableinc/cli.git && \ + cd cli && \ + git checkout fix-remove_teardown && \ + python3 setup.py install && \ + cd .. && \ + cpan Carton && \ + cpm install && \ + carton install && \ + cpan namespace::autoclean && \ + chmod +x /opt/run.sh diff --git a/prove/Dockerfile.centos b/prove/Dockerfile.centos new file mode 100644 index 00000000..ddb8f792 --- /dev/null +++ b/prove/Dockerfile.centos @@ -0,0 +1,50 @@ +FROM centos:centos7.9.2009 + +COPY . /opt/ +WORKDIR /opt/ +RUN yum update -y && \ + yum groupinstall -y "development tools" && \ + yum install -y bzip2-devel gdbm-devel libffi-devel libuuid-devel ncurses-devel \ + readline-devel sqlite-devel tk-devel wget xz-devel zlib-devel epel-release \ + curl make git gcc zstd default-jdk build-essential java-1.8.0-openjdk \ + perl perl-core perl-local-lib perl-CPAN perl-App-cpanminus expat-devel perl-XML-SemanticDiff \ + perl-Test-Unit-Runner-Xml perl-File-Slurp perl-Moose perl-IPC-Run perl-Test-XML \ + perl-XML-SAX perl-XML-SAX-Writer perl-XML-Twig perl-XML-XPath && \ + yum -y remove openssl openssl-devel + +WORKDIR /opt/ +RUN wget https://www.openssl.org/source/openssl-1.1.1t.tar.gz && \ + tar xvf openssl-1.1.1t.tar.gz && \ + cd openssl-1.1*/ && \ + ./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib no-shared zlib-dynamic && \ + make && \ + make test && \ + make install && \ + echo "export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64" >> /etc/profile.d/openssl.sh && \ + source /etc/profile.d/openssl.sh + +WORKDIR /opt/ +RUN wget https://www.python.org/ftp/python/3.8.16/Python-3.8.16.tgz && \ + tar xzf Python-3.8.16.tgz && \ + cd Python-3.8.16 && \ + ./configure --enable-optimizations && \ + make altinstall && \ + python3.8 -m pip install --upgrade pip && \ + pip install install wheel setuptools_scm && \ + git clone https://github.com/launchableinc/cli.git && \ + cd cli && \ + git checkout fix-remove_teardown && \ + python3.8 setup.py install + +WORKDIR /opt/ +RUN curl -fsSL https://raw.githubusercontent.com/skaji/cpm/main/cpm > cpm && \ + chmod +x cpm && \ + cpan Carton; exit 0 + +RUN cpan Carton && \ + cpan install MooseX::NonMoose && \ + cpan install XML::Parser && \ + ./cpm install && \ + carton install && \ + cpan namespace::autoclean && \ + chmod +x /opt/run.sh diff --git a/prove/README.md b/prove/README.md index 0433cc2a..4cfd54a7 100644 --- a/prove/README.md +++ b/prove/README.md @@ -7,28 +7,55 @@ Example - Example Perl prove project for Launchable ## Install dependencies -Please install [`Carton`](https://metacpan.org/pod/Carton) before trying this project. +Please install [`Carton`](https://metacpan.org/pod/Carton) before trying this project. Also, use [TAP::Formatter::JUnit](https://github.com/bleargh45/TAP-Formatter-JUnit) for generating JUnit XML report. The [TAP::Formatter::JUnit](https://github.com/bleargh45/TAP-Formatter-JUnit) is included in the [cpanfile](./cpanfile). ```sh $ cpanm Carton (or cpan Carton) + $ cpm install $ carton install ``` ## Run tests ```sh -$ export JUNIT_NAME_MANGLE=none -$ carton exec prove -Ilib --harness TAP::Harness::JUnit -r t - -xmlfile argument not supplied, defaulting to "junit_output.xml" at ~/examples/prove/local/lib/perl5/TAP/Harness/JUnit.pm line 125. -t/00_compile.t .... ok -t/easy/01_easy.t .. ok -t/math/01_math.t .. ok -All tests successful. -Files=3, Tests=6, 0.092551 wallclock secs ( 0.01 usr 0.00 sys + 0.06 cusr 0.01 csys = 0.08 CPU) -Result: PASS - -$ BUILD_NAME=test +$ carton exec prove -Ilib --formatter TAP::Formatter::JUnit -r -j4 --verbose --timer t > junit_output.xml + +# Failed test 'add(1, 2) == 5' +# at t/fail/01_fail.t line 9. +# got: '3' +# expected: '5' + +# Failed test 'add(1, 2) == 5' +# at t/fail/02_fail.t line 9. +# +-----+----+-------+ +# | GOT | OP | CHECK | +# +-----+----+-------+ +# | 3 | eq | 5 | +# +-----+----+-------+ + + # Failed test '1 + 2' + # at t/fail/01_fail.t line 14. + # got: '3' + # expected: '4' + # Looks like you failed 1 test of 1. + +# Failed test 'add' +# at t/fail/01_fail.t line 15. +# Tests were run but no plan was declared and done_testing() was not seen. + # Failed test '1 + 2' + # at t/fail/02_fail.t line 14. + # +-----+----+-------+ + # | GOT | OP | CHECK | + # +-----+----+-------+ + # | 3 | eq | 4 | + # +-----+----+-------+ + +# Failed test 'add' +# at t/fail/02_fail.t line 15. +# Tests were run but no plan was declared and done_testing() was not seen. +# Seeded srand with seed '20230711' from local date. + +$ BUILD_NAME=test_perl $ launchable record build --name ${BUILD_NAME} --source .. Launchable recorded 1 commit from repository ~/examples @@ -64,7 +91,7 @@ $ launchable inspect tests --test-session-id 12 ## Subsetting your test runs ```shell -$ BUILD_NAME=test +$ BUILD_NAME=test_perl $ TARGET="50%" $ find ./t -name '*.t' | launchable subset --target ${TARGET} --build ${BUILD_NAME} --rest rest.txt prove > subset.txt @@ -89,7 +116,7 @@ $ launchable inspect subset --subset-id 6 | 2 | file=t/00_compile.t | | 0.00 | | 3 | file=t/easy/01_easy.t | | 0.00 | -$ carton exec prove -Ilib --harness TAP::Harness::JUnit -r $(cat subset.txt) +$ carton exec prove -Ilib --formatter TAP::Formatter::JUnit -r $(cat subset.txt) xmlfile argument not supplied, defaulting to "junit_output.xml" at ~/examples/prove/local/lib/perl5/TAP/Harness/JUnit.pm line 125. t/00_compile.t .. ok diff --git a/prove/cpanfile b/prove/cpanfile index 2d3971ef..dfd0fd0e 100644 --- a/prove/cpanfile +++ b/prove/cpanfile @@ -1,8 +1,7 @@ requires 'perl', '5.008001'; on 'test' => sub { - requires 'TAP::Harness::JUnit'; requires 'Test::More', '0.98'; requires 'Test2::V0'; + requires 'TAP::Formatter::JUnit', git => 'https://github.com/shibuiwilliam/TAP-Formatter-JUnit.git'; }; - diff --git a/prove/junit_output.xml b/prove/junit_output.xml deleted file mode 100644 index 1422c3a1..00000000 --- a/prove/junit_output.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - ok 1 - a + b = ab -ok 2 - str_concat { - ok 1 - a + dddd - ok 2 - bb + ccc - 1..2 -} -1..2 - - - - - - ok 1 - add(1, 2) == 3 -# Subtest: add - ok 1 - 1 + 2 - ok 2 - 3 + 4 - 1..2 -ok 2 - add -# Subtest: double - ok 1 - 1 + 2 - ok 2 - 3 + 2 - 1..2 -ok 3 - double -1..3 - - - - - - - ok 1 - use Example; -1..1 - - - - diff --git a/prove/lib/Example/Easy.pm b/prove/lib/Example/Easy.pm index 813d518a..8e1f46cf 100644 --- a/prove/lib/Example/Easy.pm +++ b/prove/lib/Example/Easy.pm @@ -6,6 +6,7 @@ use utf8; sub str_concat { my ($a, $b) = @_; + sleep(1); return $a.$b; } diff --git a/prove/lib/Example/Math.pm b/prove/lib/Example/Math.pm index a33f33b4..53b70038 100644 --- a/prove/lib/Example/Math.pm +++ b/prove/lib/Example/Math.pm @@ -6,12 +6,14 @@ use utf8; sub add { my ($a, $b) = @_; + sleep(2); return $a + $b; } sub double { my $a = shift; + sleep(1); return $a * 2; } diff --git a/prove/run.sh b/prove/run.sh new file mode 100644 index 00000000..e653bde7 --- /dev/null +++ b/prove/run.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set +e + +launchable verify +carton exec prove -Ilib --formatter TAP::Formatter::JUnit -r -j4 --verbose --timer t > junit_output.xml +cat junit_output.xml +launchable record tests --build "$GITHUB_RUN_ID" prove junit_output.xml diff --git a/prove/t/easy/01_easy.t b/prove/t/easy/01_easy.t index 86ad25a2..b7eaac6f 100644 --- a/prove/t/easy/01_easy.t +++ b/prove/t/easy/01_easy.t @@ -1,7 +1,7 @@ use strict; use warnings; use utf8; -use Test2::V0; +use Test::More; use Example::Easy; diff --git a/prove/t/easy/02_easy.t b/prove/t/easy/02_easy.t new file mode 100644 index 00000000..eea80f59 --- /dev/null +++ b/prove/t/easy/02_easy.t @@ -0,0 +1,18 @@ +use strict; +use warnings; +use utf8; +use Test2::V0; + +use Example::Easy; + +is(Example::Easy::str_concat("b", "a"), "ba", "b + a = ba"); + +subtest 'str_concat_v2' => sub { + my ($a, $b, $c, $d) = ("a", "bb", "ccc", "dddd"); + + is(Example::Easy::str_concat($a, $d), "adddd", "$a + $d"); + is(Example::Easy::str_concat($b, $c), "bbccc", "$b + $c"); +}; + +done_testing; + diff --git a/prove/t/fail/01_fail.t b/prove/t/fail/01_fail.t new file mode 100644 index 00000000..b5b75444 --- /dev/null +++ b/prove/t/fail/01_fail.t @@ -0,0 +1,15 @@ +use strict; +use warnings; +use utf8; +use Test::More; + +use Example::Math; + + +is(Example::Math::add(1, 2), 5, "add(1, 2) == 5"); + +subtest 'add' => sub { + my ($a, $b) = (1, 2); + + is(Example::Math::add($a, $b), 4, "$a + $b"); +}; diff --git a/prove/t/fail/02_fail.t b/prove/t/fail/02_fail.t new file mode 100644 index 00000000..9c14cfb2 --- /dev/null +++ b/prove/t/fail/02_fail.t @@ -0,0 +1,15 @@ +use strict; +use warnings; +use utf8; +use Test2::V0; + +use Example::Math; + + +is(Example::Math::add(1, 2), 5, "add(1, 2) == 5"); + +subtest 'add' => sub { + my ($a, $b) = (1, 2); + + is(Example::Math::add($a, $b), 4, "$a + $b"); +}; diff --git a/prove/t/math/01_math.t b/prove/t/math/01_math.t index 154cc93b..8d15b10b 100644 --- a/prove/t/math/01_math.t +++ b/prove/t/math/01_math.t @@ -22,4 +22,6 @@ subtest 'double' => sub { is(Example::Math::double($b), 6, "$b + 2"); }; +is(Example::Math::add(3, 2), 5, "add(3, 2) == 5"); + done_testing; diff --git a/prove/t/math/02_math.t b/prove/t/math/02_math.t new file mode 100644 index 00000000..7aedd26f --- /dev/null +++ b/prove/t/math/02_math.t @@ -0,0 +1,27 @@ +use strict; +use warnings; +use utf8; +use Test2::V0; + +use Example::Math; + + +is(Example::Math::add(2, 1), 3, "add(2, 1) == 3"); + +subtest 'add_v2' => sub { + my ($a, $b, $c, $d) = (1, 2, 3, 4); + + is(Example::Math::add($a, $b), 3, "$a + $b"); + is(Example::Math::add($c, $d), 7, "$c + $d"); +}; + +subtest 'double_v2' => sub { + my ($a, $b) = (1, 3); + + is(Example::Math::double($a), 2, "$a + 2"); + is(Example::Math::double($b), 6, "$b + 2"); +}; + +is(Example::Math::add(2, 3), 5, "add(2, 3) == 5"); + +done_testing;