diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f227b18..e4aee13 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -69,11 +69,11 @@ jobs: path: | backend/test/functional/goldens + # yamllint disable rule:line-length - name: Generate charts json with backend run: | - cabal run pacer -- chart \ - --runs backend/data/input/example/runs.toml \ - --chart-requests backend/data/input/example/chart-requests.toml + cabal run pacer -- chart --runs backend/data/input/example/runs.toml --chart-requests backend/data/input/example/chart-requests.toml + # yamllint enable rule:line-length - name: Install web dependencies run: | diff --git a/backend/pacer.cabal b/backend/pacer.cabal index 1d6f076..f56505b 100644 --- a/backend/pacer.cabal +++ b/backend/pacer.cabal @@ -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 diff --git a/backend/src/Pacer/Prelude.hs b/backend/src/Pacer/Prelude.hs index 90f792e..892d8d3 100644 --- a/backend/src/Pacer/Prelude.hs +++ b/backend/src/Pacer/Prelude.hs @@ -63,6 +63,13 @@ module Pacer.Prelude -- * Dev / Debug todo, + -- * OS + Os (..), + currentOs, + currentOsStr, + isPosix, + posixWindowsStr, + -- * Misc pattern SetToSeqNE, errorLeft, @@ -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 @@ -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" diff --git a/backend/test/functional/Functional/Chart.hs b/backend/test/functional/Functional/Chart.hs index 2618470..11de40e 100644 --- a/backend/test/functional/Functional/Chart.hs +++ b/backend/test/functional/Functional/Chart.hs @@ -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" diff --git a/backend/test/functional/Functional/Prelude.hs b/backend/test/functional/Functional/Prelude.hs index 21ccf43..935c6bd 100644 --- a/backend/test/functional/Functional/Prelude.hs +++ b/backend/test/functional/Functional/Prelude.hs @@ -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, @@ -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 -> @@ -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. @@ -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|] diff --git a/backend/test/functional/goldens/testDuplicateDateError.golden b/backend/test/functional/goldens/testDuplicateDateError_posix.golden similarity index 100% rename from backend/test/functional/goldens/testDuplicateDateError.golden rename to backend/test/functional/goldens/testDuplicateDateError_posix.golden diff --git a/backend/test/functional/goldens/testDuplicateDateError_windows.golden b/backend/test/functional/goldens/testDuplicateDateError_windows.golden new file mode 100644 index 0000000..ef75941 --- /dev/null +++ b/backend/test/functional/goldens/testDuplicateDateError_windows.golden @@ -0,0 +1,3 @@ +Error decoding toml file 'test\functional\data\testDuplicateDateError_runs.toml': Decode error at '': Found overlapping timestamps + - : 2024-10-20T14:30:00 + - A 5k: 2024-10-20 diff --git a/web/src/build_charts.ts b/web/src/build_charts.ts index 3295a11..6a23b66 100644 --- a/web/src/build_charts.ts +++ b/web/src/build_charts.ts @@ -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);