Skip to content

Commit e883447

Browse files
zlonastSwordlash
andcommitted
Add JSPOptions test, use 3.14 as min required cabal version
Co-authored-by: Mateusz Goslinowski <mateusz.goslinowski@gmail.com>
1 parent df09931 commit e883447

File tree

11 files changed

+98
-0
lines changed

11 files changed

+98
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# cabal check
2+
The following errors are likely to affect your build negatively:
3+
Error: [jsp-options] 'jsp-options: -Q' is not a portable C-preprocessor flag.
4+
Error: Hackage would reject this package.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test.Cabal.Prelude
2+
3+
-- `jsp-options`, do not use use non portable flags.
4+
main = cabalTest $
5+
fails $ cabal "check" []
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cabal-version: 3.0
2+
name: pkg
3+
synopsis: synopsis
4+
description: description
5+
version: 0
6+
category: example
7+
maintainer: none@example.com
8+
license: GPL-3.0-or-later
9+
10+
library
11+
exposed-modules: Module
12+
default-language: Haskell2010
13+
if arch(JavaScript)
14+
jsp-options: -Q
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import Lib
4+
5+
main :: IO ()
6+
main = foo
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Test.Cabal.Prelude
2+
3+
main = do
4+
skipUnlessJavaScript
5+
skipIfWindows ""
6+
setupAndCabalTest $ do
7+
skipUnlessGhcVersion ">= 9.12"
8+
res <- cabal' "v2-run" ["demo"]
9+
assertOutputContains "Hello definition!" res
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//#OPTIONS: CPP
2+
3+
function foo() {
4+
#ifdef PRINT_DEF
5+
console.log("Hello definition!");
6+
#else
7+
console.log("Hello!");
8+
#endif
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cabal-version: 3.0
2+
name: jsjspoptions
3+
version: 0
4+
build-type: Simple
5+
6+
library
7+
default-language: Haskell2010
8+
js-sources: jsbits/lib.js
9+
if arch(JavaScript)
10+
jsp-options: -DPRINT_DEF
11+
hs-source-dirs: src
12+
exposed-modules: Lib
13+
build-depends: base
14+
15+
executable demo
16+
default-language: Haskell2010
17+
main-is: Main.hs
18+
hs-source-dirs: demo
19+
build-depends: base, jsjspoptions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# cabal v2-run
2+
Configuration is affected by the following files:
3+
- cabal.project
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following will be built:
7+
- jsjspoptions-0 (lib) (first run)
8+
- jsjspoptions-0 (exe:demo) (first run)
9+
Configuring library for jsjspoptions-0...
10+
Preprocessing library for jsjspoptions-0...
11+
Building library for jsjspoptions-0...
12+
Configuring executable 'demo' for jsjspoptions-0...
13+
Preprocessing executable 'demo' for jsjspoptions-0...
14+
Building executable 'demo' for jsjspoptions-0...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Test.Cabal.Prelude
2+
3+
main = do
4+
skipIfJavaScript
5+
cabalTest $ do
6+
-- Ensure the field `js-sources` does not raise issues
7+
res <- cabal' "v2-run" ["demo"]
8+
assertOutputContains "Not JS foo" res
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{-# LANGUAGE CPP #-}
2+
module Lib where
3+
4+
#if defined(javascript_HOST_ARCH)
5+
foreign import javascript foo :: IO ()
6+
#else
7+
foo :: IO ()
8+
foo = putStrLn "Not JS foo"
9+
#endif

0 commit comments

Comments
 (0)