From b21d1ae87235b2adf2bdc1e1204d9a8219f32779 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Wed, 28 Apr 2021 15:19:19 +0000 Subject: [PATCH] jre_minimal: add 2 simple tests --- pkgs/development/compilers/openjdk/jre.nix | 5 ++ .../compilers/openjdk/jre_minimal_test1.nix | 16 +++++++ .../compilers/openjdk/tests/hello-logging.nix | 47 +++++++++++++++++++ .../compilers/openjdk/tests/hello.nix | 42 +++++++++++++++++ .../openjdk/tests/test_jre_minimal.nix | 16 +++++++ .../tests/test_jre_minimal_with_logging.nix | 21 +++++++++ 6 files changed, 147 insertions(+) create mode 100644 pkgs/development/compilers/openjdk/jre_minimal_test1.nix create mode 100644 pkgs/development/compilers/openjdk/tests/hello-logging.nix create mode 100644 pkgs/development/compilers/openjdk/tests/hello.nix create mode 100644 pkgs/development/compilers/openjdk/tests/test_jre_minimal.nix create mode 100644 pkgs/development/compilers/openjdk/tests/test_jre_minimal_with_logging.nix diff --git a/pkgs/development/compilers/openjdk/jre.nix b/pkgs/development/compilers/openjdk/jre.nix index 436bd0468c52..78dec7885d93 100644 --- a/pkgs/development/compilers/openjdk/jre.nix +++ b/pkgs/development/compilers/openjdk/jre.nix @@ -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 diff --git a/pkgs/development/compilers/openjdk/jre_minimal_test1.nix b/pkgs/development/compilers/openjdk/jre_minimal_test1.nix new file mode 100644 index 000000000000..eebd11fb2fdf --- /dev/null +++ b/pkgs/development/compilers/openjdk/jre_minimal_test1.nix @@ -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 + '' diff --git a/pkgs/development/compilers/openjdk/tests/hello-logging.nix b/pkgs/development/compilers/openjdk/tests/hello-logging.nix new file mode 100644 index 000000000000..71f3a5543f7c --- /dev/null +++ b/pkgs/development/compilers/openjdk/tests/hello-logging.nix @@ -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 <$out/bin/hello </dev/stdout | grep "Hello, world!" + touch $out + ''