Skip to content

Commit

Permalink
Allow test and reference settings to specify array of include and exc…
Browse files Browse the repository at this point in the history
…lude patterns
  • Loading branch information
mmanela committed Feb 22, 2015
1 parent fce8c13 commit 93f3d8e
Show file tree
Hide file tree
Showing 33 changed files with 274 additions and 110 deletions.
Binary file added Chutzpah.VS2013.sln.ide/edb.chk
Binary file not shown.
Binary file added Chutzpah.VS2013.sln.ide/edbres00001.jrs
Binary file not shown.
Binary file added Chutzpah.VS2013.sln.ide/edbres00002.jrs
Binary file not shown.
Binary file added Chutzpah.VS2013.sln.ide/storage.ide
Binary file not shown.
12 changes: 6 additions & 6 deletions Chutzpah/FileProbe.cs
Expand Up @@ -157,8 +157,8 @@ public IEnumerable<PathInfo> FindScriptFiles(ChutzpahTestSettingsFile chutzpahTe

foreach (var pathSettings in chutzpahTestSettings.Tests.Where(x => x != null))
{
var includePattern = NormalizeFilePath(pathSettings.Include);
var excludePattern = NormalizeFilePath(pathSettings.Exclude);
var includePatterns = pathSettings.Includes.Select(x => NormalizeFilePath(x)).ToList();
var excludePatterns = pathSettings.Excludes.Select(x => NormalizeFilePath(x)).ToList();


// The path we assume default to the chuzpah.json directory if the Path property is not set
Expand All @@ -181,10 +181,10 @@ public IEnumerable<PathInfo> FindScriptFiles(ChutzpahTestSettingsFile chutzpahTe

var childFiles = fileSystem.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
var validFiles = from file in childFiles
let normlizedFile = NormalizeFilePath(file)
where !IsTemporaryChutzpahFile(normlizedFile)
&& (includePattern == null || NativeImports.PathMatchSpec(normlizedFile, includePattern))
&& (excludePattern == null || !NativeImports.PathMatchSpec(normlizedFile, excludePattern))
let normalizedFile = NormalizeFilePath(file)
where !IsTemporaryChutzpahFile(normalizedFile)
&& (!includePatterns.Any() || includePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat)))
&& (!excludePatterns.Any() || !excludePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat)))
select file;


