Skip to content

Commit 15263df

Browse files
Copilotandreasabel
andauthored
Convert test infrastructure to tasty-golden based testsuite (#450)
* Initial plan * Convert test infrastructure to tasty-golden based testsuite - Create test/Succeed/ and test/Fail/ directory structure - Move .agda test files to appropriate directories - Move golden .hs files next to their .agda files in test/Succeed/ - Move golden .err files next to their .agda files in test/Fail/ - Create test/Main.hs test runner using tasty-golden - Add test-suite section to agda2hs.cabal - Add test data files to cabal file - Remove old AllTests.agda, AllFailTests.agda, AllCubicalTests.agda - Remove old golden/ directory Co-authored-by: andreasabel <[email protected]> * Fix test runner for module discovery and UTF-8 encoding - Add include paths for agda2hs to find modules in Succeed directory - Add include paths for GHC to find imported Haskell modules - Fix UTF-8 encoding issue in error message comparison using Data.Text - Add text dependency to test-suite - Revert agda-lib changes (no longer needed with include path approach) - Remove duplicate Cubical subdirectory Co-authored-by: andreasabel <[email protected]> * Convert test infrastructure to tasty-golden based testsuite - Create test/Succeed/ and test/Fail/ directory structure - Move .agda test files with golden values alongside (.hs and .err) - Create test/Main.hs test runner using tasty-golden - Add test-suite section to agda2hs.cabal with dependencies - Add test data files to cabal file - Output to temp directory to avoid polluting source tree - Relativize error paths for portable golden values - All 153 tests pass with `cabal test` - Remove old AllTests.agda, AllFailTests.agda, AllCubicalTests.agda - Remove old golden/ directory Co-authored-by: andreasabel <[email protected]> * Address PR review feedback - Move language extensions to default-extensions in cabal file - Use System.Directory.doesDirectoryExist instead of custom implementation - Use Data.List.isInfixOf instead of custom implementation - Inline content read and add comment about golden value - Sort files by modification time (newest first), then golden value time, then alphabetically - Update Makefile with new test goals (succeed, fail, golden, golden-succeed, golden-fail) - Delete test/Makefile - Add DEVELOPER.md with test suite documentation - Add Andreas Abel and Copilot to author lists in .cabal and LICENSE Co-authored-by: andreasabel <[email protected]> * Remove unused UTCTime import Co-authored-by: andreasabel <[email protected]> * Fix Makefile TAB characters and simplify sortByModTime - Restore TAB characters in Makefile (required for make syntax) - Simplify sortByModTime using Down wrappers and standard tuple ordering - Remove custom fileOrder function and use standard sort Co-authored-by: andreasabel <[email protected]> * Fix Makefile for CI * Attempt to fix nix CI * Fix nix CI: add diffutils parameter to agda2hs.nix The testsuite uses diff, so diffutils needs to be available. In agda2hs.nix, pkgs refers to the list of Agda packages (not nixpkgs), so diffutils must be passed as a function parameter via callPackage. Co-authored-by: andreasabel <[email protected]> * Disable tests in nix build to fix circular dependency The testsuite requires the agda2hs binary to be in PATH, but during nix build of the Haskell package, the binary isn't available yet. This creates a circular dependency. Use dontCheck to disable tests in nix builds - tests should be run via `cabal test` in a development environment instead. Co-authored-by: andreasabel <[email protected]> * Address code style review comments - Restore comments for fixWhitespace, checkWhitespace, have-bin-% targets - Move .PHONY for have-bin-% to top of file with other .PHONY markers - Factor out discoverTests function to reduce code duplication - Use filterM with doesDirectoryExist/doesFileExist in findAgdaFiles - Refactor relativizeLine to use any (`isInfixOf` rest) - Use break '/' instead of drop 1 in findTestPrefix Co-authored-by: andreasabel <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: andreasabel <[email protected]> Co-authored-by: Andreas Abel <[email protected]>
1 parent 3bf65eb commit 15263df

File tree

276 files changed

+372
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

276 files changed

+372
-456
lines changed

DEVELOPER.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Developer Documentation
2+
3+
## Running the Test Suite
4+
5+
The test suite uses `tasty-golden` for golden value testing. Tests are organized into two categories:
6+
7+
- **Succeed tests** (`test/Succeed/`): Agda files that should compile successfully with agda2hs. The generated `.hs` files are the golden values.
8+
- **Fail tests** (`test/Fail/`): Agda files that should fail to compile. The error messages (in `.err` files) are the golden values.
9+
10+
### Running All Tests
11+
12+
```bash
13+
# Run all tests (includes whitespace check and container tests)
14+
make test
15+
16+
# Or run just the agda2hs tests
17+
cabal test agda2hs-test
18+
```
19+
20+
### Running Specific Test Categories
21+
22+
```bash
23+
# Run only successful tests
24+
make succeed
25+
26+
# Run only failing tests
27+
make fail
28+
29+
# Or using cabal directly with pattern matching
30+
cabal test agda2hs-test --test-options='-p Succeed'
31+
cabal test agda2hs-test --test-options='-p Fail'
32+
```
33+
34+
### Running Individual Tests
35+
36+
```bash
37+
# Run a specific test by name
38+
cabal test agda2hs-test --test-options='-p /Fixities/'
39+
40+
# Run tests matching a pattern
41+
cabal test agda2hs-test --test-options='-p /Issue/'
42+
```
43+
44+
## Updating Golden Values
45+
46+
When you make changes that intentionally affect the test output, you need to update the golden values:
47+
48+
```bash
49+
# Update all golden values
50+
make golden
51+
52+
# Update only successful test golden values
53+
make golden-succeed
54+
55+
# Update only failing test golden values
56+
make golden-fail
57+
58+
# Or using cabal directly
59+
cabal test agda2hs-test --test-options='--accept'
60+
```
61+
62+
After updating golden values, review the changes with `git diff` to ensure they are correct before committing.
63+
64+
## Adding New Tests
65+
66+
### Adding a Succeed Test
67+
68+
1. Create a new `.agda` file in `test/Succeed/`
69+
2. Run `make golden-succeed` to generate the golden `.hs` file
70+
3. Verify the generated Haskell code is correct
71+
4. Commit both the `.agda` and `.hs` files
72+
73+
### Adding a Fail Test
74+
75+
1. Create a new `.agda` file in `test/Fail/`
76+
2. Run `make golden-fail` to generate the golden `.err` file
77+
3. Verify the error message is correct
78+
4. Commit both the `.agda` and `.err` files
79+
80+
## Test Ordering
81+
82+
Tests are ordered by:
83+
1. Modification date of the `.agda` file (newest first)
84+
2. Modification date of the golden value file (newest first)
85+
3. Alphabetically
86+
87+
This ordering ensures that recently modified tests appear first in the output, making it easier to focus on tests you're actively working on.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2025 Ulf Norell, Jesper Cockx, Orestis Melkonian, Sára Juhošová, James Chapman, Lucas Escot, Henry Blanchette, Viktor Csimma, Aleksander Wolska, Paul Bittner, Andreas Källberg, Bohdan Liesnikov, Jakob Naucke, and Heinrich Apfelmus.
1+
Copyright 2025 Ulf Norell, Jesper Cockx, Orestis Melkonian, Sára Juhošová, James Chapman, Lucas Escot, Henry Blanchette, Viktor Csimma, Aleksander Wolska, Paul Bittner, Andreas Källberg, Bohdan Liesnikov, Jakob Naucke, Heinrich Apfelmus, Andreas Abel, and Copilot.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

Makefile

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
.PHONY : install agda repl libHtml testContainers test test-on-CI testHtml golden clean docs
1+
.PHONY : build install agda repl libHtml testContainers test succeed fail golden golden-succeed golden-fail clean docs fixWhitespace checkWhitespace have-bin-%
2+
23
FILES = $(shell find src -type f)
34

45
build :
@@ -11,45 +12,57 @@ agda :
1112
cabal install Agda --program-suffix=-erased --overwrite-policy=always
1213

1314
repl :
14-
cabal repl # e.g. `:set args -itest -otest/build test/AllTests.agda ... main ... :r ... main`
15+
cabal repl
1516

1617
libHtml :
1718
cabal run agda2hs -- --html --include-path lib/base lib/base/Haskell/Prelude.agda
1819
cp html/Haskell.Prelude.html html/index.html
1920

20-
test/agda2hs : $(FILES)
21-
cabal install agda2hs --overwrite-policy=always --installdir=test --install-method=copy
22-
2321
testContainers:
2422
cd ./lib/containers && ./generate-haskell.sh && cabal build containers-prop
2523

24+
# Run all tests
2625
test : checkWhitespace test-on-CI
2726

28-
test-on-CI : test/agda2hs testContainers
29-
make -C test
27+
# Run all tests except for fix-whitespace
28+
test-on-CI : succeed fail testContainers
29+
30+
# Run only successful tests
31+
succeed :
32+
cabal test agda2hs-test --test-options='-p Succeed'
33+
34+
# Run only failing tests
35+
fail :
36+
cabal test agda2hs-test --test-options='-p Fail'
37+
38+
# Update all golden values
39+
golden : golden-succeed golden-fail
3040

31-
testHtml : test/agda2hs
32-
make -C test html
41+
# Update golden values for successful tests
42+
golden-succeed :
43+
cabal test agda2hs-test --test-options='-p Succeed --accept'
3344

34-
golden :
35-
make -C test golden
45+
# Update golden values for failing tests
46+
golden-fail :
47+
cabal test agda2hs-test --test-options='-p Fail --accept'
3648

3749
clean :
38-
make -C test clean
50+
cabal clean
51+
rm -rf test/_build/
3952

4053
docs :
4154
make -C docs html
4255

4356
FIXW_BIN = fix-whitespace
4457

45-
.PHONY : fixWhitespace #Fix the whitespace issue.
58+
## Fix the whitespace issue.
4659
fixWhitespace : have-bin-$(FIXW_BIN) fix-whitespace.yaml
4760
$(FIXW_BIN)
4861

49-
.PHONY : checkWhitespace #Check the whitespace issue without fixing it.
62+
## Check the whitespace issue without fixing it.
5063
checkWhitespace : have-bin-$(FIXW_BIN) fix-whitespace.yaml
5164
$(FIXW_BIN) --check
5265

53-
.PHONY : have-bin-% ## Installing binaries for developer services
66+
## Installing binaries for developer services
5467
have-bin-% :
5568
@($* --help > /dev/null) || $(CABAL) install --ignore-project $*

agda2hs.cabal

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: agda2hs
33
version: 1.5
44
license: BSD-3-Clause
55
license-file: LICENSE
6-
author: Ulf Norell, Jesper Cockx, Orestis Melkonian, Sára Juhošová, James Chapman, Lucas Escot, Henry Blanchette, Viktor Csimma, Aleksander Wolska, Paul Bittner, Andreas Källberg, Bohdan Liesnikov, Jakob Naucke, and Heinrich Apfelmus
6+
author: Ulf Norell, Jesper Cockx, Orestis Melkonian, Sára Juhošová, James Chapman, Lucas Escot, Henry Blanchette, Viktor Csimma, Aleksander Wolska, Paul Bittner, Andreas Källberg, Bohdan Liesnikov, Jakob Naucke, Heinrich Apfelmus, Andreas Abel, and Copilot
77
maintainer: [email protected]
8-
copyright: 2025 Ulf Norell, Jesper Cockx, Orestis Melkonian, Sára Juhošová, James Chapman, Lucas Escot, Henry Blanchette, Viktor Csimma, Aleksander Wolska, Paul Bittner, Andreas Källberg, Bohdan Liesnikov, Jakob Naucke, and Heinrich Apfelmus
8+
copyright: 2025 Ulf Norell, Jesper Cockx, Orestis Melkonian, Sára Juhošová, James Chapman, Lucas Escot, Henry Blanchette, Viktor Csimma, Aleksander Wolska, Paul Bittner, Andreas Källberg, Bohdan Liesnikov, Jakob Naucke, Heinrich Apfelmus, Andreas Abel, and Copilot
99
category: Language, Compiler
1010
build-type: Simple
1111
synopsis: Compiling Agda code to readable Haskell.
@@ -21,6 +21,14 @@ extra-doc-files: CHANGELOG.md
2121
data-files:
2222
lib/base/base.agda-lib
2323
lib/base/**/*.agda
24+
test/agda2hs-test.agda-lib
25+
test/Haskell/**/*.agda
26+
test/Succeed/*.agda
27+
test/Succeed/*.hs
28+
test/Succeed/**/*.agda
29+
test/Succeed/**/*.hs
30+
test/Fail/*.agda
31+
test/Fail/*.err
2432

2533
source-repository head
2634
type: git
@@ -83,3 +91,22 @@ executable agda2hs
8391
NondecreasingIndentation
8492
OverloadedStrings
8593
ghc-options: -Werror -rtsopts
94+
95+
test-suite agda2hs-test
96+
type: exitcode-stdio-1.0
97+
hs-source-dirs: test
98+
main-is: Main.hs
99+
build-depends: base >= 4.13 && < 4.22,
100+
bytestring >= 0.11.5 && < 0.13,
101+
directory >= 1.2.6.2 && < 1.4,
102+
filepath >= 1.4.1.0 && < 1.6,
103+
process >= 1.6 && < 1.7,
104+
tasty >= 1.4 && < 1.6,
105+
tasty-golden >= 2.3 && < 2.4,
106+
text >= 2.0.2 && < 2.2,
107+
time >= 1.9 && < 1.15,
108+
default-language: Haskell2010
109+
default-extensions: OverloadedStrings
110+
ScopedTypeVariables
111+
build-tool-depends: agda2hs:agda2hs
112+
ghc-options: -threaded

nix/agda2hs.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
makeWrapper,
1313
writeText,
1414
ghcWithPackages,
15+
diffutils,
1516
}:
1617

1718
let
@@ -51,7 +52,10 @@ let
5152
runCommand "${pname}-${version}"
5253
{
5354
inherit pname version;
54-
nativeBuildInputs = [ makeWrapper ];
55+
nativeBuildInputs = [
56+
diffutils
57+
makeWrapper
58+
];
5559
passthru = {
5660
unwrapped = agda2hs;
5761
inherit withPackages;

nix/lib.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ let
1010
src = ../.;
1111
extraCabal2nixOptions = options; # "--jailbreak"
1212
};
13-
hpkg = pkgs.haskellPackages.callPackage (hsrc "") { };
13+
# Disable tests in nix build - the testsuite requires the agda2hs binary
14+
# to be in PATH, which is a circular dependency. Tests should be run
15+
# via `cabal test` in a development environment instead.
16+
hpkg = pkgs.haskell.lib.dontCheck (pkgs.haskellPackages.callPackage (hsrc "") { });
1417
expr = import ./agda2hs.nix;
1518
agda2hs = pkgs.lib.makeScope pkgs.newScope (
1619
self:

nix/shell.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ pkgs.haskellPackages.shellFor {
2424
pkgs.nixfmt-rfc-style
2525
cabal2nix
2626
pkgs.haskellPackages.fix-whitespace
27+
# The testsuite uses diff, so ensure `diff` is available in the shell/tests
28+
pkgs.diffutils
2729
];
2830
}

test/AllCubicalTests.agda

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/AllFailTests.agda

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)