Skip to content

Commit

Permalink
fix test file path handling for js in linux
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Dec 4, 2024
1 parent 94714ba commit ce001af
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build/TestTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module RunTests =
Trace.traceImportant "Start Js tests"
for path in ProjectInfo.testProjects do
// Setup test results directory after clean
System.IO.Directory.CreateDirectory(@".\tests\TestingUtils\TestResults\js") |> ignore
System.IO.Directory.CreateDirectory("./tests/TestingUtils/TestResults/js") |> ignore
// transpile js files from fsharp code
run dotnet $"fable {path} -o {path}/js --nocache" ""

Expand Down Expand Up @@ -67,7 +67,7 @@ module RunTests =
Trace.traceImportant "Start Python tests"
for path in ProjectInfo.testProjects do
// Setup test results directory after clean
System.IO.Directory.CreateDirectory(@".\tests\TestingUtils\TestResults\py") |> ignore
System.IO.Directory.CreateDirectory("./tests/TestingUtils/TestResults/py") |> ignore
//transpile py files from fsharp code
run dotnet $"fable {path} -o {path}/py --lang python --nocache" ""
// run pyxpecto in target path to execute tests in python
Expand Down
7 changes: 7 additions & 0 deletions src/ARCtrl/ContractIO/FileSystemHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,18 @@ let writeFileXlsxAsync path (wb : FsWorkbook) =
#endif


let trim (path : string) =
if path.StartsWith("./") then
path.Replace("./","").Trim('/')
else path.Trim('/')

/// Return the absolute path relative to the directoryPath
let makeRelative directoryPath (path : string) =
if directoryPath = "." || directoryPath = "/" || directoryPath = "" then
path
else
let directoryPath = trim directoryPath
let path = trim path
if path.StartsWith(directoryPath) then
path.Substring(directoryPath.Length)
else path
Expand Down
6 changes: 3 additions & 3 deletions tests/ARCtrl/FileSystemHelper.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ let getSubFiles =
$"{TestObjects.IO.testSubPathsFolder}/File1.txt" |> FileSystemHelper.standardizeSlashes
$"{TestObjects.IO.testSubPathsFolder}/File2.csv" |> FileSystemHelper.standardizeSlashes
]
Expect.sequenceEqual result expected "Files were not found correctly."
Expect.pathSequenceEqual result expected "Files were not found correctly."
})
]

Expand All @@ -138,7 +138,7 @@ let getSubDirectories =
[
$"{TestObjects.IO.testSubPathsFolder}/SubFolder" |> FileSystemHelper.standardizeSlashes
]
Expect.sequenceEqual result expected "Directories were not found correctly."
Expect.pathSequenceEqual result expected "Directories were not found correctly."
})
]

Expand All @@ -157,7 +157,7 @@ let getAllFilePaths =
$"/SubFolder/File3.xlsx" |> FileSystemHelper.standardizeSlashes
$"/SubFolder/SubSubFolder/File4" |> FileSystemHelper.standardizeSlashes
]
Expect.sequenceEqual result expected "File Paths were not found correctly."
Expect.pathSequenceEqual result expected "File Paths were not found correctly."

})
]
Expand Down
16 changes: 12 additions & 4 deletions tests/TestingUtils/TestObjects.IO.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ module TestObjects.IO

open ARCtrl.ArcPathHelper

let testObjectsBaseFolder = combine __SOURCE_DIRECTORY__ "TestObjects.IO"
let testBaseFolder =
#if FABLE_COMPILER_JAVASCRIPT || FABLE_COMPILER_TYPESCRIPT
"./tests/TestingUtils"
#else
//"../TestingUtils"
__SOURCE_DIRECTORY__
#endif

let testObjectsBaseFolder = combine testBaseFolder "TestObjects.IO"

let testResultsFolder =
#if !FABLE_COMPILER
combineMany [| __SOURCE_DIRECTORY__;"TestResults";"NET"|]
combineMany [| testBaseFolder;"TestResults";"NET"|]
#endif
#if FABLE_COMPILER_JAVASCRIPT || FABLE_COMPILER_TYPESCRIPT
combineMany [| __SOURCE_DIRECTORY__;"TestResults";"js"|]
combineMany [| testBaseFolder;"TestResults";"js"|]
#endif
#if FABLE_COMPILER_PYTHON
combineMany [| __SOURCE_DIRECTORY__;"TestResults";"py"|]
combineMany [| testBaseFolder;"TestResults";"py"|]
#endif

let testContractsFolder = combine testObjectsBaseFolder "Contracts"
Expand Down
11 changes: 10 additions & 1 deletion tests/TestingUtils/TestingUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ module Utils =
Seq.mapi2 (fun i s p -> i,s,p) s1 s2
|> Seq.find (function |_,Some s,Some p when s=p -> false |_-> true)

let trim (path : string) =
if path.StartsWith("./") then
path.Replace("./","").Trim('/')
else path.Trim('/')

module Result =

Expand Down Expand Up @@ -96,6 +100,7 @@ module Expect =
let inline equal actual expected message = Expect.equal actual expected message
let notEqual actual expected message = Expect.notEqual actual expected message


/// Trims whitespace and normalizes lineendings to "\n"
let trimEqual (actual: string) (expected: string) message =
let a = actual.Trim().Replace("\r\n", "\n")
Expand Down Expand Up @@ -193,7 +198,11 @@ module Expect =
failwithf "%s. Sequence actual longer than expected, at pos %i found item %O."
message i a


let pathSequenceEqual actual expected message =
let actual = actual |> Seq.map trim
let expected = expected |> Seq.map trim
sequenceEqual actual expected message

let workSheetEqual (actual : FsWorksheet) (expected : FsWorksheet) message =
let f (ws : FsWorksheet) =
ws.RescanRows()
Expand Down

0 comments on commit ce001af

Please sign in to comment.