jre_minimal: add 2 simple tests

This commit is contained in:
Arnout Engelen 2021-04-28 15:19:19 +00:00
parent 1fe6ed37fd
commit b21d1ae872
No known key found for this signature in database
GPG key ID: 061107B0F74A6DAA
6 changed files with 147 additions and 0 deletions

View file

@ -1,6 +1,7 @@
{ stdenv
, jdk
, lib
, callPackage
, modules ? [ "java.base" ]
}:
@ -29,6 +30,10 @@ let
passthru = {
home = "${jre}";
tests = [
(callPackage ./tests/test_jre_minimal.nix {})
(callPackage ./tests/test_jre_minimal_with_logging.nix {})
];
};
};
in jre

View file

@ -0,0 +1,16 @@
{ runCommand
, callPackage
, jdk
, jre_minimal
}:
let
hello = callPackage tests/hello.nix {
jdk = jdk;
jre = jre_minimal;
};
in
runCommand "test" {} ''
${hello}/bin/hello | grep "Hello, world!"
touch $out
''

View file

@ -0,0 +1,47 @@
{ jdk
, jre
, pkgs
}:
/* 'Hello world' Java application derivation for use in tests */
let
source = pkgs.writeTextDir "src/Hello.java" ''
import java.util.logging.Logger;
import java.util.logging.Level;
class Hello {
static Logger logger = Logger.getLogger(Hello.class.getName());
public static void main(String[] args) {
logger.log(Level.INFO, "Hello, world!");
}
}
'';
in
pkgs.stdenv.mkDerivation {
pname = "hello";
version = "1.0.0";
src = source;
buildPhase = ''
runHook preBuildPhase
${jdk}/bin/javac src/Hello.java
runHook postBuildPhase
'';
installPhase = ''
runHook preInstallPhase
mkdir -p $out/lib
cp src/Hello.class $out/lib
mkdir -p $out/bin
cat >$out/bin/hello <<EOF;
#!/usr/bin/env sh
${jre}/bin/java -cp $out/lib Hello
EOF
chmod a+x $out/bin/hello
runHook postInstallPhase
'';
}

View file

@ -0,0 +1,42 @@
{ jdk
, jre
, pkgs
}:
/* 'Hello world' Java application derivation for use in tests */
let
source = pkgs.writeTextDir "src/Hello.java" ''
class Hello {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
'';
in
pkgs.stdenv.mkDerivation {
pname = "hello";
version = "1.0.0";
src = source;
buildPhase = ''
runHook preBuildPhase
${jdk}/bin/javac src/Hello.java
runHook postBuildPhase
'';
installPhase = ''
runHook preInstallPhase
mkdir -p $out/lib
cp src/Hello.class $out/lib
mkdir -p $out/bin
cat >$out/bin/hello <<EOF;
#!/usr/bin/env sh
${jre}/bin/java -cp $out/lib Hello
EOF
chmod a+x $out/bin/hello
runHook postInstallPhase
'';
}

View file

@ -0,0 +1,16 @@
{ runCommand
, callPackage
, jdk
, jre_minimal
}:
let
hello = callPackage ./hello.nix {
jdk = jdk;
jre = jre_minimal;
};
in
runCommand "test" {} ''
${hello}/bin/hello | grep "Hello, world!"
touch $out
''

View file

@ -0,0 +1,21 @@
{ runCommand
, callPackage
, jdk
, jre_minimal
}:
let
hello-logging = callPackage ./hello-logging.nix {
jdk = jdk;
jre = jre_minimal.override {
modules = [
"java.base"
"java.logging"
];
};
};
in
runCommand "test" {} ''
${hello-logging}/bin/hello &>/dev/stdout | grep "Hello, world!"
touch $out
''