Incorporate suggestions

- land `HelloWorld.agda` and `TrivialBackend.hs` in files
- replace `runCommand` by `stdenvNoCC.mkDerivation`
- refactor asserts
This commit is contained in:
Carlos Tomé Cortiñas
2025-10-23 10:48:35 +02:00
parent 4c64e800a3
commit 5882fce497
3 changed files with 34 additions and 30 deletions

View File

@@ -0,0 +1,5 @@
{-# OPTIONS --guardedness #-}
open import IO
open import Level
main = run {0} (putStrLn "Hello World!")

View File

@@ -0,0 +1,6 @@
module Main where
import Agda.Main ( runAgda )
main :: IO ()
main = runAgda []

View File

@@ -2,34 +2,25 @@
let let
mainProgram = "agda-trivial-backend"; mainProgram = "agda-trivial-backend";
hello-world = pkgs.writeText "hello-world" '' hello-world = ./files/HelloWorld.agda;
{-# OPTIONS --guardedness #-}
open import IO
open import Level
main = run {0} (putStrLn "Hello World!") agda-trivial-backend = pkgs.stdenvNoCC.mkDerivation {
''; name = "trivial-backend";
agda-trivial-backend = meta = { inherit mainProgram; };
pkgs.runCommand "trivial-backend" version = "${pkgs.haskellPackages.Agda.version}";
{ src = ./files/TrivialBackend.hs;
version = "${pkgs.haskellPackages.Agda.version}"; buildInputs = [
meta.mainProgram = "${mainProgram}"; (pkgs.haskellPackages.ghcWithPackages (pkgs: [ pkgs.Agda ]))
buildInputs = [ (pkgs.haskellPackages.ghcWithPackages (pkgs: [ pkgs.Agda ])) ]; ];
} dontUnpack = true;
'' buildPhase = ''
cat << EOF > Main.hs ghc $src -o ${mainProgram}
module Main where '';
installPhase = ''
import Agda.Main ( runAgda ) mkdir -p $out/bin
cp ${mainProgram} $out/bin
main :: IO () '';
main = runAgda [] };
EOF
ghc Main.hs -o ${mainProgram}
mkdir -p $out/bin
cp ${mainProgram} $out/bin
'';
in in
{ {
name = "agda-trivial-backend"; name = "agda-trivial-backend";
@@ -58,14 +49,16 @@ in
testScript = '' testScript = ''
# agda executable is not present # agda executable is not present
machine.fail("agda --version") machine.fail("agda --version")
# backend is present
text = machine.succeed("${mainProgram} --help")
assert "${mainProgram}" in text
# Hello world # Hello world
machine.succeed( machine.succeed(
"cp ${hello-world} HelloWorld.agda" "cp ${hello-world} HelloWorld.agda"
) )
machine.succeed("${mainProgram} -l standard-library -i . -c HelloWorld.agda") machine.succeed("${mainProgram} -l standard-library -i . -c HelloWorld.agda")
# Check execution # Check execution
assert "Hello World!" in machine.succeed( text = machine.succeed("./HelloWorld")
"./HelloWorld" assert "Hello World!" in text, f"HelloWorld does not run properly: output was {text}"
), "HelloWorld does not run properly"
''; '';
} }