Skip to content

Commit 1f5d9f3

Browse files
authored
Document gitlab integration. (#7)
1 parent 58562b4 commit 1f5d9f3

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Minimum Effort Ada Unit Testing Library
1111
- Parallelization of tests
1212
- Randomization of test order to find dependencies between tests
1313
- No generated code or scripts needed
14+
- [JUnit XML reports and GitLab integration](docs/gitlab.md)
1415

1516
## Example
1617

docs/gitlab-pipeline.png

81.7 KB
Loading

docs/gitlab.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# GitLab integration
2+
3+
Gitlab CI can import test information using XML format.
4+
Here's how to do it. For example, let's create a primitive library
5+
and tests for it on trendy_test:
6+
7+
```shell
8+
alr init --in-place --lib test2
9+
cd test2
10+
alr init --bin testsuite
11+
cd testsuite
12+
alr with test2 --use=..
13+
alr with trendy_test --use=https://github.com/pyjarrett/trendy_test
14+
```
15+
16+
Let's add a simple function that we will test later:
17+
```ada
18+
package Test2 is
19+
20+
function Inc (Value : Integer) return Integer is
21+
(Value + 1);
22+
23+
end Test2;
24+
```
25+
26+
The simplest test might look like this:
27+
```ada
28+
with Test2;
29+
30+
with Trendy_Test;
31+
with Trendy_Test.XML_Reports;
32+
33+
procedure Testsuite is
34+
35+
procedure Test_Inc (T : in out Trendy_Test.Operation'Class) is
36+
begin
37+
T.Register; -- Don't put anything above here
38+
39+
Trendy_Test.Assert
40+
(T, Condition => Test2.Inc (2) = 3);
41+
end Test_Inc;
42+
43+
My_Tests : constant Trendy_Test.Test_Group :=
44+
(1 => Test_Inc'Unrestricted_Access);
45+
begin
46+
Trendy_Test.Register (My_Tests);
47+
48+
Trendy_Test.XML_Reports.Print_XML_Report
49+
(File_Name => "junit.xml",
50+
Results => Trendy_Test.Run);
51+
end Testsuite;
52+
```
53+
54+
After running such a test, it leaves an XML report `junit.xml` in the current directory.
55+
56+
Let's create a GitLab CI description file `.gitlab-ci.yml`:
57+
58+
```yaml
59+
default:
60+
image: ubuntu:22.04
61+
build-job:
62+
stage: build
63+
script:
64+
- ./.ci-script.sh
65+
66+
artifacts:
67+
when: always
68+
paths:
69+
- testsuite/junit.xml
70+
reports:
71+
junit: testsuite/junit.xml
72+
```
73+
74+
And the bash script itself `.ci-script.sh`:
75+
76+
```shell
77+
#!/bin/sh
78+
apt-get update -y
79+
apt-get install -y curl zip git libc6-dev
80+
curl -L -O https://github.com/alire-project/alire/releases/download/v2.1.0/alr-2.1.0-bin-x86_64-linux.zip
81+
unzip alr*.zip
82+
PATH=$PWD/bin:$PATH
83+
alr toolchain --select gprbuild^25 gnat_native^15
84+
alr -C testsuite run
85+
```
86+
87+
Having added all this to the gitlab repository, we will see the tests
88+
on the **Tests** tab in **Pipelines**:
89+
90+
![GitLab Pipeline screenshot](gitlab-pipeline.png)
91+
92+
Repository with example: [gitlab.com/reznikmm/test2](https://gitlab.com/reznikmm/test2)

0 commit comments

Comments
 (0)