about summary refs log tree commit diff
path: root/third_party/bazel/rules_haskell/tests/package-name
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/bazel/rules_haskell/tests/package-name')
-rw-r--r--third_party/bazel/rules_haskell/tests/package-name/BUILD.bazel28
-rw-r--r--third_party/bazel/rules_haskell/tests/package-name/Lib.hs8
-rw-r--r--third_party/bazel/rules_haskell/tests/package-name/Main.hs33
3 files changed, 69 insertions, 0 deletions
diff --git a/third_party/bazel/rules_haskell/tests/package-name/BUILD.bazel b/third_party/bazel/rules_haskell/tests/package-name/BUILD.bazel
new file mode 100644
index 000000000000..9d187f083636
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tests/package-name/BUILD.bazel
@@ -0,0 +1,28 @@
+load(
+    "@io_tweag_rules_haskell//haskell:haskell.bzl",
+    "haskell_library",
+    "haskell_test",
+)
+
+# Tests around our use of package names.
+package(default_testonly = 1)
+
+haskell_library(
+    # The character "Z" should be untouched in the GHC package name.
+    # However, underscores (which are not legal) should be turned into dashes.
+    name = "lib-a_Z",
+    srcs = ["Lib.hs"],
+    version = "1.2.3.4",
+    deps = ["//tests/hackage:base"],
+)
+
+haskell_test(
+    name = "bin",
+    size = "small",
+    srcs = ["Main.hs"],
+    version = "0.0.0",  # This flags triggers the `MIN_VERSION` macro generation
+    deps = [
+        ":lib-a_Z",
+        "//tests/hackage:base",
+    ],
+)
diff --git a/third_party/bazel/rules_haskell/tests/package-name/Lib.hs b/third_party/bazel/rules_haskell/tests/package-name/Lib.hs
new file mode 100644
index 000000000000..e5e06b414ba0
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tests/package-name/Lib.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE CPP #-}
+module Lib (foo, libPackageKey) where
+
+foo :: Integer
+foo = 42
+
+libPackageKey :: String
+libPackageKey = CURRENT_PACKAGE_KEY
diff --git a/third_party/bazel/rules_haskell/tests/package-name/Main.hs b/third_party/bazel/rules_haskell/tests/package-name/Main.hs
new file mode 100644
index 000000000000..b1e73dcbf716
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tests/package-name/Main.hs
@@ -0,0 +1,33 @@
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE PackageImports #-}
+module Main (main) where
+
+import Control.Monad (when)
+
+-- Test the PackageImports extension.
+import "lib-a-Z" Lib
+
+-- Test macros that GHC creates automatically based on the package version.
+versionHighEnoughTest, versionTooLowTest :: Bool
+#if MIN_VERSION_lib_a_Z(1,2,3)
+versionHighEnoughTest = True
+#else
+versionHighEnoughTest = False
+#endif
+
+#if MIN_VERSION_lib_a_Z(1,2,4)
+versionTooLowTest = False
+#else
+versionTooLowTest = True
+#endif
+
+check :: (Show a, Eq a) => a -> a -> IO ()
+check x y = when (x /= y) $ error $ "Failed check: " ++ show (x, y)
+
+main :: IO ()
+main = do
+    check foo 42
+    check VERSION_lib_a_Z "1.2.3.4"
+    check libPackageKey "testsZSpackage-nameZSlib-a-ZZ"
+    check versionHighEnoughTest True
+    check versionTooLowTest True