Skip to content

Commit

Permalink
Reorganize tests
Browse files Browse the repository at this point in the history
Use `rule_test` to verify that a rule a) worked, b) produced the
expected output. This obviates the need for a shell script that
launches binaries and is more general, so can be used systematically.
It's the testing strategy that `rules_rust` uses. We may want to
revive launching binaries later, but this is good enough for now.
Also, systematically put each test in its own subdir.
  • Loading branch information
mboes committed Dec 16, 2017
1 parent d5eaf73 commit 8750b80
Show file tree
Hide file tree
Showing 27 changed files with 159 additions and 110 deletions.
2 changes: 1 addition & 1 deletion haskell/haskell.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ _haskell_common_attrs = {
doc="Package/binary version"
),
"ghcVersion": attr.string(
default="8.0.2",
default="8.2.2",
# TODO (fuuzetsu): We need this because we have to generate
# correct suffix for shared libraries that GHC expects for
# dynamic-library-dirs content. As currently we're using GHC from
Expand Down
88 changes: 35 additions & 53 deletions tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,49 @@ load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_library",
)

haskell_binary(
name = "hello",
srcs = ["Main.hs"],
deps = ["//tests/test-lib"]
)
load("@bazel_tools//tools/build_rules:test_rules.bzl", "rule_test")

haskell_binary(
name = "two-libs-one-BUILD",
main = "TogetherTest.main",
srcs = ["TogetherTest.hs"],
deps = [
"//tests/together-lib:one",
"//tests/together-lib:two"
]
rule_test(
name = "test-binary-simple",
generates = ["binary-simple"],
rule = "//tests/binary-simple",
size = "small",
)

haskell_binary(
name = "non-top-srcs",
sourceDir = "non-top-srcs",
srcs = [
"non-top-srcs/Test.hs",
"non-top-srcs/Main.hs"
],
prebuilt_dependencies = ["base"]
rule_test(
name = "test-binary-with-lib",
generates = ["binary-with-lib"],
rule = "//tests/binary-with-lib",
size = "small",
)

haskell_binary(
name = "main-is",
main = "MainIs.mainIs",
srcs = [ "MainIs.hs" ],
prebuilt_dependencies = ["base"],
rule_test(
name = "test-binary-with-prebuilt",
generates = ["binary-with-prebuilt"],
rule = "//tests/binary-with-prebuilt",
size = "small",
)


haskell_library(
name = "hsc-lib",
sourceDir = "hsc",
srcs = [],
hscs = ["hsc/Test.hsc"],
prebuilt_dependencies = ["base"]
rule_test(
name = "test-binary-with-main",
generates = ["binary-with-main"],
rule = "//tests/binary-with-main",
size = "small",
)

# https://github.com/tweag/rules_haskell/issues/13
haskell_binary(
name = "hsc",
sourceDir = "hsc",
srcs = ["hsc/Main.hs"],
prebuilt_dependencies = ["base"],
deps = [":hsc-lib"],
rule_test(
name = "test-library-deps",
generates =
["library-deps-1.0.0/library-deps-1.0.0.conf",
"library-deps-1.0.0/package.cache",
],
rule = "//tests/library-deps",
size = "small",
)

[sh_test(
name = "Run" + binary,
srcs = ["test_binary.sh"],
args = ["$(location %s)" % binary],
data = [":%s" % binary],
timeout="short",
) for binary in [
"hello",
"two-libs-one-BUILD",
"non-top-srcs",
"main-is",
"hsc",
]]
rule_test(
name = "test-hsc",
generates = ["hsc"],
rule = "//tests/hsc",
size = "small",
)
6 changes: 0 additions & 6 deletions tests/Main.hs

This file was deleted.

4 changes: 0 additions & 4 deletions tests/MainIs.hs

This file was deleted.

9 changes: 9 additions & 0 deletions tests/binary-simple/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_binary",
)

haskell_binary(
name = "binary-simple",
srcs = ["Main.hs"],
visibility = ["//visibility:public"]
)
3 changes: 3 additions & 0 deletions tests/binary-simple/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Main where

main = return ()
17 changes: 17 additions & 0 deletions tests/binary-with-lib/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_binary",
"haskell_library",
)

haskell_library(
name = "lib",
srcs = glob(["src/*.hs"]),
sourceDir = "src",
)

haskell_binary(
name = "binary-with-lib",
srcs = ["Main.hs"],
deps = ["lib"],
visibility = ["//visibility:public"],
)
5 changes: 5 additions & 0 deletions tests/binary-with-lib/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Main where

import Lib (value)

main = print value
5 changes: 5 additions & 0 deletions tests/binary-with-lib/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE NoImplicitPrelude #-}

module Lib (value) where

value = 42
10 changes: 10 additions & 0 deletions tests/binary-with-main/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_binary",
)

haskell_binary(
name = "binary-with-main",
srcs = ["MainIsHere.hs"],
main = "MainIsHere.this",
visibility = ["//visibility:public"]
)
4 changes: 4 additions & 0 deletions tests/binary-with-main/MainIsHere.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MainIsHere (this) where

this :: IO ()
this = return ()
10 changes: 10 additions & 0 deletions tests/binary-with-prebuilt/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_binary",
)

haskell_binary(
name = "binary-with-prebuilt",
srcs = ["Main.hs"],
prebuilt_dependencies = ["base", "template-haskell"],
visibility = ["//visibility:public"]
)
6 changes: 6 additions & 0 deletions tests/binary-with-prebuilt/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Data.List ()
import Language.Haskell.TH ()

main = return ()
20 changes: 20 additions & 0 deletions tests/hsc/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_library",
"haskell_binary",
)

haskell_library(
name = "hsc-lib",
hscs = ["Test.hsc"],
prebuilt_dependencies = ["base"],
)

# https://github.com/tweag/rules_haskell/issues/13
haskell_binary(
name = "hsc",
srcs = ["Main.hs"],
prebuilt_dependencies = ["base"],
deps = [":hsc-lib"],
visibility = ["//visibility:public"],
)
12 changes: 12 additions & 0 deletions tests/library-deps/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_library",
)

haskell_library(
name = "library-deps",
srcs = ["TestLib.hs"],
deps = ["//tests/library-deps/sublib"],
prebuilt_dependencies = ["base"],
visibility = ["//visibility:public"],
)
File renamed without changes.
11 changes: 11 additions & 0 deletions tests/library-deps/sublib/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_library",
)

haskell_library(
name = "sublib",
srcs = ["TestSubLib.hs"],
prebuilt_dependencies = ["base"],
visibility = ["//visibility:public"],
)
File renamed without changes.
6 changes: 0 additions & 6 deletions tests/non-top-srcs/Main.hs

This file was deleted.

2 changes: 0 additions & 2 deletions tests/non-top-srcs/Test.hs

This file was deleted.

17 changes: 0 additions & 17 deletions tests/test-lib/BUILD

This file was deleted.

16 changes: 0 additions & 16 deletions tests/test-sublib/BUILD

This file was deleted.

4 changes: 0 additions & 4 deletions tests/test_binary.sh

This file was deleted.

10 changes: 10 additions & 0 deletions tests/together-lib/BUILD → tests/two-libs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ package(default_visibility = ["//visibility:public"])
load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_library",
"haskell_binary",
)

haskell_binary(
name = "two-libs",
srcs = ["Main.hs"],
deps = [
"one",
"two"
]
)

haskell_library(
Expand Down
2 changes: 1 addition & 1 deletion tests/TogetherTest.hs → tests/two-libs/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module TogetherTest (main) where
module Main where

import One (one)
import Two (two)
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 8750b80

Please sign in to comment.