Commit cdc15ad9 authored by Yuanle Song's avatar Yuanle Song
Browse files

implement ToMingwPath

added unit test sub project.
parent 0b533ed7
......@@ -8,8 +8,11 @@
// /%appdata%/mbackup/mbackup-default.exclude
// /%appdata%/mbackup/local.exclude (optional)
module Mbackup
open System
open System.Diagnostics
open System.Text.RegularExpressions;
open Argu
......@@ -69,16 +72,31 @@ let GetEnvDefault (varName: string) (defaultValue: string) =
| "" -> defaultValue
| _ -> value
// Convert windows path to Mingw64 path
let ToMingwPath windowsPath =
// TODO implement me
windowsPath
let appDataRoamingDir = ToMingwPath (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
let appDataLocalDir = ToMingwPath (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))
// TODO make sure dir ends with /
let userConfigDir = appDataRoamingDir + "/mbackup/"
// Convert windows path to Mingw64 path.
// Supported windows path: C:\foo, C:/foo, /c/foo
// MingwPath format: /cygdrive/c/foo
let ToMingwPath (windowsPath: string) =
let pattern = Regex("^/([c-zC-Z])/", RegexOptions.None)
let result =
if pattern.IsMatch(windowsPath) then
"/cygdrive" + windowsPath
else
let pattern = Regex("^([c-zC-Z]):", RegexOptions.None)
if pattern.IsMatch(windowsPath) then
let result = windowsPath.Replace('\\', '/')
"/cygdrive/" + result.Substring(0, 1).ToLower() + result.Substring(2)
else
windowsPath
result
let EnsureDir (path: string) = if path.EndsWith "/" then path else path + "/"
let appDataRoamingDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) |> ToMingwPath |> EnsureDir
let programDataDir = GetEnv "PROGRAMDATA" |> ToMingwPath |> EnsureDir
let appDataLocalDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) |> ToMingwPath |> EnsureDir
//let userConfigDir = appDataRoamingDir + "mbackup/"
let userConfigDir = programDataDir + "mbackup/"
let runtimeDir = appDataLocalDir
let isLocalTarget (target: string) = target.StartsWith "/"
......
cd mbackup-tests
dotnet test
# dirs to backup
/cygdrive/c/ProgramData/mbackup
/cygdrive/c/path/to/dir
/cygdrive/d/path/to/dir
......@@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RootNamespace>mbackup_for_windows</RootNamespace>
<RootNamespace>Mbackup</RootNamespace>
</PropertyGroup>
<ItemGroup>
......
module MbackupTests
open NUnit.Framework
open Mbackup
[<SetUp>]
let Setup () =
()
[<Test>]
let TestDumb () =
Assert.Pass()
[<Test>]
let TestToMingwPath () =
Assert.That("/cygdrive/c/", Is.EqualTo(ToMingwPath "c:\\"))
Assert.That("/cygdrive/c/", Is.EqualTo(ToMingwPath "C:\\"))
Assert.That("/cygdrive/c/foo", Is.EqualTo(ToMingwPath "C:\\foo"))
Assert.That("/cygdrive/d/foo", Is.EqualTo(ToMingwPath "D:\\foo"))
Assert.That("/cygdrive/d/Foo", Is.EqualTo(ToMingwPath "D:\\Foo"))
Assert.That("/cygdrive/c/foo/bar/", Is.EqualTo(ToMingwPath "C:\\foo\\bar\\"))
Assert.That("/cygdrive/c/foo/bar/baz.txt", Is.EqualTo(ToMingwPath "C:\\foo\\bar\\baz.txt"))
Assert.That("/cygdrive/c/foo", Is.EqualTo(ToMingwPath "C:/foo"))
Assert.That("/cygdrive/c/foo/bar", Is.EqualTo(ToMingwPath "C:/foo/bar"))
Assert.That("/cygdrive/c/foo", Is.EqualTo(ToMingwPath "/c/foo"))
Assert.That("/cygdrive/D/foo", Is.EqualTo(ToMingwPath "/D/foo"))
Assert.That("/var/log", Is.EqualTo(ToMingwPath "/var/log"))
module Program = let [<EntryPoint>] main _ = 0
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RootNamespace>MbackupTests</RootNamespace>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="MbackupTest.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\mbackup-for-windows.fsproj" />
</ItemGroup>
</Project>
......@@ -30,6 +30,8 @@ Time-stamp: <2019-11-12>
https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/literals
[|' '|] is an array of character, length is 1.
F# list is not the same as array. You can convert array to list via Array.toList
String Class (System) | Microsoft Docs
https://docs.microsoft.com/en-us/dotnet/api/system.string?view=netframework-4.8
Environment.SpecialFolder
https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=netframework-4.8
ApplicationData
......@@ -53,9 +55,34 @@ Time-stamp: <2019-11-12>
- test run in console and scheduled task.
- create an installer. The installer should add scheduled task on install and
delete scheduled task on removal.
- problems
- how to write unit test in F#?
Unit testing F# in .NET Core with dotnet test and NUnit - .NET Core | Microsoft Docs
https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-fsharp-with-nunit
mkdir mbackup-tests
cd mbackup-tests
dotnet new nunit -lang F#
//wait.
dotnet test
dotnet add reference ../mbackup-for-windows.fsproj
dotnet build # this will build both ref project and test project.
dotnet test
-
** 2019-11-12 make code work in a specific dir. then create an installer.
- install to %programfiles%
- config is saved to %appdata% roaming dir.
- config is installed/saved to %appdata% roaming dir.
- problems
- config should be system wide. %appdata% is per-user dir.
where should I save global config file in windows 10?
Windows uses the %APPDATA% directory for user specific application
configuration files. The %PROGRAMDATA% folder is used for system wide
application configuration files, though it appears that Windows Store
apps may not be able to use %PROGRAMDATA%.
C:\ProgramData\mbackup\mbackup-default.list
- on B75I3, rsync is here.
D:\downloads\apps\rsync-w64-3.1.3-2-standalone\usr\bin\rsync.exe
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment