gradle: add package tests

This commit is contained in:
Olli Helenius 2023-12-29 14:30:21 +02:00
parent db339f1706
commit 55a283228c
No known key found for this signature in database
GPG Key ID: 67235CC88F41DE3C
3 changed files with 52 additions and 8 deletions

View File

@ -26,17 +26,26 @@ rec {
]
}:
{ lib, stdenv, fetchurl, makeWrapper, unzip, ncurses5, ncurses6,
{ lib
, stdenv
, fetchurl
, makeWrapper
, unzip
, ncurses5
, ncurses6
, testers
, runCommand
, writeText
# The JDK/JRE used for running Gradle.
java ? defaultJava,
# The JDK/JRE used for running Gradle.
, java ? defaultJava
# Additional JDK/JREs to be registered as toolchains.
# See https://docs.gradle.org/current/userguide/toolchains.html
javaToolchains ? [ ]
# Additional JDK/JREs to be registered as toolchains.
# See https://docs.gradle.org/current/userguide/toolchains.html
, javaToolchains ? [ ]
}:
stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
pname = "gradle";
inherit version;
@ -99,6 +108,29 @@ rec {
echo ${ncurses6} >> $out/nix-support/manual-runtime-dependencies
'';
passthru.tests = {
version = testers.testVersion {
package = finalAttrs.finalPackage;
command = ''
env GRADLE_USER_HOME=$TMPDIR/gradle org.gradle.native.dir=$TMPDIR/native \
gradle --version
'';
};
java-application = testers.testEqualContents {
assertion = "can build and run a trivial Java application";
expected = writeText "expected" "hello\n";
actual = runCommand "actual" {
nativeBuildInputs = [ finalAttrs.finalPackage ];
src = ./tests/java-application;
} ''
cp -a $src/* .
env GRADLE_USER_HOME=$TMPDIR/gradle org.gradle.native.dir=$TMPDIR/native \
gradle run --no-daemon --quiet --console plain > $out
'';
};
};
meta = with lib; {
inherit platforms;
description = "Enterprise-grade build system";
@ -121,7 +153,7 @@ rec {
maintainers = with maintainers; [ lorenzleutgeb liff ];
mainProgram = "gradle";
};
};
});
# NOTE: Default JDKs that are hardcoded below must be LTS versions
# and respect the compatibility matrix at

View File

@ -0,0 +1,7 @@
plugins {
id('application')
}
application {
mainClass = 'Main'
}

View File

@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
System.out.println("hello");
}
}