Expand Down
36 changes: 34 additions & 2 deletions Chutzpah/Models/SettingsFilePath.cs
@@ -1,7 +1,15 @@
using System.Collections.Generic;
namespace Chutzpah.Models
{
public abstract class SettingsFilePath
{

public SettingsFilePath()
{
Includes = new List<string>();
Excludes = new List<string>();
}

/// <summary>
/// The path of file/folder to include. This could be the path to one file or a folder.
/// In the case of a folder all files found in the folder are used.
Expand All @@ -11,12 +19,36 @@ public abstract class SettingsFilePath
/// <summary>
/// A glob expression of the paths to include. This is usefull when you specify the path as a folder
/// </summary>
public string Include { get; set; }
public string Include
{
set
{
Includes.Add(value);
}
}

/// <summary>
/// A glob expression of the paths to exclude. This is usefull when you specify the path as a folder
/// </summary>
public string Exclude { get; set; }
public string Exclude
{
set
{
Excludes.Add(value);
}
}

/// <summary>
/// Glob expressions of the paths to include.
/// </summary>
public ICollection<string> Includes { get; set; }

/// <summary>
/// Glob expressions of the paths to exclude.
/// </summary>
public ICollection<string> Excludes { get; set; }



/// <summary>
/// The settings file directory that this batch compile configuration came from
Expand Down
18 changes: 10 additions & 8 deletions Chutzpah/ReferenceProcessor.cs
Expand Up @@ -15,14 +15,16 @@ public class ReferencePathSettings
public ReferencePathSettings()
{
ExpandNestedReferences = true;
Includes = new List<string>();
Excludes = new List<string>();
}

public ReferencePathSettings(SettingsFileReference settingsFileReference)
{
ExpandNestedReferences = false;

Include = settingsFileReference.Include;
Exclude = settingsFileReference.Exclude;
Includes = settingsFileReference.Includes;
Excludes = settingsFileReference.Excludes;
IncludeInTestHarness = settingsFileReference.IncludeInTestHarness;
IsTestFrameworkFile = settingsFileReference.IsTestFrameworkFile;
}
Expand All @@ -34,8 +36,8 @@ public ReferencePathSettings(SettingsFileReference settingsFileReference)
/// </summary>
public bool ExpandNestedReferences { get; set; }

public string Include { get; set; }
public string Exclude { get; set; }
public ICollection<string> Includes { get; set; }
public ICollection<string> Excludes { get; set; }
public bool IncludeInTestHarness { get; set; }
public bool IsTestFrameworkFile { get; set; }
}
Expand Down Expand Up @@ -250,17 +252,17 @@ private static string GetAmdPath(string testHarnessDirectory, string filePath, s
string absoluteFolderPath = fileProbe.FindFolderPath(relativeReferencePath);
if (absoluteFolderPath != null)
{
var includePattern = FileProbe.NormalizeFilePath(pathSettings.Include);
var excludePattern = FileProbe.NormalizeFilePath(pathSettings.Exclude);
var includePatterns = pathSettings.Includes.Select(x => FileProbe.NormalizeFilePath(x)).ToList();
var excludePatterns = pathSettings.Excludes.Select(x => FileProbe.NormalizeFilePath(x)).ToList();

// Find all files in this folder including sub-folders. This can be ALOT of files.
// Only a subset of these files Chutzpah might understand so many of these will be ignored.
var childFiles = fileSystem.GetFiles(absoluteFolderPath, "*.*", SearchOption.AllDirectories);
var validFiles = from file in childFiles
let normalizedFile = FileProbe.NormalizeFilePath(file)
where !fileProbe.IsTemporaryChutzpahFile(file)
&& (includePattern == null || NativeImports.PathMatchSpec(normalizedFile, includePattern))
&& (excludePattern == null || !NativeImports.PathMatchSpec(normalizedFile, excludePattern))
&& (!includePatterns.Any() || includePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat)))
&& (!excludePatterns.Any() || !excludePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat)))
select file;

validFiles.ForEach(file => VisitReferencedFile(file, definition, discoveredPaths, referencedFiles, chutzpahTestSettings, pathSettings));
Expand Down
25 changes: 15 additions & 10 deletions Chutzpah/TestContextBuilder.cs
Expand Up @@ -118,6 +118,11 @@ public TestContext BuildContext(IEnumerable<PathInfo> files, TestOptions options
var pathString = string.Join(",", testedPaths.Where(x => !x.IsIncluded).Select(x => x.File.FullPath));
ChutzpahTracer.TraceInformation("Excluding test files {0} given chutzpah.json settings", pathString);
files = testedPaths.Where(x => x.IsIncluded).Select(x => x.File).ToList();

if (!files.Any())
{
return null;
}
}

