9
9
using System ;
10
10
using System . Collections . Generic ;
11
11
using System . IO ;
12
- using System . Runtime . InteropServices ;
13
12
using System . Text ;
14
13
using System . Text . RegularExpressions ;
15
14
using System . Threading ;
@@ -31,12 +30,8 @@ protected BaseTestBaseline(ITestOutputHelper output) : base(output)
31
30
32
31
internal const string RawSuffix = ".raw" ;
33
32
private const string LogSuffix = ".log" ;
34
- private readonly string _baselineRootRelPath = Path . Combine ( TestDir , "BaselineOutput" , BuildString ) ; // Relative to Root.
35
33
private readonly string _logRootRelPath = Path . Combine ( "Logs" , BuildString ) ; // Relative to OutDir.
36
- private readonly string ScopeRootRelPath = Path . Combine ( "Samples" , "scope" ) ; // Root of files required for Scope related tests. Used primarily for local runs
37
- private readonly string TestExtDir = Path . Combine ( "Tests" , "Ext" ) ; // Directory with external binaries checked in. Eg libvw.dll
38
34
39
- private const string SamplesRootRelPath = @"Samples" ; // Root location of Samples. Used primarily for local runs
40
35
private const string TestDir = @"test" ;
41
36
42
37
private const string DataRootRegExp = @"[a-z]:\\[^/\t ]+\\test\\data" + @"\\[^/\t ]+" ;
@@ -70,10 +65,9 @@ protected BaseTestBaseline(ITestOutputHelper output) : base(output)
70
65
/// </summary>
71
66
protected const string ProgressLogLine = "--- Progress log ---" ;
72
67
73
- private static readonly char [ ] _seperators = { '\t ' , ' ' , '=' , '%' , '(' , ')' } ;
74
-
75
- // Full paths to the directories.
76
- private string _baseDir ;
68
+ // Full paths to the baseline directories.
69
+ private string _baselineCommonDir ;
70
+ private string _baselineBuildStringDir ;
77
71
78
72
// The writer to write to test log files.
79
73
protected StreamWriter LogWriter ;
@@ -86,13 +80,15 @@ protected override void Initialize()
86
80
base . Initialize ( ) ;
87
81
88
82
// Create the output and log directories.
89
- Contracts . Check ( Directory . Exists ( Path . Combine ( RootDir , TestDir , "BaselineOutput" ) ) ) ;
83
+ string baselineRootDir = Path . Combine ( RootDir , TestDir , "BaselineOutput" ) ;
84
+ Contracts . Check ( Directory . Exists ( baselineRootDir ) ) ;
85
+
86
+ _baselineCommonDir = Path . Combine ( baselineRootDir , "Common" ) ;
87
+ _baselineBuildStringDir = Path . Combine ( baselineRootDir , BuildString ) ;
88
+
90
89
string logDir = Path . Combine ( OutDir , _logRootRelPath ) ;
91
90
Directory . CreateDirectory ( logDir ) ;
92
91
93
- // Find the sample data and baselines.
94
- _baseDir = Path . Combine ( RootDir , _baselineRootRelPath ) ;
95
-
96
92
string logPath = Path . Combine ( logDir , FullTestName + LogSuffix ) ;
97
93
LogWriter = OpenWriter ( logPath ) ;
98
94
_passed = true ;
@@ -125,19 +121,6 @@ protected override void Cleanup()
125
121
126
122
protected bool IsPassing { get { return _passed ; } }
127
123
128
- // Return the location of the local Samples folder
129
- // Used primarily for local Scope runs
130
- protected string SamplesDir { get { return Path . Combine ( RootDir , SamplesRootRelPath ) ; } }
131
-
132
- // Return the location of the local scope folder under Samples. Used primarily
133
- // by Scope scripts and for Scope tests
134
- protected string ScopeSamplesDir { get { return Path . Combine ( RootDir , ScopeRootRelPath ) ; } }
135
-
136
- // Return the local of the directory where external binaries for test purposes are located
137
- protected string ExternalTestBinariesDir { get { return Path . Combine ( RootDir , TestExtDir ) ; } }
138
-
139
- protected string TestDirectory { get { return Path . Combine ( RootDir , TestDir ) ; } }
140
-
141
124
// Called by a test to signal normal completion. If this is not called before the
142
125
// TestScope is disposed, we assume the test was aborted.
143
126
protected void Done ( )
@@ -198,31 +181,28 @@ protected void Log(string fmt, params object[] args)
198
181
Output . WriteLine ( fmt , args ) ;
199
182
}
200
183
201
- protected string GetBaselineDir ( string subDir )
184
+ protected string GetBaselinePath ( string name )
202
185
{
203
186
Contracts . Assert ( IsActive ) ;
204
- if ( string . IsNullOrWhiteSpace ( subDir ) )
187
+ if ( string . IsNullOrWhiteSpace ( name ) )
205
188
return null ;
206
- return Path . GetFullPath ( Path . Combine ( _baseDir , subDir ) ) ;
207
- // return Path.Combine(_baseDir, subDir );
189
+
190
+ return GetBaselinePath ( string . Empty , name ) ;
208
191
}
209
192
210
193
protected string GetBaselinePath ( string subDir , string name )
211
194
{
212
195
Contracts . Assert ( IsActive ) ;
213
- if ( string . IsNullOrWhiteSpace ( subDir ) )
214
- return GetBaselinePath ( name ) ;
215
- return Path . GetFullPath ( Path . Combine ( _baseDir , subDir , name ) ) ;
216
- //return Path.Combine(_baseDir, subDir, name);
217
- }
196
+ subDir = subDir ?? string . Empty ;
218
197
219
- protected string GetBaselinePath ( string name )
220
- {
221
- Contracts . Assert ( IsActive ) ;
222
- if ( string . IsNullOrWhiteSpace ( name ) )
223
- return null ;
224
- //return Path.Combine(_baseDir, name);
225
- return Path . GetFullPath ( Path . Combine ( _baseDir , name ) ) ;
198
+ // first check the Common folder, and use it if it exists
199
+ string commonBaselinePath = Path . GetFullPath ( Path . Combine ( _baselineCommonDir , subDir , name ) ) ;
200
+ if ( File . Exists ( commonBaselinePath ) )
201
+ {
202
+ return commonBaselinePath ;
203
+ }
204
+
205
+ return Path . GetFullPath ( Path . Combine ( _baselineBuildStringDir , subDir , name ) ) ;
226
206
}
227
207
228
208
// Inverts the _passed flag. Do not ever use this except in rare conditions. Eg. Recording failure of a test as a success.
@@ -393,36 +373,6 @@ protected bool CheckEqualityCore(string dir, string name, string nameBase, bool
393
373
return res ;
394
374
}
395
375
396
- /// <summary>
397
- /// Check whether two files are same ignoring volatile differences (path, dates, times, etc),
398
- /// skipping the given number of lines on the output, and finding the corresponding line
399
- /// in the baseline.
400
- /// </summary>
401
- protected bool CheckEqualityNormalizedFromPaths ( string desc , string basePath , string outPath , int skip = 0 )
402
- {
403
- Contracts . Assert ( IsActive ) ;
404
- Contracts . AssertNonEmpty ( basePath ) ;
405
- Contracts . AssertNonEmpty ( outPath ) ;
406
- Contracts . Assert ( skip >= 0 ) ;
407
-
408
- if ( ! CheckOutFile ( outPath ) )
409
- return false ;
410
-
411
- // Normalize the output file.
412
- Normalize ( outPath ) ;
413
-
414
- if ( ! CheckBaseFile ( basePath ) )
415
- return false ;
416
-
417
- bool res = CheckEqualityFromPathsCore ( desc , basePath , outPath , skip ) ;
418
-
419
- // No need to keep the raw (unnormalized) output file.
420
- if ( res )
421
- File . Delete ( outPath + RawSuffix ) ;
422
-
423
- return res ;
424
- }
425
-
426
376
private bool FirstIsSuffix < T > ( IEnumerator < T > suffix , IEnumerator < T > seq , Func < T , T , bool > equalFunc = null )
427
377
{
428
378
Contracts . AssertValue ( suffix ) ;
@@ -464,11 +414,6 @@ private bool FirstIsSuffix<T>(IEnumerator<T> suffix, IEnumerator<T> seq, Func<T,
464
414
return true ;
465
415
}
466
416
467
- private IEnumerator < string > LineEnumerator ( TextReader reader )
468
- {
469
- return LineEnumerator ( reader , x => false ) ;
470
- }
471
-
472
417
private IEnumerator < string > LineEnumerator ( TextReader reader , Func < string , bool > stop )
473
418
{
474
419
string result ;
@@ -496,41 +441,6 @@ protected bool CheckOutputIsSuffix(string basePath, string outPath, int skip = 0
496
441
}
497
442
}
498
443
499
- /// <summary>
500
- /// Check whether two files are same ignoring volatile differences (path, dates, times, etc),
501
- /// skipping the given number of lines on the output, and finding the corresponding line
502
- /// in the baseline.
503
- /// </summary>
504
- protected bool CheckEqualityNormalized ( string dir , string name , string suffix , int skip , int digitsOfPrecision = DigitsOfPrecision )
505
- {
506
- Contracts . Assert ( IsActive ) ;
507
- Contracts . AssertValue ( dir ) ; // Can be empty.
508
- Contracts . AssertNonEmpty ( name ) ;
509
- Contracts . AssertNonEmpty ( suffix ) ;
510
- Contracts . Assert ( skip >= 0 ) ;
511
-
512
- string relPath = Path . Combine ( dir , name + suffix ) ;
513
- string basePath = GetBaselinePath ( dir , name ) ;
514
- string outPath = GetOutputPath ( dir , name + suffix ) ;
515
-
516
- if ( ! CheckOutFile ( outPath ) )
517
- return false ;
518
-
519
- // Normalize the output file.
520
- Normalize ( outPath ) ;
521
-
522
- if ( ! CheckBaseFile ( basePath ) )
523
- return false ;
524
-
525
- bool res = CheckEqualityFromPathsCore ( relPath , basePath , outPath , skip , digitsOfPrecision ) ;
526
-
527
- // No need to keep the raw (unnormalized) output file.
528
- if ( res )
529
- File . Delete ( outPath + RawSuffix ) ;
530
-
531
- return res ;
532
- }
533
-
534
444
protected bool CheckEqualityFromPathsCore ( string relPath , string basePath , string outPath , int skip = 0 , int digitsOfPrecision = DigitsOfPrecision )
535
445
{
536
446
Contracts . Assert ( skip >= 0 ) ;
@@ -838,7 +748,7 @@ protected static StreamReader OpenReader(string path)
838
748
{
839
749
Contracts . CheckNonWhiteSpace ( path , nameof ( path ) ) ;
840
750
#if CORECLR
841
- return new StreamReader ( File . Open ( path , FileMode . Open , FileAccess . Read ) ) ;
751
+ return new StreamReader ( File . Open ( path , FileMode . Open , FileAccess . Read , FileShare . Read ) ) ;
842
752
#else
843
753
return new StreamReader ( path ) ;
844
754
#endif
@@ -857,16 +767,6 @@ protected static int MainForTest(string args)
857
767
return result ;
858
768
}
859
769
}
860
-
861
- protected static string GetEnvironmentVariable ( string name )
862
- {
863
- return Environment . GetEnvironmentVariable ( name , EnvironmentVariableTarget . Process ) ;
864
- }
865
-
866
- protected static void SetEnvironmentVariable ( string name , string value )
867
- {
868
- Environment . SetEnvironmentVariable ( name , value , EnvironmentVariableTarget . Process ) ;
869
- }
870
770
}
871
771
872
772
public partial class TestBaselineNormalize : BaseTestBaseline
0 commit comments