-
-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specifying test generators to run through command-line (#307)
- Loading branch information
1 parent
7d4f40c
commit f1c637d
Showing
5 changed files
with
44 additions
and
28 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,33 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Generators.Output; | ||
|
||
namespace Generators | ||
{ | ||
public class ExerciseCollection : IEnumerable<Exercise> | ||
{ | ||
private readonly string[] _exerciseNames; | ||
|
||
public ExerciseCollection() => _exerciseNames = null; | ||
public ExerciseCollection(string[] exerciseNames) => _exerciseNames = exerciseNames; | ||
|
||
public IEnumerator<Exercise> GetEnumerator() => GetDefinedGenerators().GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
|
||
private IEnumerable<Exercise> GetDefinedGenerators() => | ||
from type in Assembly.GetEntryAssembly().GetTypes() | ||
where IsConcreteExercise(type) && ShouldBeIncluded(type) | ||
select (Exercise)Activator.CreateInstance(type); | ||
|
||
private static bool IsConcreteExercise(Type type) => typeof(Exercise).IsAssignableFrom(type) && !type.GetTypeInfo().IsAbstract; | ||
|
||
private bool ShouldBeIncluded(Type type) | ||
=> _exerciseNames == null || | ||
_exerciseNames.Contains(type.ToExerciseName(), StringComparer.OrdinalIgnoreCase) || | ||
_exerciseNames.Contains(type.Name, StringComparer.OrdinalIgnoreCase); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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