@@ -11,16 +11,23 @@ namespace tSQLtTestAdapter
1111{
1212 [ DefaultExecutorUri ( Constants . ExecutorUriString ) ]
1313 [ FileExtension ( Constants . FileExtension ) ]
14- public class XmlTestDiscoverer : ITestDiscoverer
14+ public class tSQLtTestDiscoverer : ITestDiscoverer
1515 {
1616 private static readonly object _lock = new object ( ) ;
1717 private static readonly TestCache _tests = new TestCache ( ) ;
1818
1919 private static readonly List < Regex > _includePaths = new List < Regex > ( ) ;
20+ private IMessageLogger _logger ;
21+ private bool _debug ;
2022
2123 public void DiscoverTests ( IEnumerable < string > sources , IDiscoveryContext discoveryContext , IMessageLogger logger , ITestCaseDiscoverySink discoverySink )
2224 {
23- if ( string . IsNullOrEmpty ( new RunSettings ( discoveryContext . RunSettings ) . GetSetting ( "TestDatabaseConnectionString" ) ) )
25+ var settings = new RunSettings ( discoveryContext . RunSettings ) ;
26+ _logger = logger ;
27+
28+ _debug = settings . GetSetting ( "tSQLt-TestAdapter-Debug" ) ? . ToLowerInvariant ( ) == "true" ;
29+
30+ if ( string . IsNullOrEmpty ( settings . GetSetting ( "TestDatabaseConnectionString" ) ) )
2431 {
2532 logger . SendMessage ( TestMessageLevel . Informational , "No RunSettings TestDatabaseConnectionString set - will not attempt to discover tests.." ) ;
2633 return ;
@@ -29,11 +36,10 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
2936 logger . SendMessage ( TestMessageLevel . Informational , "tSQLt Test Adapter, searching for tests..." ) ;
3037
3138 var includePath = new RunSettings ( discoveryContext . RunSettings ) . GetSetting ( "IncludePath" ) ;
32- SetPathFilter ( includePath ) ;
33-
39+
3440 lock ( _lock )
3541 {
36- GetTests ( sources , discoverySink ) ;
42+ GetTests ( sources , discoverySink , includePath ) ;
3743 }
3844
3945 if ( _tests != null )
@@ -42,7 +48,7 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
4248 logger . SendMessage ( TestMessageLevel . Informational , "tSQLt Test Adapter, searching for tests...done - none found" ) ;
4349 }
4450
45- public static void SetPathFilter ( string includePath )
51+ public void SetPathFilter ( string includePath )
4652 {
4753 _includePaths . Clear ( ) ;
4854
@@ -52,20 +58,32 @@ public static void SetPathFilter(string includePath)
5258 {
5359 foreach ( var part in includePath . Split ( ';' ) )
5460 {
61+ Debug ( $ "tSQLt-Test-Adapter: Adding filter: { part } ") ;
5562 _includePaths . Add ( new Regex ( part ) ) ;
5663 }
5764 }
5865 else
5966 {
67+ Debug ( $ "tSQLt-Test-Adapter: Adding filter: { includePath } ") ;
6068 _includePaths . Add ( new Regex ( includePath ) ) ;
6169 }
6270 }
6371 }
6472
65- public static List < TestCase > GetTests ( IEnumerable < string > sources , ITestCaseDiscoverySink discoverySink )
73+ private void Debug ( string message )
74+ {
75+ if ( _debug )
76+ _logger . SendMessage ( TestMessageLevel . Informational , message ) ;
77+ }
78+
79+
80+ public List < TestCase > GetTests ( IEnumerable < string > sources , ITestCaseDiscoverySink discoverySink , string filter )
6681 {
6782 lock ( _lock )
6883 {
84+ if ( ! String . IsNullOrEmpty ( filter ) )
85+ SetPathFilter ( filter ) ;
86+
6987 var tests = new List < TestCase > ( ) ;
7088
7189 foreach ( var source in sources )
@@ -81,15 +99,15 @@ public static List<TestCase> GetTests(IEnumerable<string> sources, ITestCaseDisc
8199 foreach ( var test in testClass . Tests )
82100 {
83101 var testCase = new TestCase ( string . Format ( "{0}.{1}" , testClass . Name , test . Name ) , tSQLtTestExecutor . ExecutorUri , test . Path ) ;
84-
85-
102+
86103 testCase . LineNumber = test . Line ;
87104 testCase . CodeFilePath = test . Path ;
88105
89106 tests . Add ( testCase ) ;
90-
107+ Debug ( $ "tSQLt-Test-Adapter Adding test case { testClass . Name } . { test . Name } " ) ;
91108 if ( discoverySink != null )
92109 {
110+ Debug ( $ "tSQLt-Test-Adapter Adding test case { testClass . Name } .{ test . Name } - SENDING TO discoverSink") ;
93111 discoverySink . SendTestCase ( testCase ) ;
94112 }
95113 }
@@ -101,7 +119,7 @@ public static List<TestCase> GetTests(IEnumerable<string> sources, ITestCaseDisc
101119 tcClass . CodeFilePath = testClass . Path ;
102120
103121 tests . Add ( tcClass ) ;
104-
122+ Debug ( $ "tSQLt-Test-Adapter Adding test case { testClass . Name } - SENDING test class wrapper" ) ;
105123 discoverySink . SendTestCase ( tcClass ) ;
106124 }
107125 }
0 commit comments