-
Notifications
You must be signed in to change notification settings - Fork 14
/
parser_tests.nix
68 lines (63 loc) · 1.6 KB
/
parser_tests.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Run this using 'nixci' at top-level
{ pkgs ? import <nixpkgs> { }, lib ? pkgs.lib, ... }:
let
parser = pkgs.callPackage ./parser.nix { };
cabalProjectTests =
let
eval = s:
let res = parser.parseCabalProjectPackages s; in
if res.type == "success" then res.value else res;
in
{
testSimple = {
expr = eval ''
packages:
foo
bar
'';
expected = [ "foo" "bar" ];
};
# Handles cases where cabal.project does not end with newline
testEOF = {
expr = eval ''
packages:
foo
bar'';
expected = [ "foo" "bar" ];
};
};
cabalExecutableTests =
let
eval = s:
let res = parser.parseCabalExecutableNames s; in
if res.type == "success" then res.value else res;
in
{
testSimple = {
expr = eval ''
cabal-version: 3.0
name: test-package
version: 0.1
executable foo-exec
main-is: foo.hs
library test
exposed-modules: Test.Types
executable bar-exec
main-is: bar.hs
'';
expected = [ "foo-exec" "bar-exec" ];
};
};
# Like lib.runTests, but actually fails if any test fails.
runTestsFailing = tests:
let
res = lib.runTests tests;
in
if res == builtins.trace "All tests passed" [ ]
then res
else builtins.throw "Some tests failed: ${builtins.toJSON res}" res;
in
{
"cabal.project" = runTestsFailing cabalProjectTests;
"foo-bar.cabal" = runTestsFailing cabalExecutableTests;
}