Skip to content

Commit

Permalink
Merge branch 'master' into SpecFlowJsonSupport
Browse files Browse the repository at this point in the history
# Conflicts:
#	IdeIntegration/Generator/OutOfProcess/OutOfProcessExecutor.cs
  • Loading branch information
Andreas Willich committed Aug 20, 2018
2 parents 951c5d7 + abf338a commit bbbdae4
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 16 deletions.
48 changes: 42 additions & 6 deletions IdeIntegration/Generator/OutOfProcess/OutOfProcessExecutor.cs
Expand Up @@ -12,19 +12,24 @@ namespace TechTalk.SpecFlow.IdeIntegration.Generator.OutOfProcess
class OutOfProcessExecutor
{
private readonly Info _info;
private readonly IntegrationOptions _integrationOptions;
private readonly string _fullPathToExe;
private const string ExeName = "TechTalk.SpecFlow.VisualStudio.CodeBehindGenerator.exe";


public OutOfProcessExecutor(Info info)
{
_info = info;
_integrationOptions = integrationOptions;
string currentDirectory = Path.GetDirectoryName(GetType().Assembly.Location);
_fullPathToExe = Path.Combine(currentDirectory, ExeName);
}

public Result Execute(CommonParameters commonParameters)
public Result Execute(CommonParameters commonParameters, bool transferViaFile)
{
commonParameters.OutputDirectory = String.IsNullOrWhiteSpace(_integrationOptions.CodeBehindFileGeneratorExchangePath) ? Path.GetTempPath() : _integrationOptions.CodeBehindFileGeneratorExchangePath;


string commandLineParameters = CommandLine.Parser.Default.FormatCommandLine(commonParameters);

var processHelper = new ProcessHelper();
Expand All @@ -40,14 +45,45 @@ public Result Execute(CommonParameters commonParameters)

outputFileContent = FilterConfigDebugOutput(outputFileContent);

var firstLine = outputFileContent
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();

if (firstLine != null)
if (transferViaFile)
{
if (File.Exists(firstLine))
var firstLine = outputFileContent.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();

if (firstLine != null)
{
if (File.Exists(firstLine))
{
outputFileContent = File.ReadAllText(firstLine, Encoding.UTF8);
try
{
File.Delete(firstLine);
}
catch
{
// ignored
}
}
else
{
return new Result(1, "We could not find a data exchange file at the path " + firstLine + "" + Environment.NewLine +
Environment.NewLine + "Please open an issue at https://github.com/techtalk/SpecFlow/issues/" +
"Complete output: " + Environment.NewLine +
outputFileContent + Environment.NewLine+
Environment.NewLine+
"Command: " + _fullPathToExe + Environment.NewLine +
"Parameters: " + commonParameters);
}
}
else
{
outputFileContent = File.ReadAllText(firstLine, Encoding.UTF8);
return new Result(1, "Data Exchange via file did not worked, because we didn't receive a file path to read. " + Environment.NewLine +
Environment.NewLine + "Please open an issue at https://github.com/techtalk/SpecFlow/issues/" +
"Complete output: " + Environment.NewLine +
outputFileContent + Environment.NewLine +
Environment.NewLine +
"Command: " + _fullPathToExe + Environment.NewLine +
"Parameters: " + commonParameters);
}
}

Expand Down
Expand Up @@ -34,8 +34,9 @@ public TestGeneratorResult GenerateTestFile(FeatureFileInput featureFileInput, G
{
FeatureFile = featureFileInputFile,
ProjectSettingsFile = projectSettingsFile,
Debug = Debugger.IsAttached
});
Debug = Debugger.IsAttached,

}, true);


var output = FilterConfigDebugOutput(result);
Expand All @@ -52,7 +53,7 @@ public Version DetectGeneratedTestVersion(FeatureFileInput featureFileInput)
{
FeatureFile = featureFileInputFile,
Debug = Debugger.IsAttached
});
}, false);


if (result.ExitCode > 0)
Expand All @@ -72,7 +73,7 @@ public string GetTestFullPath(FeatureFileInput featureFileInput)
{
FeatureFile = featureFileInputFile,
Debug = Debugger.IsAttached
});
},false);

if (result.ExitCode > 0)
{
Expand Down
Expand Up @@ -23,7 +23,7 @@ public Version GetGeneratorVersion()
var result = _outOfProcessExecutor.Execute(new GetGeneratorVersionParameters()
{
Debug = Debugger.IsAttached
});
},false);

return Version.Parse(result.Output);
}
Expand Down
1 change: 1 addition & 0 deletions IdeIntegration/Options/IntegrationOptions.cs
Expand Up @@ -14,6 +14,7 @@ public class IntegrationOptions
public bool DisableRegenerateFeatureFilePopupOnConfigChange { get; set; }
public GenerationMode GenerationMode { get; set; }
public string CodeBehindFileGeneratorPath { get; set; }
public string CodeBehindFileGeneratorExchangePath { get; set; }
}

