Merge pull request #277530 from liff/gradle/package-tests

gradle: add package tests
This commit is contained in:
Sandro 2024-03-24 22:04:31 +01:00 committed by GitHub
commit 2e4d042d91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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");
}
}