From 67624e06ef1c12af2ef82eeb999a46d5c49f991e Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Wed, 27 Aug 2025 11:17:20 +0200 Subject: [PATCH 1/2] quickcheck-monoids: compatibility with QuickCheck-2.16 --- cardano-diffusion/cardano-diffusion.cabal | 6 +- ...093532_georgy.lukyanov_10_7_integration.md | 17 ++ .../Test/Cardano/Network/Diffusion/Testnet.hs | 4 + .../lib/Test/Cardano/Network/PeerSelection.hs | 3 + ...093734_georgy.lukyanov_10_7_integration.md | 17 ++ .../Test/Ouroboros/Network/Server/Sim.hs | 6 + .../Network/ConnectionManager/Timeouts.hs | 6 + .../Network/ConnectionManager/Utils.hs | 6 + .../Network/InboundGovernor/Utils.hs | 6 + ouroboros-network/ouroboros-network.cabal | 23 ++- .../Network/Protocol/LocalStateQuery/Test.hs | 9 +- .../Network/PeerSelection/PeerMetric.hs | 4 + .../Ouroboros/Network/TxSubmission/AppV2.hs | 5 + .../Ouroboros/Network/TxSubmission/TxLogic.hs | 6 + quickcheck-monoids/CHANGELOG.md | 20 ++ quickcheck-monoids/LICENSE | 177 ++++++++++++++++++ quickcheck-monoids/NOTICE | 14 ++ quickcheck-monoids/quickcheck-monoids.cabal | 40 ++++ .../src/Test/QuickCheck/Monoids.hs | 85 +++++++++ 19 files changed, 444 insertions(+), 10 deletions(-) create mode 100644 cardano-diffusion/changelog.d/20260114_093532_georgy.lukyanov_10_7_integration.md create mode 100644 ouroboros-network/changelog.d/20260114_093734_georgy.lukyanov_10_7_integration.md create mode 100644 quickcheck-monoids/CHANGELOG.md create mode 100644 quickcheck-monoids/LICENSE create mode 100644 quickcheck-monoids/NOTICE create mode 100644 quickcheck-monoids/quickcheck-monoids.cabal create mode 100644 quickcheck-monoids/src/Test/QuickCheck/Monoids.hs diff --git a/cardano-diffusion/cardano-diffusion.cabal b/cardano-diffusion/cardano-diffusion.cabal index e081b869258..9a79bf88260 100644 --- a/cardano-diffusion/cardano-diffusion.cabal +++ b/cardano-diffusion/cardano-diffusion.cabal @@ -430,10 +430,13 @@ test-suite protocols-bench library cardano-diffusion-tests-lib import: ghc-options-tests + mixins: + QuickCheck hiding (Test.QuickCheck.Monoids) + visibility: public hs-source-dirs: tests/lib build-depends: - QuickCheck >=2.16, + QuickCheck, aeson, base >=4.14 && <4.23, bytestring, @@ -453,6 +456,7 @@ library cardano-diffusion-tests-lib pipes, pretty-simple, psqueues, + quickcheck-monoids, random, serialise, tasty, diff --git a/cardano-diffusion/changelog.d/20260114_093532_georgy.lukyanov_10_7_integration.md b/cardano-diffusion/changelog.d/20260114_093532_georgy.lukyanov_10_7_integration.md new file mode 100644 index 00000000000..876f23d02bd --- /dev/null +++ b/cardano-diffusion/changelog.d/20260114_093532_georgy.lukyanov_10_7_integration.md @@ -0,0 +1,17 @@ + + + + +### Non-Breaking + +- Compatibility with both `QuickCheck` < 2.15 and >= 2.16 diff --git a/cardano-diffusion/tests/lib/Test/Cardano/Network/Diffusion/Testnet.hs b/cardano-diffusion/tests/lib/Test/Cardano/Network/Diffusion/Testnet.hs index 24c9df589f5..4f994fd51b6 100644 --- a/cardano-diffusion/tests/lib/Test/Cardano/Network/Diffusion/Testnet.hs +++ b/cardano-diffusion/tests/lib/Test/Cardano/Network/Diffusion/Testnet.hs @@ -3,6 +3,7 @@ {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE PackageImports #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} @@ -107,6 +108,9 @@ import Test.Ouroboros.Network.TxSubmission.Types (Tx (..), TxId) import Test.Ouroboros.Network.Utils hiding (SmallDelay, debugTracer) import Test.QuickCheck +#if !MIN_VERSION_QuickCheck(2,16,0) +import "quickcheck-monoids" Test.QuickCheck.Monoids +#endif import Test.Tasty import Test.Tasty.QuickCheck (testProperty) diff --git a/cardano-diffusion/tests/lib/Test/Cardano/Network/PeerSelection.hs b/cardano-diffusion/tests/lib/Test/Cardano/Network/PeerSelection.hs index a88e5336ef7..7cd031e4336 100644 --- a/cardano-diffusion/tests/lib/Test/Cardano/Network/PeerSelection.hs +++ b/cardano-diffusion/tests/lib/Test/Cardano/Network/PeerSelection.hs @@ -88,6 +88,9 @@ import Cardano.Network.PeerSelection.Governor.Types qualified as Cardano.ExtraSi import Cardano.Network.PeerSelection.State.LocalRootPeers qualified as LocalRootPeers import Ouroboros.Network.BlockFetch (FetchMode (..), PraosFetchMode (..)) import Test.QuickCheck +#if !MIN_VERSION_QuickCheck(2,16,0) +import "quickcheck-monoids" Test.QuickCheck.Monoids +#endif import Test.Tasty import Test.Tasty.QuickCheck import Text.Pretty.Simple diff --git a/ouroboros-network/changelog.d/20260114_093734_georgy.lukyanov_10_7_integration.md b/ouroboros-network/changelog.d/20260114_093734_georgy.lukyanov_10_7_integration.md new file mode 100644 index 00000000000..876f23d02bd --- /dev/null +++ b/ouroboros-network/changelog.d/20260114_093734_georgy.lukyanov_10_7_integration.md @@ -0,0 +1,17 @@ + + + + +### Non-Breaking + +- Compatibility with both `QuickCheck` < 2.15 and >= 2.16 diff --git a/ouroboros-network/framework/sim-tests/Test/Ouroboros/Network/Server/Sim.hs b/ouroboros-network/framework/sim-tests/Test/Ouroboros/Network/Server/Sim.hs index a6bd00592ec..a8ddfbe84c4 100644 --- a/ouroboros-network/framework/sim-tests/Test/Ouroboros/Network/Server/Sim.hs +++ b/ouroboros-network/framework/sim-tests/Test/Ouroboros/Network/Server/Sim.hs @@ -15,6 +15,9 @@ {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} +#if !MIN_VERSION_QuickCheck(2,16,0) +{-# LANGUAGE PackageImports #-} +#endif -- for 'debugTracer' {-# OPTIONS_GHC -Wno-redundant-constraints #-} @@ -64,6 +67,9 @@ import System.Random (StdGen, mkStdGen, split) import Text.Printf import Test.QuickCheck +#if !MIN_VERSION_QuickCheck(2,16,0) +import "quickcheck-monoids" Test.QuickCheck.Monoids +#endif import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck diff --git a/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/ConnectionManager/Timeouts.hs b/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/ConnectionManager/Timeouts.hs index 22d07e6a33f..ec511a8ab53 100644 --- a/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/ConnectionManager/Timeouts.hs +++ b/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/ConnectionManager/Timeouts.hs @@ -1,5 +1,8 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE PackageImports #-} + +{-# LANGUAGE CPP #-} module Test.Ouroboros.Network.ConnectionManager.Timeouts ( verifyAllTimeouts @@ -39,6 +42,9 @@ import Data.Monoid (Sum (Sum)) import Text.Printf (printf) import Test.QuickCheck +#if !MIN_VERSION_QuickCheck(2,16,0) +import "quickcheck-monoids" Test.QuickCheck.Monoids +#endif import Ouroboros.Network.ConnectionHandler (ConnectionHandlerTrace) import Ouroboros.Network.ConnectionManager.Core qualified as CM diff --git a/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/ConnectionManager/Utils.hs b/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/ConnectionManager/Utils.hs index 573ce87ba89..ebe7f4860d8 100644 --- a/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/ConnectionManager/Utils.hs +++ b/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/ConnectionManager/Utils.hs @@ -1,6 +1,9 @@ {-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE PackageImports #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE CPP #-} + module Test.Ouroboros.Network.ConnectionManager.Utils where import Prelude hiding (read) @@ -10,6 +13,9 @@ import Ouroboros.Network.ConnectionManager.Core as CM import Ouroboros.Network.ConnectionManager.Types import Test.QuickCheck +#if !MIN_VERSION_QuickCheck(2,16,0) +import "quickcheck-monoids" Test.QuickCheck.Monoids +#endif verifyAbstractTransition :: AbstractTransition diff --git a/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/InboundGovernor/Utils.hs b/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/InboundGovernor/Utils.hs index 171674153d2..d9ad578bf19 100644 --- a/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/InboundGovernor/Utils.hs +++ b/ouroboros-network/framework/tests-lib/Test/Ouroboros/Network/InboundGovernor/Utils.hs @@ -1,11 +1,17 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE PackageImports #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE CPP #-} + module Test.Ouroboros.Network.InboundGovernor.Utils where import Test.QuickCheck +#if !MIN_VERSION_QuickCheck(2,16,0) +import "quickcheck-monoids" Test.QuickCheck.Monoids +#endif import Ouroboros.Network.ConnectionManager.Types import Ouroboros.Network.InboundGovernor (RemoteSt (..)) diff --git a/ouroboros-network/ouroboros-network.cabal b/ouroboros-network/ouroboros-network.cabal index f7831a0a0ff..b9d785d4b4f 100644 --- a/ouroboros-network/ouroboros-network.cabal +++ b/ouroboros-network/ouroboros-network.cabal @@ -469,6 +469,9 @@ test-suite tests-lib-tests library framework-tests-lib import: ghc-options + mixins: + QuickCheck hiding (Test.QuickCheck.Monoids) + visibility: public hs-source-dirs: framework/tests-lib exposed-modules: @@ -480,7 +483,7 @@ library framework-tests-lib Test.Ouroboros.Network.RawBearer.Utils build-depends: - QuickCheck >=2.16, + QuickCheck, base >=4.14 && <4.23, bytestring, cborg, @@ -491,12 +494,16 @@ library framework-tests-lib io-sim, network-mux, ouroboros-network:{api, framework, tests-lib}, + quickcheck-monoids, random, serialise, typed-protocols:{typed-protocols, examples}, test-suite framework-sim-tests import: ghc-options + mixins: + QuickCheck hiding (Test.QuickCheck.Monoids) + type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: framework/sim-tests @@ -508,7 +515,7 @@ test-suite framework-sim-tests Test.Simulation.Network.Snocket build-depends: - QuickCheck >=2.16, + QuickCheck, base >=4.14 && <4.23, bytestring, cborg, @@ -522,6 +529,7 @@ test-suite framework-sim-tests pretty-simple, psqueues, quickcheck-instances, + quickcheck-monoids, quiet, random, serialise, @@ -550,7 +558,7 @@ test-suite framework-io-tests Test.Ouroboros.Network.Socket build-depends: - QuickCheck >=2.16, + QuickCheck, base >=4.14 && <4.23, bytestring, contra-tracer, @@ -818,10 +826,13 @@ test-suite protocols-tests -- Simulation Test Library library ouroboros-network-tests-lib import: ghc-options-tests + mixins: + QuickCheck hiding (Test.QuickCheck.Monoids) + visibility: public hs-source-dirs: tests/lib build-depends: - QuickCheck >=2.16, + QuickCheck, aeson, array, base >=4.14 && <4.23, @@ -844,6 +855,7 @@ library ouroboros-network-tests-lib nothunks, ouroboros-network:{ouroboros-network, api, api-tests-lib, framework, framework-tests-lib, protocols, protocols-tests-lib, tests-lib}, pretty-simple, + quickcheck-monoids, random, serialise, splitmix, @@ -852,6 +864,7 @@ library ouroboros-network-tests-lib tasty-quickcheck, text, time >=1.9.1 && <1.16, + transformers-except, typed-protocols, exposed-modules: @@ -914,7 +927,7 @@ test-suite ouroboros-network-io-tests Test.Ouroboros.Network.Socket build-depends: - QuickCheck >=2.16, + QuickCheck, base >=4.14 && <4.23, bytestring, cborg, diff --git a/ouroboros-network/protocols/tests-lib/Ouroboros/Network/Protocol/LocalStateQuery/Test.hs b/ouroboros-network/protocols/tests-lib/Ouroboros/Network/Protocol/LocalStateQuery/Test.hs index 6bb7bba12a0..7d5c3f207cd 100644 --- a/ouroboros-network/protocols/tests-lib/Ouroboros/Network/Protocol/LocalStateQuery/Test.hs +++ b/ouroboros-network/protocols/tests-lib/Ouroboros/Network/Protocol/LocalStateQuery/Test.hs @@ -46,7 +46,8 @@ import Ouroboros.Network.Mock.ChainGenerators () import Ouroboros.Network.Mock.ConcreteBlock (Block) import Ouroboros.Network.Protocol.LocalStateQuery.Client -import Ouroboros.Network.Protocol.LocalStateQuery.Codec +import Ouroboros.Network.Protocol.LocalStateQuery.Codec hiding (Some (..)) +import Ouroboros.Network.Protocol.LocalStateQuery.Codec qualified as LocalStateQuery import Ouroboros.Network.Protocol.LocalStateQuery.Direct import Ouroboros.Network.Protocol.LocalStateQuery.Examples import Ouroboros.Network.Protocol.LocalStateQuery.Server @@ -54,7 +55,7 @@ import Ouroboros.Network.Protocol.LocalStateQuery.Type import Test.Ouroboros.Network.Protocol.Utils -import Test.QuickCheck as QC hiding (Result, Some (Some)) +import Test.QuickCheck as QC hiding (Result) import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) import Text.Show.Functions () @@ -386,10 +387,10 @@ codec = encodeQuery :: Query result -> CBOR.Encoding encodeQuery GetTheLedgerState = Serialise.encode () - decodeQuery :: forall s . CBOR.Decoder s (Some Query) + decodeQuery :: forall s . CBOR.Decoder s (LocalStateQuery.Some Query) decodeQuery = do () <- Serialise.decode - return $ Some GetTheLedgerState + return $ LocalStateQuery.Some GetTheLedgerState encodeResult :: Query result -> result -> CBOR.Encoding encodeResult GetTheLedgerState = Serialise.encode diff --git a/ouroboros-network/tests/lib/Test/Ouroboros/Network/PeerSelection/PeerMetric.hs b/ouroboros-network/tests/lib/Test/Ouroboros/Network/PeerSelection/PeerMetric.hs index 297b9b02074..3e5fe31139f 100644 --- a/ouroboros-network/tests/lib/Test/Ouroboros/Network/PeerSelection/PeerMetric.hs +++ b/ouroboros-network/tests/lib/Test/Ouroboros/Network/PeerSelection/PeerMetric.hs @@ -6,6 +6,7 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NumericUnderscores #-} +{-# LANGUAGE PackageImports #-} {-# LANGUAGE ScopedTypeVariables #-} #if __GLASGOW_HASKELL__ >= 908 @@ -49,6 +50,9 @@ import NoThunks.Class import Test.Ouroboros.Network.Data.Script import Test.QuickCheck +#if !MIN_VERSION_QuickCheck(2,16,0) +import "quickcheck-monoids" Test.QuickCheck.Monoids +#endif import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) diff --git a/ouroboros-network/tests/lib/Test/Ouroboros/Network/TxSubmission/AppV2.hs b/ouroboros-network/tests/lib/Test/Ouroboros/Network/TxSubmission/AppV2.hs index c12e9ca59dd..0c704ca9481 100644 --- a/ouroboros-network/tests/lib/Test/Ouroboros/Network/TxSubmission/AppV2.hs +++ b/ouroboros-network/tests/lib/Test/Ouroboros/Network/TxSubmission/AppV2.hs @@ -1,9 +1,11 @@ {-# LANGUAGE BlockArguments #-} +{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE PackageImports #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} @@ -63,6 +65,9 @@ import Test.Ouroboros.Network.TxSubmission.Types import Test.Ouroboros.Network.Utils hiding (debugTracer) import Test.QuickCheck +#if !MIN_VERSION_QuickCheck(2,16,0) +import "quickcheck-monoids" Test.QuickCheck.Monoids +#endif import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) diff --git a/ouroboros-network/tests/lib/Test/Ouroboros/Network/TxSubmission/TxLogic.hs b/ouroboros-network/tests/lib/Test/Ouroboros/Network/TxSubmission/TxLogic.hs index f15d6b06749..4b8381f8c74 100644 --- a/ouroboros-network/tests/lib/Test/Ouroboros/Network/TxSubmission/TxLogic.hs +++ b/ouroboros-network/tests/lib/Test/Ouroboros/Network/TxSubmission/TxLogic.hs @@ -7,10 +7,13 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE PackageImports #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TupleSections #-} +{-# LANGUAGE CPP #-} + {-# OPTIONS_GHC -Wno-orphans #-} module Test.Ouroboros.Network.TxSubmission.TxLogic @@ -60,6 +63,9 @@ import Test.QuickCheck import Test.QuickCheck.Function (apply) import Test.QuickCheck.Gen (Gen (..)) import Test.QuickCheck.Random (QCGen (..)) +#if !MIN_VERSION_QuickCheck(2,16,0) +import "quickcheck-monoids" Test.QuickCheck.Monoids +#endif import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) import Text.Pretty.Simple diff --git a/quickcheck-monoids/CHANGELOG.md b/quickcheck-monoids/CHANGELOG.md new file mode 100644 index 00000000000..faa779ee3aa --- /dev/null +++ b/quickcheck-monoids/CHANGELOG.md @@ -0,0 +1,20 @@ +# Revision history for quickcheck-monoids + +## 0.1.0.3 -- 2025-08-27 + +* Somewhat compatible with `QuickCheck-2.16`: `QuickCheck` is also defining + `Test.QuickCheck.Monoids` module. + +## 0.1.0.2 -- 2025-06-28 + +* Package is deprecated, use `QuickCheck >= 2.16` which provides `Every` and + `Some` monoids. + +## 0.1.0.1 -- 2024-08-07 + +* Make it build with ghc-9.10 + * fix base upper bound + +## 0.1.0.0 -- 2024-06-07 + +* First version. Released on an unsuspecting world. diff --git a/quickcheck-monoids/LICENSE b/quickcheck-monoids/LICENSE new file mode 100644 index 00000000000..f433b1a53f5 --- /dev/null +++ b/quickcheck-monoids/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/quickcheck-monoids/NOTICE b/quickcheck-monoids/NOTICE new file mode 100644 index 00000000000..3efdc24424e --- /dev/null +++ b/quickcheck-monoids/NOTICE @@ -0,0 +1,14 @@ +Copyright 2019-2023 Input Output Global Inc (IOG), 2023-2025 Intersect + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/quickcheck-monoids/quickcheck-monoids.cabal b/quickcheck-monoids/quickcheck-monoids.cabal new file mode 100644 index 00000000000..8b91498b4fa --- /dev/null +++ b/quickcheck-monoids/quickcheck-monoids.cabal @@ -0,0 +1,40 @@ +cabal-version: 3.0 +name: quickcheck-monoids +version: 0.1.0.3 +synopsis: QuickCheck monoids +description: All and Any monoids for `Testable` instances based on `.&&.` and `.||.`. +license: Apache-2.0 +license-files: + LICENSE + NOTICE + +author: Marcin Szamotulski +maintainer: coot@coot.me +category: Testing +copyright: 2024 Input Output Global Inc (IOG) +build-type: Simple +extra-doc-files: CHANGELOG.md +extra-source-files: README.md + +common warnings + ghc-options: -Wall + +library + import: warnings + exposed-modules: Test.QuickCheck.Monoids + build-depends: + QuickCheck, + base <4.22, + + hs-source-dirs: src + default-language: Haskell2010 + ghc-options: + -Wall + -Wno-unticked-promoted-constructors + -Wcompat + -Wincomplete-uni-patterns + -Wincomplete-record-updates + -Wpartial-fields + -Widentities + -Wredundant-constraints + -Wunused-packages diff --git a/quickcheck-monoids/src/Test/QuickCheck/Monoids.hs b/quickcheck-monoids/src/Test/QuickCheck/Monoids.hs new file mode 100644 index 00000000000..fb6abf8b467 --- /dev/null +++ b/quickcheck-monoids/src/Test/QuickCheck/Monoids.hs @@ -0,0 +1,85 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE ExistentialQuantification #-} +{-# LANGUAGE ExplicitNamespaces #-} +{-# LANGUAGE PackageImports #-} +{-# LANGUAGE PatternSynonyms #-} + +-- | Monoids using `.&&.` and `.||.`. +-- +-- They satisfy monoid laws with respect to the `isSuccess` unless one is using +-- `checkCoverage` (see test for a counterexample). +-- +module Test.QuickCheck.Monoids +#if !MIN_VERSION_QuickCheck(2,16,0) + ( type Every + , All(Every, getEvery, ..) + , type Some + , Any(Some, getSome, ..) +#else + ( All (..) + , Any (..) + , Every (..) + , Some (..) +#endif + ) where + +import Data.List.NonEmpty as NonEmpty +import Data.Semigroup (Semigroup (..)) +import Test.QuickCheck + +-- | Conjunction monoid build with `.&&.`. +-- +-- Use `property @All` as an accessor which doesn't leak +-- existential variables. +-- +data All = forall p. Testable p => All { getAll :: p } + +#if !MIN_VERSION_QuickCheck(2,16,0) +type Every = All + +pattern Every :: () + => Testable p + => p + -> All +pattern Every { getEvery } = All getEvery +#endif + +instance Testable All where + property (All p) = property p + +instance Semigroup All where + All p <> All p' = All (p .&&. p') + sconcat = All . conjoin . NonEmpty.toList + +instance Monoid All where + mempty = All True + mconcat = All . conjoin + + +-- | Disjunction monoid build with `.||.`. +-- +-- Use `property @Any` as an accessor which doesn't leak +-- existential variables. +-- +data Any = forall p. Testable p => Any { getAny :: p } + +#if !MIN_VERSION_QuickCheck(2,16,0) +type Some = Any + +pattern Some :: () + => Testable p + => p + -> Any +pattern Some { getSome } = Any getSome +#endif + +instance Testable Any where + property (Any p) = property p + +instance Semigroup Any where + Any p <> Any p' = Any (p .||. p') + sconcat = Any . disjoin . NonEmpty.toList + +instance Monoid Any where + mempty = Any False + mconcat = Any . disjoin From 2b1777f1e9dd41a8dab819d3c407bf6164ebd1c7 Mon Sep 17 00:00:00 2001 From: Georgy Lukyanov Date: Mon, 12 Jan 2026 14:58:22 +0100 Subject: [PATCH 2/2] Don't report unused packages in tests For not, '-Wno-redundant-constraints' is needed in testing libraries to prevent false-positives that lead to build errors with `-Werror`. See https://gitlab.haskell.org/ghc/ghc/-/issues/24173 for details. --- cardano-diffusion/cardano-diffusion.cabal | 9 ++++++++- ouroboros-network/ouroboros-network.cabal | 21 ++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/cardano-diffusion/cardano-diffusion.cabal b/cardano-diffusion/cardano-diffusion.cabal index 9a79bf88260..5c91485fd4f 100644 --- a/cardano-diffusion/cardano-diffusion.cabal +++ b/cardano-diffusion/cardano-diffusion.cabal @@ -47,9 +47,16 @@ common ghc-options -- in tests librararies redundant constraints are sometimes useful (e.g. -- by default truned off debug tracing might require extra constraints like -- `Show` or `MonadSay`). +-- +-- TODO: '-Wno-redundant-constraints' remove when we support +-- `quickcheck-monoids`. For now, it is needed to prevent +-- false-positives that lead to build errors with `-Werror`. +-- See https://gitlab.haskell.org/ghc/ghc/-/issues/24173 for details. common ghc-options-tests import: ghc-options - ghc-options: -Wno-redundant-constraints + ghc-options: + -Wno-redundant-constraints + -Wno-unused-packages library api import: ghc-options diff --git a/ouroboros-network/ouroboros-network.cabal b/ouroboros-network/ouroboros-network.cabal index b9d785d4b4f..22508123164 100644 --- a/ouroboros-network/ouroboros-network.cabal +++ b/ouroboros-network/ouroboros-network.cabal @@ -55,9 +55,16 @@ common ghc-options -- in tests librararies redundant constraints are sometimes useful (e.g. -- by default truned off debug tracing might require extra constraints like -- `Show` or `MonadSay`). +-- +-- TODO: '-Wno-redundant-constraints' remove when we support +-- `quickcheck-monoids`. For now, it is needed to prevent +-- false-positives that lead to build errors with `-Werror`. +-- See https://gitlab.haskell.org/ghc/ghc/-/issues/24173 for details. common ghc-options-tests import: ghc-options - ghc-options: -Wno-redundant-constraints + ghc-options: + -Wno-redundant-constraints + -Wno-unused-packages library api import: ghc-options @@ -451,7 +458,7 @@ library tests-lib cpp-options: -DNIGHTLY test-suite tests-lib-tests - import: ghc-options + import: ghc-options-tests type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: tests-lib/tests @@ -468,7 +475,7 @@ test-suite tests-lib-tests -threaded library framework-tests-lib - import: ghc-options + import: ghc-options-tests mixins: QuickCheck hiding (Test.QuickCheck.Monoids) @@ -500,7 +507,7 @@ library framework-tests-lib typed-protocols:{typed-protocols, examples}, test-suite framework-sim-tests - import: ghc-options + import: ghc-options-tests mixins: QuickCheck hiding (Test.QuickCheck.Monoids) @@ -547,7 +554,7 @@ test-suite framework-sim-tests cpp-options: -DOUROBOROS_NETWORK_IPV6 test-suite framework-io-tests - import: ghc-options + import: ghc-options-tests type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: framework/io-tests @@ -583,7 +590,7 @@ test-suite framework-io-tests -threaded library orphan-instances - import: ghc-options + import: ghc-options-tests visibility: public hs-source-dirs: orphan-instances exposed-modules: @@ -742,7 +749,7 @@ library protocols typed-protocols:{typed-protocols, cborg, stateful, stateful-cborg} ^>=1.1, library protocols-tests-lib - import: ghc-options + import: ghc-options-tests visibility: public hs-source-dirs: protocols/tests-lib exposed-modules: