Skip to content

Commit eeaddf0

Browse files
SwordlashMikolaj
authored andcommitted
Add JsOptions test, use 3.14 as min required cabal version
1 parent 27fec1c commit eeaddf0

File tree

11 files changed

+85
-0
lines changed

11 files changed

+85
-0
lines changed

Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs

+1
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ buildInfoFieldGrammar =
622622
<*> monoidalFieldAla "cxx-options" (alaList' NoCommaFSep Token') L.cxxOptions
623623
^^^ availableSince CabalSpecV2_2 []
624624
<*> monoidalFieldAla "js-options" (alaList' NoCommaFSep Token') L.jsOptions
625+
^^^ availableSince CabalSpecV3_14 []
625626
<*> monoidalFieldAla "ld-options" (alaList' NoCommaFSep Token') L.ldOptions
626627
<*> monoidalFieldAla "hsc2hs-options" (alaList' NoCommaFSep Token') L.hsc2hsOptions
627628
^^^ availableSince CabalSpecV3_6 []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
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
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
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cabal-version: 3.14
2+
name: jsoptions
3+
version: 0
4+
build-type: Simple
5+
6+
library
7+
default-language: Haskell2010
8+
exposed-modules: Lib
9+
build-depends: base
10+
11+
if impl(javascript)
12+
js-sources: jsbits/lib.js
13+
js-options: -optJSP-DPRINT_DEF
14+
15+
executable demo
16+
default-language: Haskell2010
17+
main-is: Main.hs
18+
hs-source-dirs: demo
19+
build-depends: base, jsoptions
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+
- jsoptions-exe-0 (lib) (first run)
8+
- jsoptions-exe-0 (exe:demo) (first run)
9+
Configuring library for jsoptions-exe-0...
10+
Preprocessing library for jsoptions-exe-0...
11+
Building library for jsoptions-exe-0...
12+
Configuring executable 'demo' for jsoptions-exe-0...
13+
Preprocessing executable 'demo' for jsoptions-exe-0...
14+
Building executable 'demo' for jsoptions-exe-0...
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-options` does not raise issues
7+
res <- cabal' "v2-run" ["demo"]
8+
assertOutputContains "foo_fallback" res
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 "foo_fallback"
9+
#endif

doc/buildinfo-fields-reference.rst

+8
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ cxx-options
271271
.. math::
272272
{\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}]^c}}^+_{} \right\}}^\ast_{\bullet}
273273
274+
js-options
275+
* Monoidal field
276+
* Available since ``cabal-version: 3.14``.
277+
* Documentation of :pkg-field:`library:js-options`
278+
279+
.. math::
280+
{\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}]^c}}^+_{} \right\}}^\ast_{\bullet}
281+
274282
cxx-sources
275283
* Monoidal field
276284
* Available since ``cabal-version: 2.2``.

editors/vim/syntax/cabal.vim

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ syn keyword cabalFieldName contained
6767
\ copyright
6868
\ cpp-options
6969
\ cxx-options
70+
\ js-options
7071
\ cxx-sources
7172
\ data-dir
7273
\ data-files

0 commit comments

Comments
 (0)