-
Notifications
You must be signed in to change notification settings - Fork 2
/
ValidateAPI.fs
91 lines (67 loc) · 3.44 KB
/
ValidateAPI.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
namespace ARCValidate.API
open ARCValidate
open ARCValidate.CLIArguments
open ARCExpect
open ARCExpect.Configs
open ARCTokenization
open Expecto
open System.IO
open Argu
open ControlledVocabulary
module ValidateAPI =
let validate (verbose: bool) (args: ParseResults<ValidateArgs>)=
let root =
args.TryGetResult(ARC_Directory)
|> Option.defaultValue (System.Environment.GetEnvironmentVariable("ARC_PATH")) // default to ARC_PATH if argument is not provided
|> fun s -> if System.String.IsNullOrWhiteSpace(s) then System.Environment.CurrentDirectory else s // default to ./ if ARC_PATH is not set
|> Path.GetFullPath
|> fun p -> p.Replace("\\","/")
|> fun p -> if not (p.EndsWith("/")) then p + "/" else p // ensure path ends with a slash
let outPath =
args.TryGetResult(Out_Directory)
|> Option.defaultValue root
let hasInvFile = File.Exists(Path.Combine(root, "isa.investigation.xlsx"))
let investigationTokens =
if hasInvFile then
Investigation.parseMetadataSheetFromFile (Path.Combine(root, "isa.investigation.xlsx"))
|> List.filter (fun p ->
Param.getValueAsTerm p <> Terms.StructuralTerms.metadataSectionKey // filter these out to get only value-holding cells
)
else
[]
/// these tests MUST pass for an ARC to be considered for publishing
let criticalTests =
testList "Critical" [
TestGeneration.Critical.ARC.FileSystem.generateARCFileSystemTests root
TestGeneration.Critical.ARC.ISA.generateISATests investigationTokens
]
let criticalTestResults =
criticalTests
|> performTest
if criticalTestResults.failed |> List.isEmpty && criticalTestResults.errored |> List.isEmpty then // if no critical tests failed or errored
/// these tests SHOULD pass for an ARC to be considered of high quality
let nonCriticalTests =
testList "Non-critical" [
TestGeneration.NonCritical.ARC.ISA.generateISATests investigationTokens
]
let nonCriticalTestResults =
nonCriticalTests
|> performTest
let combinedTestResults =
[criticalTestResults; nonCriticalTestResults]
|> combineTestRunSummaries // aggregate critical and non-critical test results
let badge =
combinedTestResults
|> BadgeCreation.createSuccessBadge "ARC quality"
badge.WriteBadge(Path.Combine(outPath, "arc-quality.svg"))
combinedTestResults
|> writeJUnitSummary verbose (Path.Combine(outPath, "arc-validate-results.xml")) // write the combined result to a single file
ExitCode.Success // critical tests passed, non-critical tests have been performed. Success!
else // one or more critical tests failed or errored.
let badge =
criticalTestResults
|> BadgeCreation.createCriticalFailBadge "ARC quality"
badge.WriteBadge(Path.Combine(outPath, "arc-quality.svg"))
criticalTestResults
|> Expecto.writeJUnitSummary verbose (Path.Combine(outPath, "arc-validate-results.xml"))
ExitCode.CriticalTestFailure