Skip to content

Project structure: extract examples (quicksort, foreign heap/list, ...) to internal library to allow easy run/test/benchmarking #480

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

Merged
merged 2 commits into from
Sep 13, 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
2 changes: 1 addition & 1 deletion examples/Simple/Quicksort.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE NoImplicitPrelude #-}

-- | This module implements quicksort with mutable arrays from linear-base
module Simple.Quicksort (quickSort) where
module Simple.Quicksort where

import Data.Array.Mutable.Linear (Array)
import qualified Data.Array.Mutable.Linear as Array
Expand Down
11 changes: 0 additions & 11 deletions examples/Test/Generic.hs

This file was deleted.

45 changes: 27 additions & 18 deletions linear-base.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,23 @@ library
vector >=0.12.2,
primitive

library examples
import: build-opts
hs-source-dirs: examples
exposed-modules:
Foreign.List
Foreign.Heap
Simple.FileIO
Simple.Pure
Simple.Quicksort
Simple.TopSort
build-depends:
base,
linear-base,
storable-tuple,
vector,
text

test-suite test
import: build-opts
import: rts-opts-multithread
Expand All @@ -158,6 +175,7 @@ test-suite test
Test.Data.Mutable.HashMap
Test.Data.Mutable.Set
Test.Data.Polarized
Test.Data.Functor.Linear
Test.Data.V
Test.Data.Replicator
default-language: Haskell2010
Expand All @@ -171,38 +189,28 @@ test-suite test
tasty,
tasty-hedgehog >= 1.2,
mmorph,
vector
vector,
linear-generics

test-suite examples
test-suite test-examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test-suite test-examples
test-suite examples

Should work. Because different units are namespaced between their types, so it'll be referred to as something like test:examples (instead of test:test-examples in your case).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesnt seem to work:

library examples
    import: build-opts
    hs-source-dirs: examples
    
[...]

test-suite examples
    import: build-opts
    import: rts-opts-multithread
    type:             exitcode-stdio-1.0
    main-is:          Main.hs
    hs-source-dirs:   test/examples

gives

Configuring linear-base-0.4.0...
There exist several components with the same name: 'examples'. This is a bug in your .cabal file.
CallStack (from HasCallStack):
  error, called at libraries/Cabal/Cabal-syntax/src/Distribution/PackageDescription/Utils.hs:18:15 in Cabal-syntax-3.10.3.0:Distribution.PackageDescription.Utils
Progress 1/2

Error: [S-7282]
       Stack failed to execute the build plan.
       
       While executing the build plan, Stack encountered the error:
       
       [S-7011]
       While building package linear-base-0.4.0 (scroll up to its section to see the error)
       using:
[...]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad then.

import: build-opts
import: rts-opts-multithread
type: exitcode-stdio-1.0
main-is: Main.hs
hs-source-dirs: examples
hs-source-dirs: test-examples
other-modules:
Test.Foreign
Test.Quicksort
Test.Generic
Foreign.List
Foreign.Heap
Simple.FileIO
Simple.Pure
Simple.Quicksort
Simple.TopSort
Generic.Traverse
Test.Simple.Quicksort
default-language: Haskell2010
build-depends:
base,
linear-base,
tasty,
tasty-hedgehog,
hedgehog,
storable-tuple,
vector,
text,
linear-generics
examples

benchmark mutable-data
benchmark bench
import: build-opts
import: rts-opts-monothread-stats
type: exitcode-stdio-1.0
Expand All @@ -224,4 +232,5 @@ benchmark mutable-data
random-shuffle,
tasty-bench >= 0.3,
unordered-containers,
MonadRandom
MonadRandom,
examples
6 changes: 2 additions & 4 deletions examples/Main.hs → test-examples/Main.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Main where

import Test.Foreign (foreignGCTests)
import Test.Generic (genericTests)
import Test.Quicksort (quickSortTests)
import Test.Simple.Quicksort (quickSortTests)
import Test.Tasty

main :: IO ()
Expand All @@ -13,6 +12,5 @@ allTests =
testGroup
"All tests"
[ foreignGCTests,
quickSortTests,
genericTests
quickSortTests
]
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.Quicksort (quickSortTests) where
module Test.Simple.Quicksort (quickSortTests) where

import Data.List (sort)
import Hedgehog
Expand Down
4 changes: 3 additions & 1 deletion test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module Main where

import Test.Data.Destination (destArrayTests)
import Test.Data.Functor.Linear (genericTests)
import Test.Data.Mutable.Array (mutArrTests)
import Test.Data.Mutable.HashMap (mutHMTests)
import Test.Data.Mutable.Set (mutSetTests)
Expand All @@ -27,7 +28,8 @@ allTests =
mutHMTests,
mutSetTests,
destArrayTests,
polarizedArrayTests
polarizedArrayTests,
genericTests
],
testGroup
"Inspection tests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}

module Generic.Traverse (genericTraverseTests) where
module Test.Data.Functor.Linear (genericTests) where

import Data.Functor.Linear (genericTraverse)
import qualified Data.Functor.Linear as Data
Expand All @@ -32,6 +32,13 @@ instance Data.Functor Pair where
instance Data.Traversable Pair where
traverse = genericTraverse

genericTests :: TestTree
genericTests =
testGroup
"Generic tests"
[ genericTraverseTests
]

genericTraverseTests :: TestTree
genericTraverseTests =
testGroup
Expand Down
Loading