public enum TestRunnerTool
Expand Down
5 changes: 5 additions & 0 deletions SpecFlow.VisualStudio.2017.sln
Expand Up @@ -29,6 +29,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechTalk.SpecFlow.RemoteApp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechTalk.SpecFlow.VisualStudio.CodeBehindGenerator", "TechTalk.SpecFlow.VisualStudio.CodeBehindGenerator\TechTalk.SpecFlow.VisualStudio.CodeBehindGenerator.csproj", "{5351E241-2B8B-4D04-8999-5E3A79E8DD64}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{93B345A8-B526-4B75-BF9A-930712FFC76E}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Expand Up @@ -45,7 +45,7 @@ public int GenerateTestFile(GenerateTestFileParameters opts)
outputFileContent = GenerateError(testGeneratorResult, codeDomHelper);
}

Console.WriteLine(WriteTempFile(outputFileContent));
Console.WriteLine(WriteTempFile(opts, outputFileContent));

return 0;
}
Expand All @@ -56,9 +56,9 @@ public int GenerateTestFile(GenerateTestFileParameters opts)
}
}

private string WriteTempFile(string content)
private string WriteTempFile(GenerateTestFileParameters opts, string content)
{
var fileName = Path.GetTempFileName();
var fileName = Path.Combine(opts.OutputDirectory, Path.GetRandomFileName());
File.WriteAllText(fileName, content, Encoding.UTF8);
return fileName;
}
Expand Down
Expand Up @@ -6,5 +6,8 @@ public class CommonParameters
{
[Option]
public bool Debug { get; set; }

[Option]
public string OutputDirectory { get; set; }
}
}
Expand Up @@ -10,5 +10,7 @@ public class GenerateTestFileParameters : CommonParameters

[Option]
public string ProjectSettingsFile { get; set; }


}
}
Expand Up @@ -10,7 +10,7 @@ class Program
{
static int Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.OutputEncoding = System.Text.Encoding.UTF8;

if (args.Contains("--debug"))
{
Expand Down
4 changes: 3 additions & 1 deletion VsIntegration/Options/IntegrationOptionsProvider.cs
Expand Up @@ -28,6 +28,7 @@ internal class IntegrationOptionsProvider : IIntegrationOptionsProvider
public const bool DisableRegenerateFeatureFilePopupOnConfigChangeDefaultValue = false;
public const GenerationMode GenerationModeDefaultValue = GenerationMode.OutOfProcess;
public const string CodeBehindFileGeneratorPath = null;
public const string CodeBehindFileGeneratorExchangePath = null;


private DTE dte;
Expand Down Expand Up @@ -65,7 +66,8 @@ private static IntegrationOptions GetOptions(DTE dte)
TestRunnerTool = GetGeneralOption(dte, "TestRunnerTool", TestRunnerToolDefaultValue),
DisableRegenerateFeatureFilePopupOnConfigChange = GetGeneralOption(dte, "DisableRegenerateFeatureFilePopupOnConfigChange", DisableRegenerateFeatureFilePopupOnConfigChangeDefaultValue),
GenerationMode = GetGeneralOption(dte, "GenerationMode", GenerationModeDefaultValue),
CodeBehindFileGeneratorPath = GetGeneralOption(dte, "PathToCodeBehindGeneratorExe", CodeBehindFileGeneratorPath)
CodeBehindFileGeneratorPath = GetGeneralOption(dte, "PathToCodeBehindGeneratorExe", CodeBehindFileGeneratorPath),
CodeBehindFileGeneratorExchangePath = GetGeneralOption(dte, "CodeBehindFileGeneratorExchangePath", CodeBehindFileGeneratorExchangePath)
};
cachedOptions = options;
return options;
Expand Down
8 changes: 8 additions & 0 deletions VsIntegration/Options/OptionsPageGeneral.cs
Expand Up @@ -102,6 +102,12 @@ public bool EnableSyntaxColoring
[DefaultValue(IntegrationOptionsProvider.CodeBehindFileGeneratorPath)]
public string PathToCodeBehindGeneratorExe { get; set; }

[Category("Code Behind File Generation")]
[Description("Specifies the path where to save data exchange files (Default: %TEMP%)")]
[DisplayName("Data Exchange Path")]
[DefaultValue(IntegrationOptionsProvider.CodeBehindFileGeneratorPath)]
public string CodeBehindFileGeneratorExchangePath { get; set; }

public OptionsPageGeneral()
{
EnableAnalysis = IntegrationOptionsProvider.EnableAnalysisDefaultValue;
Expand All @@ -115,6 +121,8 @@ public OptionsPageGeneral()
TestRunnerTool = IntegrationOptionsProvider.TestRunnerToolDefaultValue;
DisableRegenerateFeatureFilePopupOnConfigChange = IntegrationOptionsProvider.DisableRegenerateFeatureFilePopupOnConfigChangeDefaultValue;
GenerationMode = IntegrationOptionsProvider.GenerationModeDefaultValue;
PathToCodeBehindGeneratorExe = IntegrationOptionsProvider.CodeBehindFileGeneratorPath;
CodeBehindFileGeneratorExchangePath = IntegrationOptionsProvider.CodeBehindFileGeneratorExchangePath;
}

public override void SaveSettingsToStorage()
Expand Down

0 comments on commit bbbdae4

Please sign in to comment.