Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CI #4

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,32 @@ jobs:
- ubuntu-latest
- macos-latest
compiler:
- ghc8107
- ghc902
- ghc924
- ghc946
- ghc928
- ghc948
- ghc965
- ghc982
dhall:
- false
- true
swagger:
- false
- true
swaggerWrapper:
- false
- true
largeRecords:
- false
- true
exclude:
- swagger: false
swaggerWrapper: true
- compiler: ghc965
largeRecords: true
- compiler: ghc982
largeRecords: true
- compiler: ghc902
os: macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3.5.3
Expand All @@ -27,5 +49,4 @@ jobs:
with:
name: awakesecurity
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix-build --attr proto3-suite --argstr compiler "${{ matrix.compiler }}" --arg enableDhall true --arg enableLargeRecords false
- run: nix-build --attr proto3-suite --argstr compiler "${{ matrix.compiler }}" --arg enableDhall true --arg enableLargeRecords true
- run: nix-build --attr proto3-suite --argstr compiler "${{ matrix.compiler }}" --arg enableDhall "${{ matrix.dhall }}" --arg enableSwagger "${{ matrix.swagger }}" --arg swaggerWrapperFormat "${{ matrix.swaggerWrapper }}" --arg enableLargeRecords "${{ matrix.largeRecords }}"
10 changes: 10 additions & 0 deletions src/Proto3/Suite/DhallPB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import Dhall (FromDhall (..), ToDhall (..))
import GHC.Float (double2Float, float2Double)
import Proto3.Suite.Types (Enumerated (..), Fixed (..))

#if !(MIN_VERSION_dhall(1,42,0))
import qualified Data.ByteString
import qualified Data.ByteString.Base64
import qualified Data.ByteString.Base64.Lazy
import qualified Data.ByteString.Lazy
import qualified Data.Text.Encoding
import qualified Data.Text.Lazy.Encoding
#endif
import qualified Dhall

#if !(MIN_VERSION_dhall(1,27,0))
Expand Down Expand Up @@ -63,6 +65,8 @@ instance Dhall.FromDhall a => Dhall.FromDhall (Enumerated a)

instance Dhall.FromDhall a => Dhall.FromDhall (Either Int32 a)

#if !(MIN_VERSION_dhall(1,42,0))

--------------------------------------------------------------------------------
-- Interpret the strict and lazy ByteString types
--
Expand All @@ -80,6 +84,8 @@ instance Dhall.FromDhall Data.ByteString.ByteString where
where
b64Decode = Data.ByteString.Base64.decodeLenient . Data.Text.Encoding.encodeUtf8

#endif

--------------------------------------------------------------------------------
-- Interpret integer scalar types

Expand Down Expand Up @@ -182,6 +188,8 @@ instance Dhall.ToDhall (Fixed Word64) where
instance Dhall.ToDhall Float where
injectWith = fmap (contramap float2Double) Dhall.injectWith

#if !(MIN_VERSION_dhall(1,42,0))

--------------------------------------------------------------------------------
-- Inject strict and lazy ByteStrings
--
Expand All @@ -205,6 +213,8 @@ instance Dhall.ToDhall Data.ByteString.ByteString where
-- because we Base64 encode the ByteString first
b64Encode = Data.Text.Encoding.decodeUtf8 . Data.ByteString.Base64.encode

#endif

#if !(MIN_VERSION_dhall(1,27,0))
--------------------------------------------------------------------------------
-- Inject maps
Expand Down
25 changes: 21 additions & 4 deletions tests/TestCodeGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ module TestCodeGen where
import ArbitraryGeneratedTestTypes ()
import Control.Applicative
import Control.Monad
#ifdef SWAGGER
import qualified Data.Aeson
#endif
import qualified Data.ByteString.Lazy as LBS
import Data.Proxy (Proxy(..))
import Data.String (IsString)
#ifdef SWAGGER
import Data.Swagger (ToSchema)
import qualified Data.Swagger
#endif
import qualified Data.Text as T
import Data.Typeable (Typeable, splitTyConApp,
tyConName, typeRep)
import Data.Typeable (Typeable, typeRep,
#ifdef SWAGGER
splitTyConApp, tyConName
#endif
)
import Google.Protobuf.Timestamp (Timestamp(..))
import Prelude hiding (FilePath)
import Proto3.Suite.Class (def)
Expand All @@ -39,19 +46,23 @@ import qualified Turtle
import qualified Turtle.Format as F
import qualified TestProto
import qualified TestProtoOneof
#ifdef SWAGGER
import qualified TestProtoWrappers
#endif

codeGenTests :: TestTree
codeGenTests = testGroup "Code generator unit tests"
[ jsonpbTests
, swaggerTests
, hasDefaultTests
, swaggerWrapperFormat
, pascalCaseMessageNames
, camelCaseMessageFieldNames
, don'tAlterEnumFieldNames
, knownTypeMessages
, pythonInteroperation
#ifdef SWAGGER
, swaggerTests
, swaggerWrapperFormat
#endif
]

pythonInteroperation :: TestTree
Expand All @@ -67,6 +78,7 @@ pythonInteroperation = testGroup "Python interoperation" $ do
direction <- [simpleEncodeDotProto, simpleDecodeDotProto]
pure @[] (direction recStyle isPrefixedArg tt format)

#ifdef SWAGGER
swaggerWrapperFormat :: TestTree
swaggerWrapperFormat = testGroup "Swagger Wrapper Format"
[ expectSchema @TestProtoWrappers.TestDoubleValue
Expand Down Expand Up @@ -114,6 +126,7 @@ swaggerWrapperFormat = testGroup "Swagger Wrapper Format"
#else
wf = False
#endif
#endif

knownTypeMessages :: TestTree
knownTypeMessages =
Expand Down Expand Up @@ -378,6 +391,7 @@ jsonpbTests = testGroup "JSONPB tests"
]
]

#ifdef SWAGGER
swaggerTests :: TestTree
swaggerTests = testGroup "Swagger tests"
[ schemaOf @TestProtoOneof.Something
Expand All @@ -390,6 +404,7 @@ swaggerTests = testGroup "Swagger tests"
"{\"enum\":[\"DUMMY0\",\"DUMMY1\"],\"type\":\"string\"}"

]
#endif

hasDefaultTests :: TestTree
hasDefaultTests = testGroup "Generic HasDefault"
Expand Down Expand Up @@ -456,6 +471,7 @@ decodesAs bs x = testProperty (testName "") (eitherDecode bs === Right x)
showString " == Right " .
showsPrec 11 x

#ifdef SWAGGER
schemaOf ::
forall a .
(ToSchema a, Eq a, Show a, Typeable a) =>
Expand All @@ -470,3 +486,4 @@ schemaOf bs = testProperty (testName "") (lbsSchemaOf @a === bs)

lbsSchemaOf :: forall a . ToSchema a => LBS.ByteString
lbsSchemaOf = Data.Aeson.encode (Data.Swagger.toSchema (Proxy @a))
#endif