File tree Expand file tree Collapse file tree 6 files changed +113
-13
lines changed
Expand file tree Collapse file tree 6 files changed +113
-13
lines changed Original file line number Diff line number Diff line change 1+ name : ' Unit tests'
2+
3+ on :
4+ workflow_dispatch :
5+ pull_request :
6+ push :
7+
8+ # Kill other jobs when we trigger this workflow by sending new commits
9+ # to the PR.
10+ # https://stackoverflow.com/a/72408109
11+ concurrency :
12+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13+ cancel-in-progress : true
14+
15+ jobs :
16+ unit-tests :
17+ name : Run unit tests with Expecto
18+ runs-on : ubuntu-22.04
19+ steps :
20+ - name : Checkout repo
21+ uses : actions/checkout@v4
22+ - name : Setup .NET
23+ uses : actions/setup-dotnet@v4
24+ with :
25+ dotnet-version : ' 8.x'
26+ - name : Install dependencies
27+ run : dotnet restore
28+ - name : Run tests
29+ run : dotnet run --project tests/
Original file line number Diff line number Diff line change 1111 </ItemGroup >
1212
1313 <ItemGroup >
14+ <Compile Include =" TruncateTags.fs" />
1415 <Compile Include =" Program.fs" />
1516 </ItemGroup >
1617
Original file line number Diff line number Diff line change @@ -38,10 +38,16 @@ type RETURN_CODE =
3838 | SUCCESS = 0
3939 | FAIL = 1
4040
41- let truncate ( valuesToTake : int ) ( args : string array ) : string array =
42- match valuesToTake = - 1 with
43- | true -> args
44- | false -> args |> Array.truncate valuesToTake
41+ // let getTruncatedTags (valuesToTake: int) (args: string array) : string array =
42+ // let truncate (valuesToTake: int) (args: string array) : string array =
43+ // match valuesToTake = -1 with
44+ // | true -> args
45+ // | false -> args |> Array.truncate valuesToTake
46+
47+ // args
48+ // |> Array.map (fun s -> s.Split(' ') |> Array.filter (String.IsNullOrEmpty >> not))
49+ // |> Array.concat // flat
50+ // |> truncate valuesToTake
4551
4652let getWorkflowNewPath () =
4753 Path.Combine [| Directory.GetCurrentDirectory(); " workflow.new.yml" |]
@@ -69,11 +75,7 @@ let main (args: string array) : int =
6975 let! valuesToTake = GitHubHelpers.getValuesToTake ()
7076 let! workflowKey = GitHubHelpers.getWorkflowKey ()
7177
72- let tags =
73- args
74- |> Array.map ( fun s -> s.Split( ' ' ) |> Array.filter ( String.IsNullOrEmpty >> not ))
75- |> Array.concat // flat
76- |> truncate valuesToTake
78+ let tags = Main.TruncateTags.getTruncatedTags valuesToTake args
7779
7880 do ! Validations.validateTagsAreNotEmpty tags
7981
Original file line number Diff line number Diff line change 1+ namespace Main
2+
3+ module TruncateTags =
4+
5+ open System
6+
7+ let getTruncatedTags ( valuesToTake : int ) ( args : string array ) : string array =
8+ let truncate ( valuesToTake : int ) ( args : string array ) : string array =
9+ match valuesToTake = - 1 with
10+ | true -> args
11+ | false -> args |> Array.truncate valuesToTake
12+
13+ args
14+ |> Array.map ( fun s -> s.Split( ' ' ) |> Array.filter ( String.IsNullOrEmpty >> not ))
15+ |> Array.concat // flat
16+ |> truncate valuesToTake
Original file line number Diff line number Diff line change 1- // For more information see https://aka.ms/fsharp-console-apps
2- printfn "Hello from F#"
1+ open Expecto
2+ open Main.TruncateTags
3+
4+ let tests =
5+ let inputArgs =
6+ [| " v0.0.010 v0.0.009 v0.0.008 v0.0.007 v0.0.006 v0.0.005 v0.0.004 v0.0.003 v0.0.002 v0.0.001" |]
7+
8+ let valuesToTake = 5
9+
10+ testList
11+ " Truncated tags tests"
12+ [ test " one string" {
13+ let expected = inputArgs.[ 0 ]. Split ' ' |> Array.take valuesToTake
14+
15+ Expect.equal ( getTruncatedTags valuesToTake inputArgs) expected " Does not work with one string"
16+ }
17+
18+ test " many string" {
19+ let inputArgs = inputArgs.[ 0 ]. Split ' '
20+
21+ let expected = inputArgs |> Array.take valuesToTake
22+
23+ Expect.equal ( getTruncatedTags valuesToTake inputArgs) expected " Does not work with many strings"
24+ }
25+
26+ test " insufficient one string" {
27+ let inputArgs = [| " v0.0.003 v0.0.002 v0.0.001" |]
28+
29+ let expected = inputArgs.[ 0 ]. Split ' '
30+
31+ Expect.equal
32+ ( getTruncatedTags valuesToTake inputArgs)
33+ expected
34+ " Does not work with insufficient one string"
35+ }
36+
37+ test " insufficient many strings" {
38+ let inputArgs = [| " v0.0.003 v0.0.002 v0.0.001" |].[ 0 ]. Split ' '
39+
40+ let expected = inputArgs
41+
42+ Expect.equal
43+ ( getTruncatedTags valuesToTake inputArgs)
44+ expected
45+ " Does not work with insufficient many strings"
46+ } ]
47+ |> testLabel " getTruncatedTags"
48+
49+ [<EntryPoint>]
50+ let main args = runTestsWithCLIArgs [] args tests
Original file line number Diff line number Diff line change 99 <Compile Include =" Program.fs" />
1010 </ItemGroup >
1111
12- <ItemGroup >
13- <PackageReference Include =" Expecto" Version =" 10.2.1" />
12+ <ItemGroup >
13+ <ProjectReference Include =" ..\src\Main.fsproj" />
14+ </ItemGroup >
15+
16+ <ItemGroup >
17+ <PackageReference Include =" Expecto" Version =" 10.2.1" />
1418 </ItemGroup >
1519
1620</Project >
You can’t perform that action at this time.
0 commit comments