Skip to content

Commit

Permalink
feat: Use semver4j to parse Dafny version and ignore build metadata (#13
Browse files Browse the repository at this point in the history
)

Fixes #9

This allows you to just set dafnyVersion.set("4.9.1") instead of dafnyVersion.set("4.9.1+48e8bd498baaa0af79af008dbf0c34f14b9087b1") (as dafny --version currently outputs it)

Also updated the CI to test on the latest Dafny version. Would be worth testing on a range of supported Dafny versions soon as well.
  • Loading branch information
robin-aws authored Dec 10, 2024
1 parent ceb57fb commit 0b0156f
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
java-version: '17'
distribution: 'corretto'
- name: Set up Dafny
uses: dafny-lang/setup-dafny-action@v1.6.1
uses: dafny-lang/setup-dafny-action@v1.8.0
with:
dafny-version: "4.1.0"
dafny-version: "4.9.0"
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build
arguments: build --info --stacktrace
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
*/

plugins {
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
`java-gradle-plugin`
// Apply the Plugin Publish plugin to make plugin publication possible
// The Plugin Publish plugin will in turn auto-apply the Gradle Plugin Development Plugin (java-gradle-plugin)
// and the Maven Publish plugin (maven-publish)
id("com.gradle.plugin-publish") version "1.2.0"

`maven-publish`
}
Expand All @@ -22,6 +24,7 @@ repositories {
}

dependencies {
implementation("org.semver4j:semver4j:5.4.1")
// Use JUnit Jupiter for testing.
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
}
Expand Down
5 changes: 2 additions & 3 deletions examples/multi-project-incompatible/consumer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ plugins {
dependencies {
implementation(project(":producer"))

// TODO: Replace with 4.1.0 once released
implementation("org.dafny:DafnyRuntime:4.0.0")
implementation("org.dafny:DafnyRuntime:4.9.0")
}

dafny {
dafnyVersion.set("4.1.0")
dafnyVersion.set("4.9.0")

optionsMap.put("unicode-char", true)
}
5 changes: 2 additions & 3 deletions examples/multi-project-incompatible/producer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ plugins {
}

dependencies {
// TODO: Replace with 4.1.0 once released
implementation("org.dafny:DafnyRuntime:4.0.0")
implementation("org.dafny:DafnyRuntime:4.9.0")
}

dafny {
dafnyVersion.set("4.1.0")
dafnyVersion.set("4.9.0")

optionsMap.put("unicode-char", false)
}
5 changes: 2 additions & 3 deletions examples/multi-project/consumer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ plugins {
}

dafny {
dafnyVersion.set("4.1.0")
dafnyVersion.set("4.9.0")
}

dependencies {
implementation(project(":producer"))

// TODO: Replace with 4.1.0 once released
implementation("org.dafny:DafnyRuntime:4.0.0")
implementation("org.dafny:DafnyRuntime:4.9.0")
}
5 changes: 2 additions & 3 deletions examples/multi-project/producer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ plugins {
}

dafny {
dafnyVersion.set("4.1.0")
dafnyVersion.set("4.9.0")

optionsMap.put("function-syntax", 3)
}

dependencies {
// TODO: Replace with 4.1.0 once released
implementation("org.dafny:DafnyRuntime:4.0.0")
implementation("org.dafny:DafnyRuntime:4.9.0")
}
4 changes: 2 additions & 2 deletions examples/multi-project/producer/src/main/dafny/timesTwo.dfy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module {:options "--function-syntax:4"} LibraryModule {
module LibraryModule {

function TimesTwo(x: nat): nat {
function method TimesTwo(x: nat): nat {
x * 2
}
}
2 changes: 1 addition & 1 deletion examples/no-dafny/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ repositories {
}

dafny {
dafnyVersion.set("4.1.0")
dafnyVersion.set("4.9.0")
}
2 changes: 1 addition & 1 deletion examples/simple-verify/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ repositories {
}

dafny {
dafnyVersion.set("4.1.0")
dafnyVersion.set("4.9.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class DafnyPluginFunctionalTest {
.buildAndFail();

Assertions.assertTrue(result.getOutput().contains(
"examples/simple-verify/src/main/dafny/simple.dfy(2,15): Error: assertion might not hold"));
"examples/simple-verify/src/main/dafny/simple.dfy(2,9): Error: assertion might not hold"));
Assertions.assertTrue(result.getOutput().contains(
"examples/simple-verify/src/main/dafny/nested/simple.dfy(2,15): Error: assertion might not hold"));
"examples/simple-verify/src/main/dafny/nested/simple.dfy(2,9): Error: assertion might not hold"));
}

@Test void canReferenceDependencies() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction;
import org.semver4j.Semver;

import java.io.IOException;
import java.util.List;
Expand All @@ -18,9 +19,9 @@ public void checkVersion() throws IOException, InterruptedException {
List<String> args = List.of("--version");
DafnyCLIResult result = invokeDafnyCLI(args);

String expected = getRequiredVersion().get();
String actual = result.stdout().trim();
if (!expected.equals(actual)) {
Semver expected = Semver.parse(getRequiredVersion().get());
Semver actual = Semver.parse(result.stdout().trim());
if (!expected.isEquivalentTo(actual)) {
throw new GradleException("Incorrect Dafny version: expected " + expected + ", found " + actual);
}
}
Expand Down

0 comments on commit 0b0156f

Please sign in to comment.