<commit_before>#r @"ThirdParty\FAKE\FAKE.Core\tools\FakeLib.dll"
#load @"Build\ExtractDocs.fsx"

open Fake
open Fake.AssemblyInfoFile
open Fake.FileUtils
open System
open System.IO
open ExtractDocs
open System.Text.RegularExpressions

module FileReaderWriter = 
    let Read file = File.ReadAllText(file)
    let Write file text = File.WriteAllText(file, text)
    let TransformFile file target (f : string -> string) = 
        Read file
        |> f
        |> Write target

module ExamplesToCode = 
    open FileReaderWriter
    
    let ConvertFile file targetDir = 
        let fileName = Path.GetFileNameWithoutExtension(file)
        let target = targetDir @@ fileName + ".cs"
        log <| sprintf "Converting %s to %s" file target
        TransformFile file target (ExtractDocs.strToFixture fileName)
    
    let Convert paths targetDir = 
        let paths = paths |> Seq.toList
        for p in paths do
            trace <| sprintf "Convert from %s to %s" p targetDir
            let files = !! "*.markdown" ++ "*.html" |> SetBaseDir p
            for file in files do
                ConvertFile file targetDir

let ALL_TARGETS = [ "NET35"; "NET40"; "NET45" ]
let buildMode = getBuildParamOrDefault "mode" "Debug"

let targets = 
    match getBuildParamOrDefault "targets" "" with
    | "" -> [ ALL_TARGETS.Head ]
    | "ALL" -> ALL_TARGETS
    | s -> s.Split([| ',' |], StringSplitOptions.RemoveEmptyEntries) |> Array.toList

let OUTPUT_PATH = "Output"
let releaseNotes = ReadFile "CHANGELOG.txt" |> ReleaseNotesHelper.parseReleaseNotes
let version = releaseNotes.AssemblyVersion
let outputBasePath = OUTPUT_PATH @@ buildMode
let deployPath = outputBasePath @@ "NSubstitute-" + version

Target "Clean" <| fun _ -> CleanDirs [ OUTPUT_PATH ]

Target "Version" <| fun _ ->
    CreateCSharpAssemblyInfo "Source/NSubstitute/Properties/AssemblyInfo.cs"
        [ Attribute.Title "NSubstitute"
          Attribute.Description "A simple substitute for .NET mocking libraries." 
          Attribute.Guid "f1571463-8354-493c-b67c-cd9cec9adf78"
          Attribute.Product "NSubstitute" 
          Attribute.Copyright @"Copyright \u00A9 2009 NSubstitute Team"
          Attribute.Version version
          Attribute.FileVersion version ]

Target "BuildSolution" <| fun _ -> 
    let build config mode = 
        MSBuild null "Build"
            [ "Configuration", config + "-" + buildMode ] // e.g. NET35-Debug
            [ "./Source/NSubstitute.2010.sln" ]
            |> ignore
    targets |> List.iter (fun config -> build config buildMode)

Target "Test" <| fun _ -> 
    targets
    |> List.iter (fun config -> 
                   let workingDir = outputBasePath @@ config
                   let testDlls = !!(workingDir @@ "**" @@ "*Specs.dll")
                   testDlls |> NUnit(fun p -> 
                                   { p with DisableShadowCopy = true
                                            Framework = "net-4.0"
                                            ExcludeCategory = "Pending"
                                            OutputFile = workingDir @@ "TestResults.xml" })
                   )

