Skip to content

Commit

Permalink
--select-{class,method,trait-condition} options
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Jun 27, 2019
1 parent b8a1125 commit 69fbdfd
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 29 deletions.
95 changes: 72 additions & 23 deletions Assets/Scripts/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,55 @@ public class EntryPoint : MonoBehaviour
{
private static readonly OptionSet Options = new OptionSet
{
{
"c|select-class=",
"Select a test class by its fully qualified name, and exclude " +
"other classes. This option can be used multiple times, and " +
"all specified classes (and others selected by -m/--select-method " +
"and -t/--select-trait-condition options) are included together.",
className => SelectedClasses.Add(className)
},
{
"m|select-method=",
"Select a test method by its fully qualified name, and exclude " +
"other methods. This option can be used multiple times, and " +
"all specified methods (and others selected by -c/--select-class " +
"and -t/--select-trait-condition options) are included together.",
method => SelectedMethods.Add(method)
},
{
"t|select-trait-condition=",
"Select a trait condition (e.g., `-T TraitName=value') and exclude " +
"others. This option can be used multiple times, and " +
"all specified methods (and others selected by -c/--select-class " +
"and -m/--select-method options) are included together.",
traitCondition =>
SelectedTraitConditions.Add(ParseTraitCondition(traitCondition))
},
{
"C|exclude-class=",
"Exclude a test class by its fully qualified name. " +
"This option can be used multiple times.",
"This option can be used multiple times. " +
"Prior to -c/--select-class, -m/--select-method, and " +
"-t/--select-trait-condition options.",
className => ExcludedClasses.Add(className)
},
{
"M|exclude-method=",
"Exclude a test method by its fully qualified name. " +
"This option can be used multiple times.",
"This option can be used multiple times. " +
"Prior to -c/--select-class, -m/--select-method, and " +
"-t/--select-trait-condition options.",
method => ExcludedMethods.Add(method)
},
{
"T|exclude-trait-condition=",
"Exclude a trait condition (e.g., `-T TraitName=value'). " +
"This option can be used multiple times.",
"This option can be used multiple times. " +
"Prior to -c/--select-class, -m/--select-method, and " +
"-t/--select-trait-condition options.",
traitCondition =>
{
int equal = traitCondition.IndexOf('=');
string traitName, value;
if (equal < 0)
{
traitName = traitCondition;
value = string.Empty;
}
else
{
traitName = traitCondition.Substring(0, equal);
value = traitCondition.Substring(equal + 1);
}
ExcludedTraitConditions.Add((traitName, value));
}
ExcludedTraitConditions.Add(ParseTraitCondition(traitCondition))
},
{
"h|help",
Expand All @@ -59,8 +76,27 @@ public class EntryPoint : MonoBehaviour
static readonly ISet<string> ExcludedMethods = new HashSet<string>();
static readonly ISet<(string, string)> ExcludedTraitConditions =
new HashSet<(string, string)>();

static readonly ISet<string> SelectedClasses = new HashSet<string>();
static readonly ISet<string> SelectedMethods = new HashSet<string>();
static readonly ISet<(string, string)> SelectedTraitConditions =
new HashSet<(string, string)>();
private static bool Help { get; set; }= false;

private static (string, string) ParseTraitCondition( string traitCondition)
{
int equal = traitCondition.IndexOf('=');
if (equal < 0)
{
return (traitCondition, string.Empty);
}

return (
traitCondition.Substring(0, equal),
traitCondition.Substring(equal + 1)
);
}

int ExitCode { get; set; } = 0;

void Start()
Expand Down Expand Up @@ -200,12 +236,25 @@ static IEnumerable<ITestCase> FilterTestCases(IList<ITestCase> testCases) =>
ITestMethod method = t.TestMethod;
string className = method.TestClass.Class.Name;
string methodName = $"{className}.{method.Method.Name}";
return !ExcludedClasses.Contains(className) &&
bool selected = true;
bool IsSatisfied((string, string) pair) =>
t.Traits.ContainsKey(pair.Item1) &&
t.Traits[pair.Item1].Contains(pair.Item2);
if (SelectedClasses.Any() ||
SelectedMethods.Any() ||
SelectedTraitConditions.Any())
{
selected =
SelectedClasses.Contains(className) ||
SelectedMethods.Contains(methodName) ||
SelectedTraitConditions.Any(IsSatisfied);
}
return selected && !ExcludedClasses.Contains(className) &&
!ExcludedMethods.Contains(methodName) &&
!ExcludedTraitConditions.Any(pair =>
t.Traits.ContainsKey(pair.Item1) &&
t.Traits[pair.Item1].Contains(pair.Item2)
);
!ExcludedTraitConditions.Any(IsSatisfied);
});

private void OnTest(TestInfo info)
Expand Down
1 change: 1 addition & 0 deletions ProjectSettings/GraphicsSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ GraphicsSettings:
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16002, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ from stable [Mono].

You can download the executable binaries from the [releases] page.

This program takes one or more *.dll* files and run tests in them, e.g.:
This program takes one or more *absolute* paths to .NET assembly files (*.dll*)
and run tests in them, e.g.:

~~~~ bash
./StandaloneLinux64 YourTests.dll
./StandaloneLinux64 "$(pwd)"/YourTests.dll
~~~~

~~~~ pwsh
StandaloneWindows64.exe YourTests.dll
StandaloneWindows64.exe C:\path\to\YourTests.dll
~~~~

It also takes several options like `-C`/`--exclude-class` and
It also takes several options like `-c`/`--select-class` and
`-T`/`--exclude-trait-condition`. See `--help` for details.

On macOS you need to invoke the actual executable binary in
*StandardOSX.app/Contents/MacOS/* directory, e.g.:

~~~~ bash
StandaloneOSX.app/Contents/MacOS/StandardOSX YourTests.dll
StandaloneOSX.app/Contents/MacOS/StandardOSX "$(pwd)"/YourTests.dll
~~~~

Note that *.dll* files to test should target on .NET Framework (e.g., `net461`),
Expand All @@ -46,7 +47,7 @@ Mono (e.g., `xterm-256color`) yet Unity player's built-in Mono runtime could
throw such an exception. You could work around this by setting it `xterm`:

~~~~ bash
TERM=xterm ./StandaloneLinux64 YourTests.dll
TERM=xterm ./StandaloneLinux64 "$(pwd)"/YourTests.dll
~~~~

See also the related issue on the Mono project:
Expand Down

0 comments on commit 69fbdfd

Please sign in to comment.