Skip to content

Commit

Permalink
Add JsOptions test, use 3.14 as min required cabal version
Browse files Browse the repository at this point in the history
  • Loading branch information
Swordlash committed Jan 12, 2025
1 parent eca0d2e commit 4f2fbc5
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ buildInfoFieldGrammar =
<*> monoidalFieldAla "cxx-options" (alaList' NoCommaFSep Token') L.cxxOptions
^^^ availableSince CabalSpecV2_2 []
<*> monoidalFieldAla "js-options" (alaList' NoCommaFSep Token') L.jsOptions
^^^ availableSince CabalSpecV3_14 []
<*> monoidalFieldAla "ld-options" (alaList' NoCommaFSep Token') L.ldOptions
<*> monoidalFieldAla "hsc2hs-options" (alaList' NoCommaFSep Token') L.hsc2hsOptions
^^^ availableSince CabalSpecV3_6 []
Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/JS/JsOptions/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/JS/JsOptions/demo/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = foo
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/JS/JsOptions/js.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude

main = do
skipUnlessJavaScript
skipIfWindows ""
setupAndCabalTest $ do
skipUnlessGhcVersion ">= 9.12"
res <- cabal' "v2-run" ["demo"]
assertOutputContains "Hello definition!" res
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/JS/JsOptions/jsbits/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//#OPTIONS: CPP

function foo() {
#ifdef PRINT_DEF
console.log("Hello definition!");
#else
console.log("Hello!");
#endif
}
19 changes: 19 additions & 0 deletions cabal-testsuite/PackageTests/JS/JsOptions/jsoptions.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cabal-version: 3.14
name: jsoptions
version: 0
build-type: Simple

library
default-language: Haskell2010
exposed-modules: Lib
build-depends: base

if impl(javascript)
js-sources: jsbits/lib.js
js-options: -optJSP-DPRINT_DEF

executable demo
default-language: Haskell2010
main-is: Main.hs
hs-source-dirs: demo
build-depends: base, jsoptions
14 changes: 14 additions & 0 deletions cabal-testsuite/PackageTests/JS/JsOptions/other-arch.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# cabal v2-run
Configuration is affected by the following files:
- cabal.project
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- jsoptions-exe-0 (lib) (first run)
- jsoptions-exe-0 (exe:demo) (first run)
Configuring library for jsoptions-exe-0...
Preprocessing library for jsoptions-exe-0...
Building library for jsoptions-exe-0...
Configuring executable 'demo' for jsoptions-exe-0...
Preprocessing executable 'demo' for jsoptions-exe-0...
Building executable 'demo' for jsoptions-exe-0...
8 changes: 8 additions & 0 deletions cabal-testsuite/PackageTests/JS/JsOptions/other-arch.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Test.Cabal.Prelude

main = do
skipIfJavaScript
cabalTest $ do
-- Ensure the field `js-options` does not raise issues
res <- cabal' "v2-run" ["demo"]
assertOutputContains "foo_fallback" res
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/JS/JsOptions/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{-# LANGUAGE CPP #-}
module Lib where

#if defined(javascript_HOST_ARCH)
foreign import javascript foo :: IO ()
#else
foo :: IO ()
foo = putStrLn "foo_fallback"
#endif
8 changes: 8 additions & 0 deletions doc/buildinfo-fields-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ cxx-options
.. math::
{\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}]^c}}^+_{} \right\}}^\ast_{\bullet}
js-options
* Monoidal field
* Available since ``cabal-version: 3.14``.
* Documentation of :pkg-field:`library:js-options`

.. math::
{\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}]^c}}^+_{} \right\}}^\ast_{\bullet}
cxx-sources
* Monoidal field
* Available since ``cabal-version: 2.2``.
Expand Down
1 change: 1 addition & 0 deletions editors/vim/syntax/cabal.vim
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ syn keyword cabalFieldName contained
\ copyright
\ cpp-options
\ cxx-options
\ js-options
\ cxx-sources
\ data-dir
\ data-files
Expand Down

0 comments on commit 4f2fbc5

Please sign in to comment.