Target "TestExamples" <| fun _ -> 
    targets
    |> List.iter (fun config -> 
                   let workingDir = outputBasePath
                   let testDlls = !!(workingDir @@ "CodeFromDocs" @@ "NSubstitute.Samples.dll")
                   testDlls |> NUnit(fun p -> 
                                   { p with DisableShadowCopy = true
                                            Framework = "net-4.0"<commit_msg>Updating copyright character in fake build assemblyinfo task<commit_after>#r @"ThirdParty\FAKE\FAKE.Core\tools\FakeLib.dll"
#load @"Build\ExtractDocs.fsx"

open Fake
open Fake.AssemblyInfoFile
open Fake.FileUtils
open System
open System.IO
open ExtractDocs
open System.Text.RegularExpressions

module FileReaderWriter = 
    let Read file = File.ReadAllText(file)
    let Write file text = File.WriteAllText(file, text)
    let TransformFile file target (f : string -> string) = 
        Read file
        |> f
        |> Write target

module ExamplesToCode = 
    open FileReaderWriter
    
    let ConvertFile file targetDir = 
        let fileName = Path.GetFileNameWithoutExtension(file)
        let target = targetDir @@ fileName + ".cs"
        log <| sprintf "Converting %s to %s" file target
        TransformFile file target (ExtractDocs.strToFixture fileName)
    
    let Convert paths targetDir = 
        let paths = paths |> Seq.toList
        for p in paths do
            trace <| sprintf "Convert from %s to %s" p targetDir
            let files = !! "*.markdown" ++ "*.html" |> SetBaseDir p
            for file in files do
                ConvertFile file targetDir

let ALL_TARGETS = [ "NET35"; "NET40"; "NET45" ]
let buildMode = getBuildParamOrDefault "mode" "Debug"

let targets = 
    match getBuildParamOrDefault "targets" "" with
    | "" -> [ ALL_TARGETS.Head ]
    | "ALL" -> ALL_TARGETS
    | s -> s.Split([| ',' |], StringSplitOptions.RemoveEmptyEntries) |> Array.toList

let OUTPUT_PATH = "Output"
let releaseNotes = ReadFile "CHANGELOG.txt" |> ReleaseNotesHelper.parseReleaseNotes
let version = releaseNotes.AssemblyVersion
let outputBasePath = OUTPUT_PATH @@ buildMode
let deployPath = outputBasePath @@ "NSubstitute-" + version

Target "Clean" <| fun _ -> CleanDirs [ OUTPUT_PATH ]

Target "Version" <| fun _ ->
    CreateCSharpAssemblyInfo "Source/NSubstitute/Properties/AssemblyInfo.cs"
        [ Attribute.Title "NSubstitute"
          Attribute.Description "A simple substitute for .NET mocking libraries." 
          Attribute.Guid "f1571463-8354-493c-b67c-cd9cec9adf78"
          Attribute.Product "NSubstitute" 
          Attribute.Copyright @"Copyright  2009 NSubstitute Team"
          Attribute.Version version
          Attribute.FileVersion version ]

Target "BuildSolution" <| fun _ -> 
    let build config mode = 
        MSBuild null "Build"
            [ "Configuration", config + "-" + buildMode ] // e.g. NET35-Debug
            [ "./Source/NSubstitute.2010.sln" ]
            |> ignore
    targets |> List.iter (fun config -> build config buildMode)

Target "Test" <| fun _ -> 
    targets
    |> List.iter (fun config -> 
                   let workingDir = outputBasePath @@ config
                   let testDlls = !!(workingDir @@ "**" @@ "*Specs.dll")
                   testDlls |> NUnit(fun p -> 
                                   { p with DisableShadowCopy = true
                                            Framework = "net-4.0"
                                            ExcludeCategory = "Pending"
                                            OutputFile = workingDir @@ "TestResults.xml" })
                   )

Target "TestExamples" <| fun _ -> 
    targets
    |> List.iter (fun config -> 
                   let workingDir = outputBasePath
                   let testDlls = !!(workingDir @@ "CodeFromDocs" @@ "NSubstitute.Samples.dll")
                   testDlls |> NUnit(fun p -> 
                                   { p with DisableShadowCopy = true
                                            Framework = "net-4.0"
{'fraction_non_alphanumeric': 0.09830318328425186, 'fraction_numerical': 0.011639321273313701, 'mean_word_length': 2.03102422439439, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3155078', 'n_tokens_mistral': 2100, 'n_tokens_neox': 1929, 'n_words': 527}