This repository has been archived by the owner on Jul 21, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scan gauge_additional_libs, some refactoring, fixes #58
- Loading branch information
Showing
18 changed files
with
387 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Copyright 2015 ThoughtWorks, Inc. | ||
// | ||
// This file is part of Gauge-CSharp. | ||
// | ||
// Gauge-CSharp is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Gauge-CSharp is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Gauge-CSharp. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using Gauge.CSharp.Core; | ||
using Gauge.CSharp.Runner.Wrappers; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace Gauge.CSharp.Runner.UnitTests | ||
{ | ||
[TestFixture] | ||
internal class AssemblyLocaterTests | ||
{ | ||
private readonly Mock<IDirectoryWrapper> _mockDirectoryWrapper = new Mock<IDirectoryWrapper>(); | ||
private readonly Mock<IFileWrapper> _mockFileWrapper = new Mock<IFileWrapper>(); | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
Environment.SetEnvironmentVariable("GAUGE_PROJECT_ROOT", Directory.GetCurrentDirectory()); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
Environment.SetEnvironmentVariable("GAUGE_ADDITIONAL_LIBS", null); | ||
Environment.SetEnvironmentVariable("GAUGE_PROJECT_ROOT", null); | ||
} | ||
|
||
[Test] | ||
public void ShouldGetAssembliesFromGaugeBin() | ||
{ | ||
var expectedAssemblies = new[] {"fooAssemblyLocation", "barAssemblyLocation"}; | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.dll", SearchOption.TopDirectoryOnly)) | ||
.Returns(expectedAssemblies); | ||
var assemblyLocater = new AssemblyLocater(_mockDirectoryWrapper.Object, _mockFileWrapper.Object); | ||
|
||
var assemblies = assemblyLocater.GetAllAssemblies(); | ||
|
||
Assert.AreEqual(expectedAssemblies, assemblies); | ||
} | ||
|
||
[Test] | ||
public void ShouldGetAssembliesFromGaugeAdditionalLibsEnvVar() | ||
{ | ||
Environment.SetEnvironmentVariable("GAUGE_ADDITIONAL_LIBS", "foo/"); | ||
var expectedAssemblies = new[] { "fooAssemblyLocation", "barAssemblyLocation" }; | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.Exists(Path.GetFullPath("foo/"))).Returns(true); | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.dll", SearchOption.TopDirectoryOnly)) | ||
.Returns(Enumerable.Empty<string>()); | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Path.GetFullPath("foo/"), "*.dll", SearchOption.TopDirectoryOnly)) | ||
.Returns(expectedAssemblies); | ||
|
||
var assemblyLocater = new AssemblyLocater(_mockDirectoryWrapper.Object, _mockFileWrapper.Object); | ||
|
||
var assemblies = assemblyLocater.GetAllAssemblies(); | ||
Assert.AreEqual(expectedAssemblies, assemblies); | ||
} | ||
|
||
[Test] | ||
public void ShouldAddAssembliyFromGaugeAdditionalLibFile() | ||
{ | ||
Environment.SetEnvironmentVariable("GAUGE_ADDITIONAL_LIBS", "foo.dll"); | ||
var expectedAssemblies = new[] { Path.GetFullPath("foo.dll") }; | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.dll", SearchOption.TopDirectoryOnly)) | ||
.Returns(Enumerable.Empty<string>()); | ||
_mockFileWrapper.Setup(wrapper => wrapper.Exists(Path.GetFullPath("foo.dll"))).Returns(true); | ||
var assemblyLocater = new AssemblyLocater(_mockDirectoryWrapper.Object, _mockFileWrapper.Object); | ||
|
||
var assemblies = assemblyLocater.GetAllAssemblies(); | ||
Assert.AreEqual(expectedAssemblies, assemblies); | ||
} | ||
|
||
[Test] | ||
public void ShouldAddAssembliesFromMultipleLocations() | ||
{ | ||
Environment.SetEnvironmentVariable("GAUGE_ADDITIONAL_LIBS", "foo.dll, foo/"); | ||
var expectedAssemblies = new[] { Path.GetFullPath("foo.dll"), "fooAssemblyLocation", "barAssemblyLocation" }; | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.Exists(Path.GetFullPath("foo/"))).Returns(true); | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.dll", SearchOption.TopDirectoryOnly)) | ||
.Returns(Enumerable.Empty<string>()); | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Path.GetFullPath("foo/"), "*.dll", SearchOption.TopDirectoryOnly)) | ||
.Returns(new []{"fooAssemblyLocation", "barAssemblyLocation"}); | ||
_mockFileWrapper.Setup(wrapper => wrapper.Exists(Path.GetFullPath("foo.dll"))).Returns(true); | ||
var assemblyLocater = new AssemblyLocater(_mockDirectoryWrapper.Object, _mockFileWrapper.Object); | ||
|
||
var assemblies = assemblyLocater.GetAllAssemblies(); | ||
|
||
Assert.AreEqual(expectedAssemblies, assemblies); | ||
} | ||
|
||
[Test] | ||
public void ShoulNotdAddAssembliesFromInvalidDirectory() | ||
{ | ||
Environment.SetEnvironmentVariable("GAUGE_ADDITIONAL_LIBS", "foo/"); | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.Exists(Path.GetFullPath("foo/"))).Returns(false); | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.dll", SearchOption.TopDirectoryOnly)) | ||
.Returns(Enumerable.Empty<string>()); | ||
|
||
var assemblyLocater = new AssemblyLocater(_mockDirectoryWrapper.Object, _mockFileWrapper.Object); | ||
|
||
var assemblies = assemblyLocater.GetAllAssemblies(); | ||
Assert.IsEmpty(assemblies); | ||
} | ||
|
||
[Test] | ||
public void ShouldNotAddAssembliesFromInvalidFile() | ||
{ | ||
Environment.SetEnvironmentVariable("GAUGE_ADDITIONAL_LIBS", "foo.dll"); | ||
_mockFileWrapper.Setup(wrapper => wrapper.Exists(Path.GetFullPath("foo.dll"))).Returns(false); | ||
_mockDirectoryWrapper.Setup(wrapper => wrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.dll", SearchOption.TopDirectoryOnly)) | ||
.Returns(Enumerable.Empty<string>()); | ||
|
||
var assemblyLocater = new AssemblyLocater(_mockDirectoryWrapper.Object, _mockFileWrapper.Object); | ||
|
||
var assemblies = assemblyLocater.GetAllAssemblies(); | ||
Assert.IsEmpty(assemblies); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2015 ThoughtWorks, Inc. | ||
// | ||
// This file is part of Gauge-CSharp. | ||
// | ||
// Gauge-CSharp is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Gauge-CSharp is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Gauge-CSharp. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Gauge.CSharp.Core; | ||
using Gauge.CSharp.Runner.Wrappers; | ||
using NLog; | ||
|
||
namespace Gauge.CSharp.Runner | ||
{ | ||
public class AssemblyLocater : IAssemblyLocater | ||
{ | ||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); | ||
private readonly IDirectoryWrapper _directoryWrapper; | ||
private readonly IFileWrapper _fileWrapper; | ||
|
||
public AssemblyLocater(IDirectoryWrapper directoryWrapper, IFileWrapper fileWrapper) | ||
{ | ||
_directoryWrapper = directoryWrapper; | ||
_fileWrapper = fileWrapper; | ||
} | ||
|
||
public IEnumerable<string> GetAllAssemblies() | ||
{ | ||
var assemblies = _directoryWrapper.EnumerateFiles(Utils.GetGaugeBinDir(), "*.dll", SearchOption.TopDirectoryOnly).ToList(); | ||
var gaugeAdditionalLibsPath = Environment.GetEnvironmentVariable("gauge_additional_libs"); | ||
if (string.IsNullOrEmpty(gaugeAdditionalLibsPath)) | ||
return assemblies; | ||
|
||
var additionalLibPaths = gaugeAdditionalLibsPath.Split(',').Select(s => Path.GetFullPath(s.Trim())); | ||
foreach (var libPath in additionalLibPaths) | ||
{ | ||
if (Path.HasExtension(libPath)) | ||
{ | ||
AddFile(libPath, assemblies); | ||
continue; | ||
} | ||
AddFilesFromDirectory(libPath, assemblies); | ||
} | ||
return assemblies; | ||
} | ||
|
||
private void AddFilesFromDirectory(string path, List<string> assemblies) | ||
{ | ||
if (!_directoryWrapper.Exists(path)) | ||
{ | ||
Logger.Warn("Path does not exist: {0}", path); | ||
return; | ||
} | ||
assemblies.AddRange(_directoryWrapper.EnumerateFiles(path, "*.dll", SearchOption.TopDirectoryOnly)); | ||
} | ||
|
||
private void AddFile(string path, List<string> assemblies) | ||
{ | ||
if (!_fileWrapper.Exists(path)) | ||
{ | ||
Logger.Warn("Path does not exist: {0}", path); | ||
return; | ||
} | ||
assemblies.Add(path); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.