Skip to content

Commit a51b462

Browse files
committed
Add test for embedFile from the file-embed package
1 parent 37f2b4b commit a51b462

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed

test/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ let
221221
cabal-project-nix-path = callTest ./cabal-project-nix-path {};
222222
plugin = callTest ./plugin {};
223223
supported-languages = callTest ./supported-langauges {};
224+
embed-file = callTest ./embed-file {};
224225
unit = unitTests;
225226
};
226227

test/embed-file/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for embed-file
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.

test/embed-file/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2024 Hamish Mackenzie
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included
12+
in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

test/embed-file/app/Main.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
module Main where
3+
4+
import Control.Monad (unless)
5+
import qualified Data.Text as T (pack)
6+
import Data.Text.Encoding (encodeUtf8)
7+
import System.Exit (exitFailure)
8+
import Data.FileEmbed (embedFile, makeRelativeToProject)
9+
10+
main :: IO ()
11+
main =
12+
unless ($(makeRelativeToProject "app/test.txt" >>= embedFile) == encodeUtf8 (T.pack "Hello World")) exitFailure

test/embed-file/app/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World

test/embed-file/default.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Test that embedFile function for the file-embed package works
2+
{ stdenv, lib, project', haskellLib, recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages, buildPackages }:
3+
4+
with lib;
5+
6+
let
7+
project = project' {
8+
inherit compiler-nix-name evalPackages;
9+
src = testSrc "embed-file";
10+
# cabalProjectLocal = builtins.readFile ../cabal.project.local;
11+
};
12+
13+
packages = project.hsPkgs;
14+
15+
in recurseIntoAttrs rec {
16+
meta.disabled = stdenv.hostPlatform.isGhcjs;
17+
18+
ifdInputs = {
19+
inherit (project) plan-nix;
20+
};
21+
22+
build = packages.embed-file.components.exes.embed-file;
23+
check = haskellLib.check build;
24+
# build-profiled = packages.embed-file.components.exes.embed-file.profiled;
25+
# check-profiled = haskellLib.check build-profiled;
26+
}

test/embed-file/embed-file.cabal

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cabal-version: 3.4
2+
name: embed-file
3+
version: 0.1.0.0
4+
-- synopsis:
5+
-- description:
6+
license: MIT
7+
license-file: LICENSE
8+
author: Hamish Mackenzie
9+
maintainer: [email protected]
10+
-- copyright:
11+
category: Testing
12+
build-type: Simple
13+
extra-doc-files: CHANGELOG.md
14+
-- extra-source-files:
15+
16+
common warnings
17+
ghc-options: -Wall
18+
19+
executable embed-file
20+
import: warnings
21+
main-is: Main.hs
22+
-- other-modules:
23+
-- other-extensions:
24+
build-depends: base, file-embed, text
25+
hs-source-dirs: app
26+
default-language: Haskell2010

0 commit comments

Comments
 (0)