string firstTestFileText;
Expand Down Expand Up @@ -285,8 +290,8 @@ private bool IsTestPathIncluded(string testFilePath, ChutzpahTestSettingsFile ch

foreach (var pathSettings in chutzpahTestSettings.Tests.Where(x => x != null))
{
var includePattern = FileProbe.NormalizeFilePath(pathSettings.Include);
var excludePattern = FileProbe.NormalizeFilePath(pathSettings.Exclude);
var includePatterns = pathSettings.Includes.Select(x => FileProbe.NormalizeFilePath(x)).ToList();
var excludePatterns = pathSettings.Excludes.Select(x => FileProbe.NormalizeFilePath(x)).ToList();

// The path we assume default to the chuzpah.json directory if the Path property is not set
var testPath = string.IsNullOrEmpty(pathSettings.Path) ? pathSettings.SettingsFileDirectory : pathSettings.Path;
Expand All @@ -310,27 +315,27 @@ private bool IsTestPathIncluded(string testFilePath, ChutzpahTestSettingsFile ch
{
if (testFilePath.Contains(folderPath))
{
var shouldIncludeFile = (includePattern == null || NativeImports.PathMatchSpec(testFilePath, includePattern))
&& (excludePattern == null || !NativeImports.PathMatchSpec(testFilePath, excludePattern));
var shouldIncludeFile = (!includePatterns.Any() || includePatterns.Any(pat => NativeImports.PathMatchSpec(testFilePath, pat)))
&& (!excludePatterns.Any() || !excludePatterns.Any(pat => NativeImports.PathMatchSpec(testFilePath, pat)));

if (shouldIncludeFile)
{
ChutzpahTracer.TraceInformation(
"Test file {0} matched folder {1} with include {2} and exclude {3} patterns from settings file",
"Test file {0} matched folder {1} with includes {2} and excludes {3} patterns from settings file",
testFilePath,
folderPath,
includePattern,
excludePattern);
string.Join(",", includePatterns),
string.Join(",", excludePatterns));
return true;
}
else
{
ChutzpahTracer.TraceInformation(
"Test file {0} did not match folder {1} with include {2} and exclude {3} patterns from settings file",
"Test file {0} did not match folder {1} with includes {2} and excludes {3} patterns from settings file",
testFilePath,
folderPath,
includePattern,
excludePattern);
string.Join(",", includePatterns),
string.Join(",", excludePatterns));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Chutzpah/TestFiles/Jasmine/v1/jasmine.html
Expand Up @@ -32,7 +32,7 @@
window.chutzpah.usingModuleLoader = true;
}

requirejs.config({
require.config({
map: {
'*': {
@@AMDModuleMap@@
Expand Down
2 changes: 1 addition & 1 deletion Chutzpah/TestFiles/Jasmine/v2/jasmine.html
Expand Up @@ -17,7 +17,7 @@
window.chutzpah.usingModuleLoader = true;
}

requirejs.config({
require.config({
map: {
'*': {
@@AMDModuleMap@@
Expand Down
2 changes: 1 addition & 1 deletion Chutzpah/TestFiles/Mocha/mocha.html
Expand Up @@ -25,7 +25,7 @@
window.chutzpah.usingModuleLoader = true;
}

requirejs.config({
require.config({
map: {
'*': {
@@AMDModuleMap@@
Expand Down
2 changes: 1 addition & 1 deletion Chutzpah/TestFiles/QUnit/qunit.html
Expand Up @@ -16,7 +16,7 @@
window.chutzpah.usingModuleLoader = true;
}

requirejs.config({
require.config({
map: {
'*': {
@@AMDModuleMap@@
Expand Down
2 changes: 1 addition & 1 deletion Chutzpah/TestRunner.cs
Expand Up @@ -477,7 +477,7 @@ private IEnumerable<PathInfo> FindTestFiles(IEnumerable<string> testPaths, TestO
processStream => testCaseStreamReaderFactory.Create().Read(processStream, options, testContext, callback, m_debugEnabled);
var processResult = process.RunExecutableAndProcessOutput(headlessBrowserPath, runnerArgs, streamProcessor);

HandleTestProcessExitCode(processResult.ExitCode, testContext.FirstInputTestFile, processResult.Model.Select(x => x.Errors).First(), callback);
HandleTestProcessExitCode(processResult.ExitCode, testContext.FirstInputTestFile, processResult.Model.Select(x => x.Errors).FirstOrDefault(), callback);

return processResult.Model;
}
Expand Down
11 changes: 11 additions & 0 deletions Facts.Integration/Execution.cs
Expand Up @@ -926,6 +926,17 @@ public void will_use_tests_setting_to_filter_tests()
Assert.Equal(4, result.TotalCount);
}

[Fact]
public void will_use_tests_setting_with_multiple_include_excludes_to_filter_tests()
{
var testRunner = TestRunner.Create();
var result = testRunner.RunTests(@"JS\Test\TestSettings\TestPathsMultipleIncludeExclude", new ExceptionThrowingRunnerCallback());

Assert.Equal(0, result.FailedCount);
Assert.Equal(4, result.PassedCount);
Assert.Equal(4, result.TotalCount);
}

[Fact]
public void will_use_tests_setting_to_discover_tests()
{
Expand Down
21 changes: 21 additions & 0 deletions Facts.Integration/Facts.Integration.csproj
Expand Up @@ -366,6 +366,24 @@
<Content Include="JS\Test\requirejs\WithSettings\chutzpah.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="JS\Test\TestSettings\TestPathsMultipleIncludeExclude\Dir1\test3.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="JS\Test\TestSettings\TestPathsMultipleIncludeExclude\Dir1\test4.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="JS\Test\TestSettings\TestPathsMultipleIncludeExclude\Dir2\test.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="JS\Test\TestSettings\TestPathsMultipleIncludeExclude\Dir3\test.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="JS\Test\TestSettings\TestPathsMultipleIncludeExclude\test1.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="JS\Test\TestSettings\TestPathsMultipleIncludeExclude\test2.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="JS\Test\TestSettings\TestPaths\Dir1\test4.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -474,6 +492,9 @@
<None Include="JS\Test\TestSettings\Batching\Ambiguous1\chutzpah.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="JS\Test\TestSettings\TestPathsMultipleIncludeExclude\chutzpah.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="JS\Test\TypeScript\basic-mocha-bdd.ts">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
14 changes: 7 additions & 7 deletions Facts.Integration/JS/Test/TestSettings/TestPaths/chutzpah.json
@@ -1,8 +1,8 @@
{
"Tests": [
{ "Include": "*test1*" },
{ "Path": "Dir3/test.js"},
{ "Path": "Dir1", "Include": "*.js", "Exclude": "*test4.js" },
{ "Path": "Dir2" }
]
{
"Tests": [
{ "Include": "*test1*" },
{ "Path": "Dir3/test.js"},
{ "Path": "Dir1", "Include": "*.js", "Exclude": "*test4.js" },
{ "Path": "Dir2" }
]
}
@@ -0,0 +1,3 @@
test("TestPathTest", function () {
ok(true);
});
@@ -0,0 +1,3 @@
test("TestPathTest", function () {
ok(true);
});
@@ -0,0 +1,3 @@
test("TestPathTest", function () {
ok(true);
});
@@ -0,0 +1,3 @@
test("TestPathTest", function () {
ok(true);
});
@@ -0,0 +1,5 @@
{
"Tests": [
{ "Includes": [ "*test1*", "*Dir1/*.js", "*Dir2/*.js", "*Dir3/test.js" ], "Excludes": [ "*Dir1/test4.js" ] }
]
}
@@ -0,0 +1,3 @@
test("TestPathTest", function() {
ok(true);
});
@@ -0,0 +1,3 @@
test("TestPathTest", function () {
ok(true);
});
39 changes: 39 additions & 0 deletions Facts/Library/FileProbeFacts.cs
Expand Up @@ -587,6 +587,45 @@ public void Will_return_paths_from_folder_which_match_include_exclude_patterns()
Assert.Contains(@"somefolder\src\d.ts", fullPaths);
}

public void Will_return_paths_from_folder_which_match_includes_excludes_patterns()
{
var probe = new TestableFileProbe();
probe.Mock<IFileSystemWrapper>().Setup(x => x.GetFullPath(It.IsAny<string>())).Returns<string>(x => x);
probe.Mock<IFileSystemWrapper>().Setup(x => x.FileExists(It.IsAny<string>())).Returns(false);
probe.Mock<IFileSystemWrapper>().Setup(x => x.FolderExists(It.IsAny<string>())).Returns(true);
probe.Mock<IFileSystemWrapper>().Setup(x => x.GetFiles(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<SearchOption>()))
.Returns(new[]
{
"somefolder/src/a.js",
"somefolder/src/B.JS",
"somefolder2/src/c.ts",
"somefolder2/src/c.js",
"somefolder\\src\\d.ts",
"somefolder/e.ts"
});
var setting = new ChutzpahTestSettingsFile
{
SettingsFileDirectory = "dir",
Tests = new List<SettingsFileTestPath>
{
new SettingsFileTestPath
{
Path = "someFolder",
Includes = new []{"*somefolder/src/*", "*somefolder2/*"},
Excludes = new []{"*somefolder/*.js","*somefolder2/*.js"},
SettingsFileDirectory = "dir"
}
}
};
var res = probe.ClassUnderTest.FindScriptFiles(setting);

Assert.Equal(2, res.Count());
var fullPaths = res.Select(x => x.FullPath);
Assert.Contains(@"somefolder2/src/c.ts", fullPaths);
Assert.Contains(@"somefolder\src\d.ts", fullPaths);
}



}
}
Expand Down

0 comments on commit 93f3d8e

Please sign in to comment.