Skip to content

Commit

Permalink
Fix windows ci
Browse files Browse the repository at this point in the history
  • Loading branch information
tbidne committed Dec 17, 2024
1 parent 3ea3752 commit 95c5574
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 8 deletions.
9 changes: 9 additions & 0 deletions backend/pacer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ common common-lang
TypeAbstractions
TypeFamilyDependencies

if os(windows)
cpp-options: -DWINDOWS

elif os(osx)
cpp-options: -DOSX -DPOSIX

else
cpp-options: -DLINUX -DPOSIX

default-language: GHC2021

library
Expand Down
37 changes: 37 additions & 0 deletions backend/src/Pacer/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ module Pacer.Prelude
-- * Dev / Debug
todo,

-- * OS
Os (..),
currentOs,
currentOsStr,
isPosix,
posixWindowsStr,

-- * Misc
pattern SetToSeqNE,
errorLeft,
Expand Down Expand Up @@ -112,6 +119,7 @@ import Data.Bool as X (Bool (False, True), not, otherwise, (&&), (||))
import Data.ByteString as X (ByteString)
import Data.ByteString.Lazy qualified as BSL
import Data.Char as X (Char)
import Data.Char qualified as Ch
import Data.Either as X (Either (Left, Right))
import Data.Eq as X (Eq ((/=), (==)))
import Data.Foldable as X
Expand Down Expand Up @@ -393,3 +401,32 @@ knownExceptions :: List ExceptionProxy
knownExceptions =
[ MkExceptionProxy @TextException Proxy
]

data Os
= Linux
| Osx
| Windows
deriving stock (Eq, Show)

currentOs :: Os
#if WINDOWS
currentOs = Windows
#elif OSX
currentOs = OSX
#else
currentOs = Linux
#endif

currentOsStr :: String
currentOsStr = Ch.toLower <$> show currentOs

isPosix :: Bool
isPosix = case currentOs of
Windows -> False
_ -> True

posixWindowsStr :: String
posixWindowsStr =
if isPosix
then "posix"
else "windows"
2 changes: 1 addition & 1 deletion backend/test/functional/Functional/Chart.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ testFilterEmptyError = testChart desc [osp|testFilterEmptyError|]
desc = "Filter empty error"

testDuplicateDateError :: IO OsPath -> TestTree
testDuplicateDateError = testChart desc [osp|testDuplicateDateError|]
testDuplicateDateError = testChartPosix True desc [osp|testDuplicateDateError|]
where
desc = "Duplicate date error"
32 changes: 29 additions & 3 deletions backend/test/functional/Functional/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ module Functional.Prelude
GoldenParams (..),
testGoldenParams,
testChart,
testChartPosix,
)
where

import Data.Word (Word8)
import FileSystem.OsPath (unsafeDecode)
import FileSystem.OsPath (unsafeDecode, unsafeEncode)
import FileSystem.OsPath qualified as FS.OsPath
import Hedgehog as X
( Gen,
Expand Down Expand Up @@ -129,8 +130,31 @@ data GoldenParams = MkGoldenParams
--
-- testFoo is the 'test name'.
testChart :: TestName -> OsPath -> IO OsPath -> TestTree
testChart testDesc testName getTestDir = testGoldenParams getTestDir params
testChart = testChartPosix False

-- | Like 'testChart', except it includes to determine if we take the current
-- OS into account.
testChartPosix ::
-- | If true, we will append posix/windows to the end of the golden test
-- path e.g. testName_posix.golden.
Bool ->
-- | Test description.
TestName ->
-- | Test name.
OsPath ->
-- | Retrieves the current directory.
IO OsPath ->
TestTree
testChartPosix osSwitch testDesc testName getTestDir = testGoldenParams getTestDir params
where
-- This is the path to the golden files. If osSwitch is false, then it
-- is the same as testName e.g. testName.golden. If the switch is active,
-- then we need to append the os e.g. testName_posix.golden.
goldenName =
if osSwitch
then testName <> unsafeEncode ("_" ++ posixWindowsStr)
else testName

params =
MkGoldenParams
{ mkArgs = \testDir ->
Expand All @@ -143,7 +167,7 @@ testChart testDesc testName getTestDir = testGoldenParams getTestDir params
unsafeDecode (mkJsonPath testDir)
],
testDesc,
testName,
testName = goldenName,
-- NOTE: It would be nice to test the txt output here i.e. the
-- second arg. Alas, it includes the path of the output json file,
-- which is non-deterministic, as it includes the tmp dir.
Expand All @@ -153,6 +177,8 @@ testChart testDesc testName getTestDir = testGoldenParams getTestDir params
resultToBytes = \path _ -> readBinaryFileIO . mkJsonPath $ path
}

-- These are always based on the testName, since all Os's share the same
-- CLI inputs.
basePath = [ospPathSep|test/functional/data|]
chartRequestsPath = unsafeDecode $ basePath </> testName <> [osp|_chart-requests.toml|]
runsPath = unsafeDecode $ basePath </> testName <> [osp|_runs.toml|]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Error decoding toml file 'test\functional\data\testDuplicateDateError_runs.toml': Decode error at '': Found overlapping timestamps
- <no title>: 2024-10-20T14:30:00
- A 5k: 2024-10-20
9 changes: 5 additions & 4 deletions web/src/build_charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@ function mkDataSet(x: { values: number[]; label: string }) {
* We widen charts to charts_typed since if charts.json does not have any
* charts with a y1 axis, ts will infer the y1 prop does not exist,
* hence the y1 access will fail.
*/
*/
const charts_typed = charts as {
data: {
x: string[];
y: {
label: string; values: number[];
label: string;
values: number[];
};
y1: {
label: string; values: number[];
label: string;
values: number[];
};
};
title: string;
}[];


for (var i = 0; i <= charts_typed.length; i++) {
const elemId = `chart${i}`;
appendCanvasId(elemId);
Expand Down

0 comments on commit 95c5574

Please sign in to comment.