-
Notifications
You must be signed in to change notification settings - Fork 177
Feature/info option #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/info option #282
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Xunit; | ||
using System.Text.RegularExpressions; | ||
|
||
|
||
namespace Dotnet.Script.Tests | ||
{ | ||
public class EnvironmentTests | ||
{ | ||
[Fact] | ||
public void ShouldPrintVersionNumber() | ||
{ | ||
var result = ScriptTestRunner.Default.Execute("--version"); | ||
Assert.Equal(0, result.exitCode); | ||
Assert.Matches(@"\d*.\d*.\d*", result.output); | ||
|
||
result = ScriptTestRunner.Default.Execute("-v"); | ||
Assert.Equal(0, result.exitCode); | ||
Assert.Matches(@"\d*.\d*.\d*", result.output); | ||
} | ||
|
||
[Fact] | ||
public void ShouldPrintInfo() | ||
{ | ||
var result = ScriptTestRunner.Default.Execute("--info"); | ||
Assert.Equal(0, result.exitCode); | ||
Assert.Contains("Version", result.output); | ||
Assert.Contains("Install location", result.output); | ||
Assert.Contains("Target framework", result.output); | ||
Assert.Contains("Platform identifier", result.output); | ||
Assert.Contains("Runtime identifier", result.output); | ||
} | ||
|
||
} | ||
} |
This file contains hidden or 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,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Dotnet.Script.DependencyModel.Environment; | ||
|
||
namespace Dotnet.Script.Tests | ||
{ | ||
public class ScriptTestRunner | ||
{ | ||
public static readonly ScriptTestRunner Default = new ScriptTestRunner(); | ||
|
||
private ScriptEnvironment _scriptEnvironment; | ||
|
||
private ScriptTestRunner() | ||
{ | ||
_scriptEnvironment = ScriptEnvironment.Default; | ||
} | ||
|
||
|
||
public (string output, int exitCode) Execute(params string[] arguments) | ||
{ | ||
var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments(arguments)); | ||
return result; | ||
} | ||
|
||
public int ExecuteInProcess(params string[] arguments) | ||
{ | ||
return Program.Main(arguments ?? Array.Empty<string>()); | ||
} | ||
|
||
public (string output, int exitCode) ExecuteFixture(string fixture, params string[] arguments) | ||
{ | ||
var pathToFixture = Path.Combine("..", "..", "..", "TestFixtures", fixture); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reuse |
||
var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments(new string[] { pathToFixture}.Concat(arguments ?? Array.Empty<string>()).ToArray())); | ||
return result; | ||
} | ||
|
||
public int ExecuteFixtureInProcess(string fixture, params string[] arguments) | ||
{ | ||
var pathToFixture = Path.Combine("..", "..", "..", "TestFixtures", fixture); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not used. Can be removed as you call |
||
return Program.Main(new[] { GetPathToFixture(fixture) }.Concat(arguments ?? Array.Empty<string>()).ToArray()); | ||
} | ||
|
||
private static string GetPathToFixture(string fixture) | ||
{ | ||
return Path.Combine("..", "..", "..", "TestFixtures", fixture); | ||
} | ||
|
||
private string[] GetDotnetScriptArguments(params string[] arguments) | ||
{ | ||
string configuration; | ||
#if DEBUG | ||
configuration = "Debug"; | ||
#else | ||
configuration = "Release"; | ||
#endif | ||
var allArguments = new List<string>(new[] { "exec", Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "Dotnet.Script", "bin", configuration, _scriptEnvironment.TargetFramework, "dotnet-script.dll")}); | ||
if (arguments != null) | ||
{ | ||
allArguments.AddRange(arguments); | ||
} | ||
return allArguments.ToArray(); | ||
} | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an incorrect test. It says match 3 Unicode digit separated by anything and which appears anywhere in the output. What's more, since the Unicode digits are optional (
*
), it will also match 3 of anything! The right test would be:However, this test is still somewhat inaccurate. If you run
dotnet script --version
, the output is:The trouble here is that there is a leading blank line! The test shouldn't be passing but looks like it does because
ProcessHelper.RunAndCaptureOutput
trims the output:https://github.com/filipw/dotnet-script/blob/9bced12676415fd5eb1c69b95cf3765c71190358/src/Dotnet.Script.Tests/ProcessHelper.cs#L40
Ideally trimming should be decision of the caller.