<commit_before>﻿module Paket.IntegrationTests.LocalOverrideSpecs

open System.IO
open System.Xml

open Paket
open Paket.Xml

open FsUnit

open NUnit.Framework

[<Test>]
let ``#1633 paket.local local source override``() = 
    paket "restore" "i001633-local-source-override" |> ignore
    let doc = new XmlDocument()
    Path.Combine(
        scenarioTempPath "i001633-local-source-override",
        "packages",
        "NUnit",
        "NUnit.nuspec")
    |> doc.Load

    doc 
    |> getNode "package" 
    |> optGetNode "metadata" 
    |> optGetNode "devSourceOverride"
    |> Option.map (fun n -> n.InnerText)
    |> shouldEqual (Some "true")

let replaceInFile filePath (searchText: string) replaceText =
    File.ReadAllText filePath
    |> fun x -> x.Replace(searchText, replaceText)
    |> fun x -> File.WriteAllText (filePath, x)

[<Test>]
let ``#1633 paket.local local git override``() = 
    let scenario = "i001633-local-git-override"
    replaceInFile 
        (Path.Combine (originalScenarioPath scenario, "paket.local"))
        "[build-command]" 
        (if isUnix then "build.sh NuGet" else "build.cmd NuGet") 
    paket "restore" scenario |> ignore
    let doc = new XmlDocument()
    Path.Combine(
        scenarioTempPath scenario,
        "packages",
        "Argu",
        "Argu.nuspec")
    |> doc.Load

    doc 
    |> getNode "package" 
    |> optGetNode "metadata" 
    |> optGetNode "summary"
    |> Option.map (fun n -> n.InnerText)
    |> shouldEqual (Some "Test paket source remote git override.")

[<Test>]
let ``#1633 paket.local local git override (git origin)``() = 
    let scenario = "i001633-local-git_origin"
    replaceInFile 
        (Path.Combine (originalScenarioPath scenario, "paket.local"))
        "[build-command]" 
        (if isUnix then "build.sh NuGet" else "build.cmd NuGet") 
    paket "restore" scenario |> ignore
    let doc = new XmlDocument()
    Path.Combine(
        scenarioTempPath scenario,
        "packages",
        "Argu",
        "Argu.nuspec")
    |> doc.Load

    doc 
    |> getNode "package" <commit_msg>expand '[build-command]' variable in temp scenario path<commit_after>﻿module Paket.IntegrationTests.LocalOverrideSpecs

open System.IO
open System.Xml

open Paket
open Paket.Xml

open FsUnit

open NUnit.Framework

[<Test>]
let ``#1633 paket.local local source override``() = 
    paket "restore" "i001633-local-source-override" |> ignore
    let doc = new XmlDocument()
    Path.Combine(
        scenarioTempPath "i001633-local-source-override",
        "packages",
        "NUnit",
        "NUnit.nuspec")
    |> doc.Load

    doc 
    |> getNode "package" 
    |> optGetNode "metadata" 
    |> optGetNode "devSourceOverride"
    |> Option.map (fun n -> n.InnerText)
    |> shouldEqual (Some "true")

let replaceInFile filePath (searchText: string) replaceText =
    File.ReadAllText filePath
    |> fun x -> x.Replace(searchText, replaceText)
    |> fun x -> File.WriteAllText (filePath, x)

[<Test>]
let ``#1633 paket.local local git override``() = 
    let scenario = "i001633-local-git-override"
    prepare scenario
    replaceInFile 
        (Path.Combine (scenarioTempPath scenario, "paket.local"))
        "[build-command]" 
        (if isUnix then "build.sh NuGet" else "build.cmd NuGet") 
    directPaket "restore" scenario |> ignore
    let doc = new XmlDocument()
    Path.Combine(
        scenarioTempPath scenario,
        "packages",
        "Argu",
        "Argu.nuspec")
    |> doc.Load

    doc 
    |> getNode "package" 
    |> optGetNode "metadata" 
    |> optGetNode "summary"
    |> Option.map (fun n -> n.InnerText)
    |> shouldEqual (Some "Test paket source remote git override.")

[<Test>]
let ``#1633 paket.local local git override (git origin)``() = 
    let scenario = "i001633-local-git_origin"
    prepare scenario
    replaceInFile 
        (Path.Combine (scenarioTempPath scenario, "paket.local"))
        "[build-command]" 
        (if isUnix then "build.sh NuGet" else "build.cmd NuGet") 
    directPaket "restore" scenario |> ignore
    let doc = new XmlDocument()
    Path.Combine(
        scenarioTempPath scenario,
        "packages",
        "Argu",
        "Argu.nuspec")
    |> doc.Load

    doc 
    |> getNode "package" 
{'fraction_non_alphanumeric': 0.12517680339462517, 'fraction_numerical': 0.016973125884016973, 'mean_word_length': 2.7548672566371684, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '826878', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1355, 'n_words': 348}