From b9a1d83a63b2b7c2bd8aa08bd652b93d77fc136d Mon Sep 17 00:00:00 2001 From: singingbush Date: Tue, 12 Dec 2023 16:27:18 +0000 Subject: [PATCH 1/3] Add GitHub Action and fix #36 --- .github/workflows/dub.yml | 121 ++++++++++++++++++++++++++++++++++++++ .gitignore | 8 +++ README.md | 2 +- dub.json | 7 ++- src/dunit/assertion.d | 6 +- src/dunit/framework.d | 27 +++++---- 6 files changed, 153 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/dub.yml diff --git a/.github/workflows/dub.yml b/.github/workflows/dub.yml new file mode 100644 index 0000000..74c5ca7 --- /dev/null +++ b/.github/workflows/dub.yml @@ -0,0 +1,121 @@ +name: dub + +on: + push: + pull_request: + branches: + - master + +## A wide range of dmd versions on Linux are used to ensure compatibility. On Windows & macOS only the latest DMD and LDC are used +jobs: + test: + name: ${{ matrix.compiler }} on ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest ] # see include section for Windows & macOS builds + compiler: + - dmd-latest + - ldc-latest + - dmd-2.105.3 # (released in 2023) + - dmd-2.104.2 # (released in 2023) + - dmd-2.103.1 # (released in 2023) + - dmd-2.102.2 # (released in 2023) + - dmd-2.101.2 # (released in 2023) + - dmd-2.100.2 # (released in 2022) ## GDC 12 can support 2.100 + - dmd-2.099.1 # (released in 2022) + - dmd-2.098.1 # (released in 2021) + # - dmd-2.097.2 # (released in 2021) + # - dmd-2.096.1 # (released in 2021) + - dmd-2.095.1 # (released in 2021) + - dmd-2.094.2 # (released in 2020) + # - dmd-2.093.1 # (released in 2020) + # - dmd-2.092.1 # (released in 2020) + # - dmd-2.091.1 # (released in 2020) + - dmd-2.090.1 # (released in 2020) + - dmd-2.089.1 # (released in 2019) + # - dmd-2.088.1 # (released in 2019) + # - dmd-2.087.1 # (released in 2019) + # - dmd-2.086.1 # (released in 2019) + # - dmd-2.085.1 # (released in 2019) + - dmd-2.084.1 # (released in 2019) + - dmd-2.083.1 # (released in 2018) + # - dmd-2.082.1 # (released in 2018) + # - dmd-2.081.2 # (released in 2018) + # - dmd-2.080.1 # (released in 2018) + # - dmd-2.079.1 # (released in 2018) + - dmd-2.078.3 # (released in 2018) + - dmd-2.076.1 # compatibility with GDC 11 will require 2076 compatibility (from 2017) + - ldc-1.35.0 # eq to dmd v2.105.2 + - ldc-1.34.0 # eq to dmd v2.104.2 + - ldc-1.33.0 # eq to dmd v2.103.1 + - ldc-1.28.1 # eq to dmd v2.098.1 + - ldc-1.27.1 # eq to dmd v2.097.2 + + include: + - { os: windows-latest, compiler: dmd-latest } # Windows Server 2022 + - { os: windows-latest, compiler: ldc-latest } # Windows Server 2022 + - { os: macos-latest, compiler: dmd-latest } # macOS 12 + - { os: macos-latest, compiler: ldc-latest } # macOS 12 + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - name: Install D ${{ matrix.compiler }} + uses: dlang-community/setup-dlang@v1 + with: + compiler: ${{ matrix.compiler }} + + - name: Show version + if: runner.os != 'Windows' + run: | + $DC --version + dub --version + + - name: run unit tests with coverage + run: dub test --coverage + + - name: build library (strict build) + run: dub build --config=library --build=strict + + +## On Ubuntu we can use GDC. The compatibility of gdc is: +## gcc gdc-10 -> D 2.076 (the default on Ubuntu 20.04 (ubuntu-latest), also available on 22.04) +## gcc gdc-11 -> D 2.076 (requires Ubuntu 22.04) +## gcc gdc-12 -> D 2.100 (requires Ubuntu 22.04) +# gdc: +# name: ${{ matrix.compiler }} on Ubuntu +# strategy: +# fail-fast: false +# matrix: +# compiler: [ gdc-10, gdc-11, gdc-12 ] +# runs-on: ubuntu-22.04 +# +# steps: +# - uses: actions/checkout@v4 +# +# - name: Install DMD (so dub is available) +# uses: dlang-community/setup-dlang@v1 +# with: +# compiler: dmd-latest +# +# - name: Install ${{ matrix.compiler }} +# run: | +# sudo apt update +# sudo apt install ${{ matrix.compiler }} -y +# +# - name: Show version +# run: | +# gdc --version +# dub --version +# +# - name: run unit tests with coverage +# env: +# DC: gdc +# run: dub test --coverage --compiler=gdc +# +# - name: release build of library +# env: +# DC: gdc +# run: dub build --config=library --compiler=gdc --build=release \ No newline at end of file diff --git a/.gitignore b/.gitignore index e0dc92d..d6226cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,13 @@ +# Ignore Intellij IDEA folder: +.idea +*.iml + +# Ignore Sublime Text workspace (project file is ok): +*.sublime-workspace + *.a *.o +*.lst *.swp *.exe .dub diff --git a/README.md b/README.md index 5820f7c..69b01cf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # xUnit Testing Framework for D -[![Build Status](https://travis-ci.org/linkrope/dunit.svg?branch=master)](https://travis-ci.org/linkrope/dunit) +[![DUB Package](https://img.shields.io/dub/v/d-unit.svg)](https://code.dlang.org/packages/d-unit) [![CI](https://github.com/linkrope/dunit/actions/workflows/dub.yml/badge.svg)](https://github.com/linkrope/dunit/actions/workflows/dub.yml) This is a simple implementation of the xUnit Testing Framework for the [D Programming Language]. diff --git a/dub.json b/dub.json index c5a4ac2..030ed47 100644 --- a/dub.json +++ b/dub.json @@ -11,6 +11,11 @@ }, "undead": ">=1.1.1" }, + "buildTypes": { + "strict": { + "buildOptions": ["deprecationErrors", "warningsAsErrors"] + } + }, "configurations": [ { "name": "library", @@ -19,7 +24,7 @@ { "name": "unittest", "targetType": "executable", - "sourceFiles": ["test/main.d"] + "mainSourceFile": "test/main.d" } ] } diff --git a/src/dunit/assertion.d b/src/dunit/assertion.d index 8bb60e1..1025d7f 100644 --- a/src/dunit/assertion.d +++ b/src/dunit/assertion.d @@ -7,7 +7,7 @@ module dunit.assertion; import core.thread; -import core.time; +import core.time : MonoTime; import std.algorithm; import std.array; import std.conv; @@ -669,11 +669,11 @@ public static void assertEventually(bool delegate() probe, string file = __FILE__, size_t line = __LINE__) { - const startTime = TickDuration.currSystemTick(); + const startTime = MonoTime.currTime; while (!probe()) { - const elapsedTime = cast(Duration)(TickDuration.currSystemTick() - startTime); + const elapsedTime = cast(Duration)(MonoTime.currTime - startTime); if (elapsedTime >= timeout) fail(msg.empty ? "timed out" : msg, file, line); diff --git a/src/dunit/framework.d b/src/dunit/framework.d index d75594c..289000a 100644 --- a/src/dunit/framework.d +++ b/src/dunit/framework.d @@ -11,7 +11,8 @@ import dunit.attributes; import dunit.color; import core.runtime; -import core.time; +// import core.time : TickDuration; +import core.time : Duration, MonoTime; import std.algorithm; import std.array; import std.conv; @@ -559,7 +560,7 @@ class IssueReporter : TestListener class DetailReporter : TestListener { private string test; - private TickDuration startTime; + private MonoTime startTime; public override void enterClass(string className) { @@ -569,7 +570,7 @@ class DetailReporter : TestListener public override void enterTest(string test) { this.test = test; - this.startTime = TickDuration.currSystemTick(); + this.startTime = MonoTime.currTime; } public override void skip(string reason) @@ -599,10 +600,10 @@ class DetailReporter : TestListener { if (success) { - const elapsed = (TickDuration.currSystemTick() - this.startTime).usecs() / 1_000.0; + Duration elapsed = MonoTime.currTime() - this.startTime; writec(Color.green, " OK: "); - writefln("%6.2f ms %s", elapsed, this.test); + writefln("%6.2f ms %s", elapsed.total!"msecs", this.test); } } @@ -690,7 +691,7 @@ class XmlReporter : TestListener private Document testCase; private string className; - private TickDuration startTime; + private MonoTime startTime; public override void enterClass(string className) { @@ -702,7 +703,7 @@ class XmlReporter : TestListener this.testCase = new Document(new Tag("testcase")); this.testCase.tag.attr["classname"] = this.className; this.testCase.tag.attr["name"] = test; - this.startTime = TickDuration.currSystemTick(); + this.startTime = MonoTime.currTime; } public override void skip(string reason) @@ -733,9 +734,9 @@ class XmlReporter : TestListener public override void exitTest(bool success) { - const elapsed = (TickDuration.currSystemTick() - this.startTime).msecs() / 1_000.0; + Duration elapsed = MonoTime.currTime() - this.startTime; - this.testCase.tag.attr["time"] = format("%.3f", elapsed); + this.testCase.tag.attr["time"] = format("%.3f", elapsed.total!"msecs"); const report = join(this.testCase.pretty(4), "\n"); @@ -760,7 +761,7 @@ class ReportReporter : TestListener private Element testSuite; private Element testCase; private string className; - private TickDuration startTime; + private MonoTime startTime; public this(string fileName, string testSuiteName) { @@ -782,7 +783,7 @@ class ReportReporter : TestListener this.testCase.tag.attr["classname"] = this.className; this.testCase.tag.attr["name"] = test; this.testSuite ~= this.testCase; - this.startTime = TickDuration.currSystemTick(); + this.startTime = MonoTime.currTime; } public override void skip(string reason) @@ -825,9 +826,9 @@ class ReportReporter : TestListener public override void exitTest(bool success) { - const elapsed = (TickDuration.currSystemTick() - this.startTime).msecs() / 1_000.0; + Duration elapsed = MonoTime.currTime - this.startTime; - this.testCase.tag.attr["time"] = format("%.3f", elapsed); + this.testCase.tag.attr["time"] = format("%.3f", elapsed.total!"msecs"); } public override void exit() From 946e6f360785b4189828329988d0c166f0428397 Mon Sep 17 00:00:00 2001 From: singingbush Date: Tue, 12 Dec 2023 16:50:30 +0000 Subject: [PATCH 2/3] Add GitHub Action and fix #36 --- .github/workflows/dub.yml | 62 ++------------------------------------- 1 file changed, 2 insertions(+), 60 deletions(-) diff --git a/.github/workflows/dub.yml b/.github/workflows/dub.yml index 74c5ca7..14a6276 100644 --- a/.github/workflows/dub.yml +++ b/.github/workflows/dub.yml @@ -25,27 +25,10 @@ jobs: - dmd-2.100.2 # (released in 2022) ## GDC 12 can support 2.100 - dmd-2.099.1 # (released in 2022) - dmd-2.098.1 # (released in 2021) - # - dmd-2.097.2 # (released in 2021) - # - dmd-2.096.1 # (released in 2021) + - dmd-2.097.2 # (released in 2021) + - dmd-2.096.1 # (released in 2021) - dmd-2.095.1 # (released in 2021) - dmd-2.094.2 # (released in 2020) - # - dmd-2.093.1 # (released in 2020) - # - dmd-2.092.1 # (released in 2020) - # - dmd-2.091.1 # (released in 2020) - - dmd-2.090.1 # (released in 2020) - - dmd-2.089.1 # (released in 2019) - # - dmd-2.088.1 # (released in 2019) - # - dmd-2.087.1 # (released in 2019) - # - dmd-2.086.1 # (released in 2019) - # - dmd-2.085.1 # (released in 2019) - - dmd-2.084.1 # (released in 2019) - - dmd-2.083.1 # (released in 2018) - # - dmd-2.082.1 # (released in 2018) - # - dmd-2.081.2 # (released in 2018) - # - dmd-2.080.1 # (released in 2018) - # - dmd-2.079.1 # (released in 2018) - - dmd-2.078.3 # (released in 2018) - - dmd-2.076.1 # compatibility with GDC 11 will require 2076 compatibility (from 2017) - ldc-1.35.0 # eq to dmd v2.105.2 - ldc-1.34.0 # eq to dmd v2.104.2 - ldc-1.33.0 # eq to dmd v2.103.1 @@ -78,44 +61,3 @@ jobs: - name: build library (strict build) run: dub build --config=library --build=strict - - -## On Ubuntu we can use GDC. The compatibility of gdc is: -## gcc gdc-10 -> D 2.076 (the default on Ubuntu 20.04 (ubuntu-latest), also available on 22.04) -## gcc gdc-11 -> D 2.076 (requires Ubuntu 22.04) -## gcc gdc-12 -> D 2.100 (requires Ubuntu 22.04) -# gdc: -# name: ${{ matrix.compiler }} on Ubuntu -# strategy: -# fail-fast: false -# matrix: -# compiler: [ gdc-10, gdc-11, gdc-12 ] -# runs-on: ubuntu-22.04 -# -# steps: -# - uses: actions/checkout@v4 -# -# - name: Install DMD (so dub is available) -# uses: dlang-community/setup-dlang@v1 -# with: -# compiler: dmd-latest -# -# - name: Install ${{ matrix.compiler }} -# run: | -# sudo apt update -# sudo apt install ${{ matrix.compiler }} -y -# -# - name: Show version -# run: | -# gdc --version -# dub --version -# -# - name: run unit tests with coverage -# env: -# DC: gdc -# run: dub test --coverage --compiler=gdc -# -# - name: release build of library -# env: -# DC: gdc -# run: dub build --config=library --compiler=gdc --build=release \ No newline at end of file From cbd322e19d29d123bbf4663882b3df1fdd9dbe7e Mon Sep 17 00:00:00 2001 From: singingbush Date: Tue, 12 Dec 2023 16:51:54 +0000 Subject: [PATCH 3/3] remove travis yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 62d0c9e..0000000 --- a/.travis.yml +++ /dev/null @@ -1 +0,0 @@ -language: d