11using Microsoft . VisualStudio . TestTools . UnitTesting ;
22using System ;
3+ using System . Collections . Generic ;
34using System . IO ;
4- using System . Text ;
55using System . Linq ;
6- using System . Runtime . InteropServices ;
7- using System . Collections . Generic ;
6+ using System . Text ;
87
98namespace Typewriter . Test
109{
11- [ TestClass ]
12- public class CSharpMultipleNamespaceSupportTests
10+ // supported test languages
11+ public enum TestLanguage
1312 {
14- private const string OutputDirectoryName = "OutputDirectory" ;
15- private const string TestDataCSharpDirectoryName = "TestDataCSharp" ;
13+ CSharp ,
14+ Java
15+ }
16+
17+ public static class MultipleNamespacesTestRunner
18+ {
19+ private const string OutputDirectoryPrefix = "OutputDirectory" ;
20+ private const string TestDataDirectoryPrefix = "TestData" ;
1621 private const string MetadataDirectoryName = "Metadata" ;
1722
18- [ TestMethod ]
19- public void Test ( )
23+ public static void Run ( TestLanguage language )
2024 {
2125 // Arrange
26+ var languageStr = language . ToString ( ) ;
27+ var outputDirectoryName = OutputDirectoryPrefix + languageStr ;
28+ var testDataDirectoryName = TestDataDirectoryPrefix + languageStr ;
29+
2230 var currentDirectory = Directory . GetCurrentDirectory ( ) ;
23- var outputDirectory = Path . Combine ( currentDirectory , OutputDirectoryName ) ;
24- var dataDirectory = Path . Combine ( currentDirectory , TestDataCSharpDirectoryName ) ;
31+ var outputDirectory = Path . Combine ( currentDirectory , outputDirectoryName ) ;
32+ var dataDirectory = Path . Combine ( currentDirectory , testDataDirectoryName ) ;
2533 var metadataFile = Path . Combine ( currentDirectory , MetadataDirectoryName , "MetadataMultipleNamespaces.xml" ) ;
26- var typewriterParameters = $ "-v Info -m { metadataFile } -o { outputDirectory } -g Files";
34+ var typewriterParameters = $ "-v Info -m { metadataFile } -o { outputDirectory } -g Files -l { languageStr } ";
2735
2836 // Act
2937 if ( Directory . Exists ( outputDirectory ) )
@@ -36,7 +44,7 @@ public void Test()
3644 // Assert
3745 var testOutputBuilder = new StringBuilder ( ) ;
3846 var errorCounter = 0 ;
39- foreach ( var ( expectedFilePath , actualOutputFilePath ) in GetFilePaths ( dataDirectory ) )
47+ foreach ( var ( expectedFilePath , actualOutputFilePath ) in GetFilePaths ( language , dataDirectory , testDataDirectoryName , outputDirectoryName ) )
4048 {
4149 if ( File . Exists ( actualOutputFilePath ) )
4250 {
@@ -56,7 +64,7 @@ public void Test()
5664 dataDirectory ,
5765 outputDirectory ,
5866 string . Empty ,
59- $ "If the changes are expected, please replace the contents of { TestDataCSharpDirectoryName } with the contents of { OutputDirectoryName } .",
67+ $ "If the changes are expected, please replace the contents of { testDataDirectoryName } with the contents of { outputDirectoryName } .",
6068 string . Empty ,
6169 "Details of failures:" ) ;
6270
@@ -90,11 +98,24 @@ private static void CompareFiles(StringBuilder testOutputBuilder, string expecte
9098 /// converts expected file paths into actual output file paths as well for a later diff.
9199 /// </summary>
92100 /// <param name="dataDirectory">Data directory full path</param>
93- /// <returns>Pairs of expected and actual file paths as an enumerable</returns>
94- private static IEnumerable < ( string , string ) > GetFilePaths ( string dataDirectory )
101+ /// <param name="testDataDirectoryName">test data directory name, e.g. TestDataCSharp</param>
102+ /// <param name="outputDirectoryName">output directory name, e.g. OutputDirectoryCSharp</param>
103+ /// <returns></returns>
104+ private static IEnumerable < ( string , string ) > GetFilePaths ( TestLanguage language , string dataDirectory , string testDataDirectoryName , string outputDirectoryName )
95105 {
96- return from file in new DirectoryInfo ( dataDirectory ) . GetFiles ( "*.cs" , SearchOption . AllDirectories )
97- let actualOutputFilePath = file . FullName . Replace ( TestDataCSharpDirectoryName , OutputDirectoryName )
106+ string extension = string . Empty ;
107+ switch ( language )
108+ {
109+ case TestLanguage . CSharp :
110+ extension = "*.cs" ;
111+ break ;
112+ case TestLanguage . Java :
113+ extension = "*.java" ;
114+ break ;
115+ }
116+
117+ return from file in new DirectoryInfo ( dataDirectory ) . GetFiles ( extension , SearchOption . AllDirectories )
118+ let actualOutputFilePath = file . FullName . Replace ( testDataDirectoryName , outputDirectoryName )
98119 let expectedFilePath = file . FullName
99120 select ( expectedFilePath , actualOutputFilePath ) ;
100121 }
0 commit comments