Skip to content

Commit 1839374

Browse files
committed
Merge pull request #782 from voiceofwisdom/watchchanges-pathfix
Fix for watching files via relative paths.
2 parents aeca224 + 5a6f4c6 commit 1839374

File tree

4 files changed

+70
-5
lines changed

4 files changed

+70
-5
lines changed

help/watch.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Add a new target named "Watch" to your build:
1414
Target "Watch" (fun _ ->
1515
use watcher = !! "docs/**/*.*" |> WatchChanges (fun changes ->
1616
tracefn "%A" changes
17-
RunTarget "GenerateDocs"
17+
Run "GenerateDocs"
1818
)
1919

2020
System.Console.ReadLine() |> ignore //Needed to keep FAKE from exiting
@@ -34,7 +34,7 @@ If you need to watch only a subset of the files, say you want to rerun tests as
3434
Target "Watch" (fun _ ->
3535
use watcher = !! "tests/**/bin/debug/*.dll" |> WatchChanges (fun changes ->
3636
tracefn "%A" changes
37-
RunTarget "RunTests"
37+
Run "RunTests"
3838
)
3939

4040
System.Console.ReadLine() |> ignore //Needed to keep FAKE from exiting

src/app/FakeLib/Globbing/FileSystem.fs

+9-3
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@ type FileIncludes =
2424

2525
/// Checks if a particular file is matched
2626
member this.IsMatch (path : string) =
27+
let fullDir pattern =
28+
if Path.IsPathRooted(pattern) then
29+
pattern
30+
else
31+
System.IO.Path.Combine(this.BaseDirectory, pattern)
32+
2733
let included =
2834
this.Includes
2935
|> Seq.exists(fun fileInclude ->
30-
Globbing.isMatch fileInclude path
36+
Globbing.isMatch (fullDir fileInclude) path
3137
)
3238
let excluded =
3339
this.Excludes
34-
|> Seq.exists(fun fileInclude ->
35-
Globbing.isMatch fileInclude path
40+
|> Seq.exists(fun fileExclude ->
41+
Globbing.isMatch (fullDir fileExclude) path
3642
)
3743

3844
included && not excluded
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Linq;
2+
using Fake;
3+
using Machine.Specifications;
4+
using Test.FAKECore.FileHandling;
5+
6+
namespace Test.FAKECore.Globbing
7+
{
8+
public class when_matching_files_to_patterns_using_filesystem : BaseFunctions
9+
{
10+
static void IsMatch(string include, string[] files)
11+
{
12+
var fi = FileSystem.Include(include).SetBaseDirectory("/root");
13+
foreach (var file in files)
14+
{
15+
fi.IsMatch(file).ShouldBeTrue();
16+
}
17+
}
18+
19+
static void IsMatchWithExclude(string include, string exclude, string[] files)
20+
{
21+
var fi = FileSystem.Include(include).ButNot(exclude).SetBaseDirectory("/root");
22+
foreach (var file in files)
23+
{
24+
fi.IsMatch(file).ShouldBeTrue();
25+
}
26+
}
27+
28+
static void IsNotMatch(string include, string[] files)
29+
{
30+
var fi = FileSystem.Include(include).SetBaseDirectory("/root");
31+
foreach (var file in files)
32+
{
33+
fi.IsMatch(file).ShouldBeFalse();
34+
}
35+
}
36+
37+
static void IsNotMatchWithExclude(string include, string exclude, string[] files)
38+
{
39+
var fi = FileSystem.Include(include).ButNot(exclude).SetBaseDirectory("/root");
40+
foreach (var file in files)
41+
{
42+
fi.IsMatch(file).ShouldBeFalse();
43+
}
44+
}
45+
46+
It should_match =
47+
() => IsMatch("foo.bar", new[] { "/root/foo.bar" });
48+
49+
It should_not_match =
50+
() => IsNotMatch("foo.bar", new[] { "foo.bar", "/other/foo.bar" });
51+
52+
It should_match_absolute =
53+
() => IsMatch("/other/**/*.*", new[] { "/other/foo.bar", "/other/sub/foo.bar" });
54+
55+
It should__not_match_absolute =
56+
() => IsNotMatch("/other/**/*.*", new[] { "foo.bar", "sub/foo.bar" });
57+
}
58+
}

src/test/Test.FAKECore/Test.FAKECore.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="FileHandling\CopyFileSpecs.cs" />
7272
<Compile Include="FixProjectFileSpecs.cs" />
7373
<Compile Include="CompareProjectFilesSpecs.cs" />
74+
<Compile Include="Globbing\FileIncludesSpecs.cs" />
7475
<Compile Include="Globbing\GlobbingSpecs.cs" />
7576
<Compile Include="Globbing\SampeWithParens\SampleWithParensSpecs.cs" />
7677
<Compile Include="Globbing\TestSample7\CountersRegressionSpecs.cs" />

0 commit comments

Comments
 (0)