diff --git a/scripts/build/TestPlatform.Dependencies.props b/scripts/build/TestPlatform.Dependencies.props index 30fcabab0e..04a239235d 100644 --- a/scripts/build/TestPlatform.Dependencies.props +++ b/scripts/build/TestPlatform.Dependencies.props @@ -19,6 +19,7 @@ 3.8.0 4.3.7 + 1.1.1 9.0.1 4.7.63 diff --git a/scripts/verify-nupkgs.ps1 b/scripts/verify-nupkgs.ps1 index 0bff808d7d..84ed4d6a4e 100644 --- a/scripts/verify-nupkgs.ps1 +++ b/scripts/verify-nupkgs.ps1 @@ -14,12 +14,12 @@ function Verify-Nuget-Packages($packageDirectory) Write-Log "Starting Verify-Nuget-Packages." $expectedNumOfFiles = @{"Microsoft.CodeCoverage" = 29; "Microsoft.NET.Test.Sdk" = 13; - "Microsoft.TestPlatform" = 421; + "Microsoft.TestPlatform" = 422; "Microsoft.TestPlatform.Build" = 19; - "Microsoft.TestPlatform.CLI" = 300; + "Microsoft.TestPlatform.CLI" = 301; "Microsoft.TestPlatform.Extensions.TrxLogger" = 33; "Microsoft.TestPlatform.ObjectModel" = 62; - "Microsoft.TestPlatform.Portable" = 469; + "Microsoft.TestPlatform.Portable" = 471; "Microsoft.TestPlatform.TestHost" = 140; "Microsoft.TestPlatform.TranslationLayer" = 121} diff --git a/src/package/nuspec/Microsoft.TestPlatform.Portable.nuspec b/src/package/nuspec/Microsoft.TestPlatform.Portable.nuspec index a0d836efc6..81d63e9f40 100644 --- a/src/package/nuspec/Microsoft.TestPlatform.Portable.nuspec +++ b/src/package/nuspec/Microsoft.TestPlatform.Portable.nuspec @@ -22,6 +22,7 @@ + @@ -224,6 +225,7 @@ + diff --git a/src/package/nuspec/Microsoft.TestPlatform.nuspec b/src/package/nuspec/Microsoft.TestPlatform.nuspec index 9ca82f4d67..de164d2d71 100644 --- a/src/package/nuspec/Microsoft.TestPlatform.nuspec +++ b/src/package/nuspec/Microsoft.TestPlatform.nuspec @@ -97,6 +97,7 @@ + diff --git a/src/vstest.console/CommandLine/CommandLineOptions.cs b/src/vstest.console/CommandLine/CommandLineOptions.cs index 1d0aea2f4c..04e3c7e392 100644 --- a/src/vstest.console/CommandLine/CommandLineOptions.cs +++ b/src/vstest.console/CommandLine/CommandLineOptions.cs @@ -5,7 +5,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine { using System; using System.Collections.Generic; - using System.Globalization; using System.Linq; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -15,6 +14,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources; using System.IO; + using vstest.console.Internal; /// /// Provides access to the command-line options. @@ -83,6 +83,7 @@ protected CommandLineOptions() this.BatchSize = DefaultBatchSize; this.TestStatsEventTimeout = this.DefaultRetrievalTimeout; this.FileHelper = new FileHelper(); + this.FilePatternParser = new FilePatternParser(); #if TODO UseVsixExtensions = Utilities.GetAppSettingValue(UseVsixExtensionsKey, false); #endif @@ -238,6 +239,8 @@ public bool ShouldCollectSourceInformation internal IFileHelper FileHelper { get; set; } + internal FilePatternParser FilePatternParser { get; set; } + /// /// Gets or sets the target Framework version for test run. /// @@ -283,28 +286,20 @@ public void AddSource(string source) { throw new CommandLineException(CommandLineResources.CannotBeNullOrEmpty); } - + source = source.Trim(); - + // Convert the relative path to absolute path - if(!Path.IsPathRooted(source)) + if (!Path.IsPathRooted(source)) { source = Path.Combine(FileHelper.GetCurrentDirectory(), source); } - if (!FileHelper.Exists(source)) - { - throw new CommandLineException( - string.Format(CultureInfo.CurrentUICulture, CommandLineResources.TestSourceFileNotFound, source)); - } - - if (this.sources.Contains(source, StringComparer.OrdinalIgnoreCase)) - { - throw new CommandLineException( - string.Format(CultureInfo.CurrentCulture, CommandLineResources.DuplicateSource, source)); - } + // Get matching files from file pattern parser + var matchingFiles = FilePatternParser.GetMatchingFiles(source); - this.sources.Add(source); + // Add the matching files to source list + this.sources = this.sources.Union(matchingFiles).ToList(); } #endregion diff --git a/src/vstest.console/Internal/ConsoleLogger.cs b/src/vstest.console/Internal/ConsoleLogger.cs index 35db258aa7..2162ec0770 100644 --- a/src/vstest.console/Internal/ConsoleLogger.cs +++ b/src/vstest.console/Internal/ConsoleLogger.cs @@ -176,6 +176,7 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory) events.TestRunMessage += this.TestMessageHandler; events.TestResult += this.TestResultHandler; events.TestRunComplete += this.TestRunCompleteHandler; + events.TestRunStart += this.TestRunStartHandler; // Register for the discovery events. events.DiscoveryMessage += this.TestMessageHandler; @@ -358,6 +359,26 @@ private static void DisplayFullInformation(TestResult result) #region Event Handlers + /// + /// Called when a test run start is received + /// + private void TestRunStartHandler(object sender, TestRunStartEventArgs e) + { + ValidateArg.NotNull(sender, "sender"); + ValidateArg.NotNull(e, "e"); + + // Print all test containers. + Output.WriteLine(string.Empty, OutputLevel.Information); + Output.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestSourcesDiscovered, CommandLineOptions.Instance.Sources.Count()), OutputLevel.Information); + if (verbosityLevel == Verbosity.Detailed) + { + foreach (var source in CommandLineOptions.Instance.Sources) + { + Output.WriteLine(source, OutputLevel.Information); + } + } + } + /// /// Called when a test message is received. /// diff --git a/src/vstest.console/Internal/FilePatternParser.cs b/src/vstest.console/Internal/FilePatternParser.cs new file mode 100644 index 0000000000..923a96a252 --- /dev/null +++ b/src/vstest.console/Internal/FilePatternParser.cs @@ -0,0 +1,99 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace vstest.console.Internal +{ + using Microsoft.Extensions.FileSystemGlobbing; + using Microsoft.Extensions.FileSystemGlobbing.Abstractions; + using Microsoft.VisualStudio.TestPlatform.CommandLine; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; + using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; + using System; + using System.Collections.Generic; + using System.Globalization; + using System.IO; + + using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources; + + /// + /// Class for getting matching files from wild card pattern file name + /// Microsoft.Extensions.FileSystemGlobbing methods used to get matching file names + /// + public class FilePatternParser + { + private Matcher matcher; + private IFileHelper fileHelper; + private char[] wildCardCharacters = { '*' }; + + public FilePatternParser() + : this(new Matcher(), new FileHelper()) + { + } + + internal FilePatternParser(Matcher matcher, IFileHelper fileHelper) + { + this.matcher = matcher; + this.fileHelper = fileHelper; + } + + /// + /// Used to get matching files with pattern + /// + /// Returns the list of matching files + public List GetMatchingFiles(string filePattern) + { + var matchingFiles = new List(); + + // If there is no wildcard simply add the file to the list of matching files. + if(filePattern.IndexOfAny(wildCardCharacters) == -1) + { + EqtTrace.Info($"FilePatternParser: The given file {filePattern} is a full path."); + + // Check if the file exists. + if (!this.fileHelper.Exists(filePattern)) + { + throw new CommandLineException( + string.Format(CultureInfo.CurrentUICulture, CommandLineResources.TestSourceFileNotFound, filePattern)); + } + + matchingFiles.Add(filePattern); + + return matchingFiles; + } + + // Split the given wildcard into search directory and pattern to be searched. + var splitPattern = SplitFilePatternOnWildCard(filePattern); + EqtTrace.Info($"FilePatternParser: Matching file pattern '{splitPattern.Item2}' within directory '{splitPattern.Item1}'"); + + this.matcher.AddInclude(splitPattern.Item2); + + // Execute the given pattern in the search directory. + var matches = this.matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(splitPattern.Item1))); + + // Add all the files to the list of matching files. + foreach (var match in matches.Files) + { + matchingFiles.Add(Path.Combine(splitPattern.Item1, match.Path)); + } + + return matchingFiles; + } + + /// + /// Splits full pattern into search directory and pattern. + /// + private Tuple SplitFilePatternOnWildCard(string filePattern) + { + // Split the pattern based on first wildcard character found. + var splitOnWildCardIndex = filePattern.IndexOfAny(wildCardCharacters); + var directorySeparatorIndex = filePattern.Substring(0, splitOnWildCardIndex).LastIndexOf(Path.DirectorySeparatorChar); + + string searchDir = filePattern.Substring(0, directorySeparatorIndex); + string pattern = filePattern.Substring(directorySeparatorIndex + 1); + + Tuple splitPattern = new Tuple(searchDir, pattern); + return splitPattern; + } + } +} diff --git a/src/vstest.console/Resources/Resources.Designer.cs b/src/vstest.console/Resources/Resources.Designer.cs index ac592cc5b3..319bfe8957 100644 --- a/src/vstest.console/Resources/Resources.Designer.cs +++ b/src/vstest.console/Resources/Resources.Designer.cs @@ -432,15 +432,6 @@ internal class Resources { } } - /// - /// Looks up a localized string similar to Duplicate source {0} specified.. - /// - internal static string DuplicateSource { - get { - return ResourceManager.GetString("DuplicateSource", resourceCulture); - } - } - /// /// Looks up a localized string similar to --Blame|/Blame:[CollectDump];[CollectAlways]=[Value];[DumpType]=[Value] /// Runs the test in blame mode. This option is helpful in isolating the problematic test causing test host crash. @@ -1616,7 +1607,19 @@ public static string ProgressIndicatorString return ResourceManager.GetString("TestSourceFileNotFound", resourceCulture); } } - + + /// + /// Looks up a localized string similar to A total of {0} test source files are discovered.. + /// + internal static string TestSourcesDiscovered + { + get + { + return ResourceManager.GetString("TestSourcesDiscovered", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Time elapsed :. /// diff --git a/src/vstest.console/Resources/Resources.resx b/src/vstest.console/Resources/Resources.resx index dcd46707d8..a15a20c6e9 100644 --- a/src/vstest.console/Resources/Resources.resx +++ b/src/vstest.console/Resources/Resources.resx @@ -221,9 +221,6 @@ The parameter "{0}" should be provided only once. - - Duplicate source {0} specified. - /EnableCodeCoverage Enables data collector 'CodeCoverage' for the test run. @@ -486,10 +483,11 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll , @@ -730,4 +728,7 @@ Test run in progress + + A total of {0} test files matched the specified pattern. + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.cs.xlf b/src/vstest.console/Resources/xlf/Resources.cs.xlf index daddd18995..f225d94f37 100644 --- a/src/vstest.console/Resources/xlf/Resources.cs.xlf +++ b/src/vstest.console/Resources/xlf/Resources.cs.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - Zadal se duplicitní zdroj {0}. - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. {0} se nenašel. @@ -299,16 +290,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [TestFileNames] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [TestFileNames] Spustí testy ze zadaných souborů. Pokud máte názvů souborů více, oddělte je mezerami. Příklad: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1653,6 +1645,11 @@ Přeskočené: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.de.xlf b/src/vstest.console/Resources/xlf/Resources.de.xlf index 953c18ca7d..f04a059b9c 100644 --- a/src/vstest.console/Resources/xlf/Resources.de.xlf +++ b/src/vstest.console/Resources/xlf/Resources.de.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - Es wurde eine doppelte Quelle {0} angegeben. - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. "{0}" wurde nicht gefunden. @@ -299,16 +290,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [TestFileNames] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [TestFileNames] Führt Tests aus den angegebenen Dateien aus. Trennen Sie mehrere Testdateinamen durch Leerzeichen. Beispiele: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1653,6 +1645,11 @@ Übersprungen: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.es.xlf b/src/vstest.console/Resources/xlf/Resources.es.xlf index 94c4f15cb5..31fd55ce9d 100644 --- a/src/vstest.console/Resources/xlf/Resources.es.xlf +++ b/src/vstest.console/Resources/xlf/Resources.es.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - Se ha especificado un origen duplicado ({0}). - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. No se encuentra '{0}'. @@ -299,16 +290,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [NombresDeArchivosDePrueba] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [NombresDeArchivosDePrueba] Ejecutar pruebas de los archivos especificados. Separe varios nombres de archivo con espacios. Ejemplos: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1655,6 +1647,11 @@ Omitido: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.fr.xlf b/src/vstest.console/Resources/xlf/Resources.fr.xlf index 788e5c23c8..d7f61f2967 100644 --- a/src/vstest.console/Resources/xlf/Resources.fr.xlf +++ b/src/vstest.console/Resources/xlf/Resources.fr.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - Source dupliquée {0} spécifiée. - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. '{0}' introuvable. @@ -299,16 +290,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [TestFileNames] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [TestFileNames] Exécutez les tests à partir des fichiers spécifiés. Séparez plusieurs noms de fichiers de test par des espaces. Exemples : mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1653,6 +1645,11 @@ Ignoré(s) : {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.it.xlf b/src/vstest.console/Resources/xlf/Resources.it.xlf index bb6c835e05..171804d646 100644 --- a/src/vstest.console/Resources/xlf/Resources.it.xlf +++ b/src/vstest.console/Resources/xlf/Resources.it.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - L'origine {0} specificata è duplicata. - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. '{0}' non è stato trovato. @@ -299,16 +290,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [NomiFileTest] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [NomiFileTest] Esegue test dai file specificati. Separare più nomi di file di test con spazi. Esempi: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1653,6 +1645,11 @@ Ignorati: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.ja.xlf b/src/vstest.console/Resources/xlf/Resources.ja.xlf index 8511a9f746..9c3952efe9 100644 --- a/src/vstest.console/Resources/xlf/Resources.ja.xlf +++ b/src/vstest.console/Resources/xlf/Resources.ja.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - 重複するソース {0} が指定されています。 - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. '{0}' が見つかりません。 @@ -299,16 +290,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [テストファイル名] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [テストファイル名] 指定されたファイルからテストを実行します。複数のテスト ファイルがある場合は、 名前をスペースで区切ってください。 例: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1653,6 +1645,11 @@ スキップ: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.ko.xlf b/src/vstest.console/Resources/xlf/Resources.ko.xlf index e3e9bc8c15..9fa52e3dc0 100644 --- a/src/vstest.console/Resources/xlf/Resources.ko.xlf +++ b/src/vstest.console/Resources/xlf/Resources.ko.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - 중복 소스 {0}을(를) 지정했습니다. - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. '{0}'을(를) 찾을 수 없습니다. @@ -299,16 +290,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [TestFileNames] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [TestFileNames] 지정한 파일에서 테스트를 실행합니다. 테스트 파일 이름이 여러 개이면 공백으로 구분합니다. 예: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1653,6 +1645,11 @@ 건너뜀: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.pl.xlf b/src/vstest.console/Resources/xlf/Resources.pl.xlf index 9872a4ce0f..c210a4da1e 100644 --- a/src/vstest.console/Resources/xlf/Resources.pl.xlf +++ b/src/vstest.console/Resources/xlf/Resources.pl.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - Określono zduplikowane źródło {0}. - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. Nie można odnaleźć elementu „{0}”. @@ -299,16 +290,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [TestFileNames] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [TestFileNames] Uruchamia testy z określonych plików. Oddziel wiele nazw plików testowych spacjami. Przykłady: mojProjektTestowy.dll mojProjektTestowy.dll mojInnyProjektTestowy.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1653,6 +1645,11 @@ Pominięte: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.pt-BR.xlf b/src/vstest.console/Resources/xlf/Resources.pt-BR.xlf index 7ae7dd4987..f62a73019a 100644 --- a/src/vstest.console/Resources/xlf/Resources.pt-BR.xlf +++ b/src/vstest.console/Resources/xlf/Resources.pt-BR.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - Fonte duplicada {0} especificada. - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. '{0}' não encontrado. @@ -299,16 +290,17 @@ Altere o prefixo de nível de diagnóstico do agente de console, como mostrado a [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [TestFileNames] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [TestFileNames] Executar testes dos arquivos especificados. Use espaços para separar vários nomes de arquivo de teste. Exemplos: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1653,6 +1645,11 @@ Altere o prefixo de nível de diagnóstico do agente de console, como mostrado a Ignorados: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.ru.xlf b/src/vstest.console/Resources/xlf/Resources.ru.xlf index 7f87be0933..24644230a5 100644 --- a/src/vstest.console/Resources/xlf/Resources.ru.xlf +++ b/src/vstest.console/Resources/xlf/Resources.ru.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - Указан повторяющийся источник {0}. - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. "{0}": не найдено. @@ -299,16 +290,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [TestFileNames] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [TestFileNames] Выполнение тестов из указанных файлов. При вводе нескольких имен файла теста они разделяются пробелами. Примеры: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1653,6 +1645,11 @@ Пропущено: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.tr.xlf b/src/vstest.console/Resources/xlf/Resources.tr.xlf index df8b4901f5..9535b66c8d 100644 --- a/src/vstest.console/Resources/xlf/Resources.tr.xlf +++ b/src/vstest.console/Resources/xlf/Resources.tr.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - Yinelenen {0} kaynağı belirtildi. - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. '{0}' bulunamadı. @@ -299,16 +290,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [TestFileNames] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [TestFileNames] Belirtilen dosyalardan testleri çalıştırır. Birden fazla test dosyası adını boşlukla ayırın. Örnekler: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1653,6 +1645,11 @@ Günlükler için izleme düzeyini aşağıda gösterildiği gibi değiştirin Atlandı: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.xlf b/src/vstest.console/Resources/xlf/Resources.xlf index cdaa74fa6a..4615d0fa70 100644 --- a/src/vstest.console/Resources/xlf/Resources.xlf +++ b/src/vstest.console/Resources/xlf/Resources.xlf @@ -2,10 +2,6 @@ - - Duplicate source {0} specified. - - '{0}' not found. @@ -124,10 +120,11 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll @@ -840,6 +837,11 @@ Skipped: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.zh-Hans.xlf b/src/vstest.console/Resources/xlf/Resources.zh-Hans.xlf index 0f597fdba8..9183942b4c 100644 --- a/src/vstest.console/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/vstest.console/Resources/xlf/Resources.zh-Hans.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - 指定了重复的源 {0}。 - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. 未找到“{0}”。 @@ -298,16 +289,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [TestFileNames] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [TestFileNames] 从指定文件运行测试。使用空格分隔多个测试文件 名称。 实例: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1652,6 +1644,11 @@ 跳过数: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.zh-Hant.xlf b/src/vstest.console/Resources/xlf/Resources.zh-Hant.xlf index 89ea9c6c11..7aa01f9cc3 100644 --- a/src/vstest.console/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/vstest.console/Resources/xlf/Resources.zh-Hant.xlf @@ -20,15 +20,6 @@ - - Duplicate source {0} specified. - 指定了重複的來源 {0}。 - - - Doppelte Quelle {0} angegeben. - - fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - '{0}' not found. 找不到 '{0}'。 @@ -300,16 +291,17 @@ [TestFileNames] - Run tests from the specified files. Separate multiple test file names - by spaces. + Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern + by spaces. Set console logger verbosity to detailed to view matched test files. Examples: mytestproject.dll - mytestproject.dll myothertestproject.exe - [TestFileNames] + mytestproject.dll myothertestproject.exe + testproject*.dll my*project.dll + [TestFileNames] 從指定的檔案執行測試。請以空格分隔多個 測試檔案名稱。 範例: mytestproject.dll mytestproject.dll myothertestproject.exe - + [TestFileNames] Führen Sie Tests aus den angegebenen Dateien. Trennen Sie mehrere Test-Dateinamen @@ -1654,6 +1646,11 @@ 跳過: {0} + + A total of {0} test files matched the specified pattern. + A total of {0} test source files are discovered. + + \ No newline at end of file diff --git a/src/vstest.console/vstest.console.csproj b/src/vstest.console/vstest.console.csproj index 859ace0cba..6843aaf587 100644 --- a/src/vstest.console/vstest.console.csproj +++ b/src/vstest.console/vstest.console.csproj @@ -20,6 +20,11 @@ + + + $(FileSystemGlobbingVersion) + + diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/FilePatternParserTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/FilePatternParserTests.cs new file mode 100644 index 0000000000..d8f281a7c0 --- /dev/null +++ b/test/Microsoft.TestPlatform.AcceptanceTests/FilePatternParserTests.cs @@ -0,0 +1,101 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information.using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Microsoft.TestPlatform.AcceptanceTests +{ + using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.IO; + + [TestClass] + public class FilePatternParserTests : AcceptanceTestBase + { + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void WildCardPatternShouldCorrectlyWorkOnFiles(RunnerInfo runnerInfo) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + + var testAssembly = this.GetSampleTestAssembly(); + testAssembly = testAssembly.Replace("SimpleTestProject.dll", "*TestProj*.dll"); + + var arguments = PrepareArguments( + testAssembly, + this.GetTestAdapterPath(), + string.Empty, this.FrameworkArgValue, + runnerInfo.InIsolationValue); + + this.InvokeVsTest(arguments); + this.ValidateSummaryStatus(1, 1, 1); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void WildCardPatternShouldCorrectlyWorkOnArbitraryDepthDirectories(RunnerInfo runnerInfo) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + + var testAssembly = this.GetSampleTestAssembly(); + var oldAssemblyPath = Path.Combine("Debug", this.testEnvironment.TargetFramework, "SimpleTestProject.dll"); + var newAssemblyPath = Path.Combine("**", this.testEnvironment.TargetFramework, "*TestProj*.dll"); + testAssembly = testAssembly.Replace(oldAssemblyPath, newAssemblyPath); + + var arguments = PrepareArguments( + testAssembly, + this.GetTestAdapterPath(), + string.Empty, string.Empty, + runnerInfo.InIsolationValue); + + this.InvokeVsTest(arguments); + this.ValidateSummaryStatus(1, 1, 1); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void WildCardPatternShouldCorrectlyWorkForRelativeAssemblyPath(RunnerInfo runnerInfo) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + + var testAssembly = this.GetSampleTestAssembly(); + testAssembly = testAssembly.Replace("SimpleTestProject.dll", "*TestProj*.dll"); + + var wildCardIndex = testAssembly.IndexOfAny(new char[] { '*' }); + var testAssemblyDirectory = testAssembly.Substring(0, wildCardIndex); + testAssembly = testAssembly.Substring(wildCardIndex); + + Directory.SetCurrentDirectory(testAssemblyDirectory); + + var arguments = PrepareArguments( + testAssembly, + this.GetTestAdapterPath(), + string.Empty, string.Empty, + runnerInfo.InIsolationValue); + + this.InvokeVsTest(arguments); + this.ValidateSummaryStatus(1, 1, 1); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void WildCardPatternShouldCorrectlyWorkOnMultipleFiles(RunnerInfo runnerInfo) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + + var testAssembly = this.BuildMultipleAssemblyPath("SimpleTestProject.dll", "SimpleTestProject2.dll").Trim('\"'); ; + testAssembly = testAssembly.Replace("SimpleTestProject.dll", "*TestProj*.dll"); + testAssembly = testAssembly.Replace("SimpleTestProject2.dll", "*TestProj*.dll"); + + var arguments = PrepareArguments( + testAssembly, + this.GetTestAdapterPath(), + string.Empty, this.FrameworkArgValue, + runnerInfo.InIsolationValue); + + this.InvokeVsTest(arguments); + this.ValidateSummaryStatus(2, 2, 2); + } + } +} diff --git a/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs b/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs index 1d7a0c5cac..458ce9a5a5 100644 --- a/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs +++ b/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs @@ -12,18 +12,23 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.CommandLine using Moq; using System.IO; using MSTest.TestFramework.AssertExtensions; + using vstest.console.Internal; + using Microsoft.Extensions.FileSystemGlobbing; [TestClass] public class CommandLineOptionsTests { private readonly Mock fileHelper; + private FilePatternParser filePatternParser; private readonly string currentDirectory = @"C:\\Temp"; public CommandLineOptionsTests() { this.fileHelper = new Mock(); + this.filePatternParser = new FilePatternParser(new Mock().Object, this.fileHelper.Object); CommandLineOptions.Instance.Reset(); CommandLineOptions.Instance.FileHelper = this.fileHelper.Object; + CommandLineOptions.Instance.FilePatternParser = this.filePatternParser; this.fileHelper.Setup(fh => fh.GetCurrentDirectory()).Returns(currentDirectory); } @@ -80,17 +85,6 @@ public void CommandLineOptionsAddSourceShouldThrowCommandLineExceptionForInvalid Assert.ThrowsException(() => CommandLineOptions.Instance.AddSource("DummySource")); } - [TestMethod] - public void CommandLineOptionsAddSourceShouldAddSourceThrowExceptionIfDuplicateSource() - { - var testFilePath = "C:\\DummyTestFile.txt"; - this.fileHelper.Setup(fh => fh.Exists(testFilePath)).Returns(true); - - CommandLineOptions.Instance.AddSource(testFilePath); - Assert.That.Throws(() => CommandLineOptions.Instance.AddSource(testFilePath)) - .WithExactMessage("Duplicate source " + testFilePath + " specified."); - } - [TestMethod] public void CommandLineOptionsAddSourceShouldAddSourceForValidSource() { diff --git a/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs b/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs index 7d17c8bb77..0773f9d24d 100644 --- a/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs +++ b/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs @@ -7,8 +7,9 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Internal using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; + using System.Linq; using System.Threading; - + using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal; using Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors; using Microsoft.VisualStudio.TestPlatform.Common.Logging; @@ -16,8 +17,10 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Internal using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.Utilities; + using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; + using vstest.console.Internal; using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources; [TestClass] @@ -812,6 +815,94 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsAbortedWithoutRunni this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunAborted, OutputLevel.Error), Times.Once()); } + [TestMethod] + public void TestRunStartHandlerShouldWriteNumberOfTestSourcesDiscoveredOnConsole() + { + var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); + loggerEvents.EnableEvents(); + + var fileHelper = new Mock(); + CommandLineOptions.Instance.Reset(); + CommandLineOptions.Instance.FileHelper = fileHelper.Object; + CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, fileHelper.Object); + string testFilePath = "C:\\DummyTestFile.dll"; + fileHelper.Setup(fh => fh.Exists(testFilePath)).Returns(true); + + CommandLineOptions.Instance.AddSource(testFilePath); + + var parameters = new Dictionary(); + parameters.Add("verbosity", "normal"); + this.consoleLogger.Initialize(loggerEvents, parameters); + + var testRunStartEventArgs = new TestRunStartEventArgs(new TestRunCriteria(new List { "C:\\DummyTestFile.dll" }, 1)); + loggerEvents.RaiseTestRunStart(testRunStartEventArgs); + loggerEvents.WaitForEventCompletion(); + + this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestSourcesDiscovered, CommandLineOptions.Instance.Sources.Count()), OutputLevel.Information), Times.Once()); + } + + [TestMethod] + public void TestRunStartHandlerShouldWriteTestSourcesDiscoveredOnConsoleIfVerbosityDetailed() + { + var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); + loggerEvents.EnableEvents(); + + var fileHelper = new Mock(); + CommandLineOptions.Instance.Reset(); + CommandLineOptions.Instance.FileHelper = fileHelper.Object; + CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, fileHelper.Object); + string testFilePath = "C:\\DummyTestFile.dll"; + fileHelper.Setup(fh => fh.Exists(testFilePath)).Returns(true); + string testFilePath2 = "C:\\DummyTestFile2.dll"; + fileHelper.Setup(fh => fh.Exists(testFilePath2)).Returns(true); + + CommandLineOptions.Instance.AddSource(testFilePath); + CommandLineOptions.Instance.AddSource(testFilePath2); + + var parameters = new Dictionary(); + parameters.Add("verbosity", "detailed"); + this.consoleLogger.Initialize(loggerEvents, parameters); + + var testRunStartEventArgs = new TestRunStartEventArgs(new TestRunCriteria(new List { "C:\\DummyTestFile.dll" }, 1)); + loggerEvents.RaiseTestRunStart(testRunStartEventArgs); + loggerEvents.WaitForEventCompletion(); + + this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestSourcesDiscovered, CommandLineOptions.Instance.Sources.Count()), OutputLevel.Information), Times.Once()); + this.mockOutput.Verify(o => o.WriteLine("C:\\DummyTestFile.dll", OutputLevel.Information), Times.Once); + this.mockOutput.Verify(o => o.WriteLine("C:\\DummyTestFile2.dll", OutputLevel.Information), Times.Once); + } + + [TestMethod] + public void TestRunStartHandlerShouldNotWriteTestSourcesDiscoveredOnConsoleIfVerbosityNotDetailed() + { + var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); + loggerEvents.EnableEvents(); + + var fileHelper = new Mock(); + CommandLineOptions.Instance.Reset(); + CommandLineOptions.Instance.FileHelper = fileHelper.Object; + CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, fileHelper.Object); + string testFilePath = "C:\\DummyTestFile.dll"; + fileHelper.Setup(fh => fh.Exists(testFilePath)).Returns(true); + string testFilePath2 = "C:\\DummyTestFile2.dll"; + fileHelper.Setup(fh => fh.Exists(testFilePath2)).Returns(true); + + CommandLineOptions.Instance.AddSource(testFilePath); + CommandLineOptions.Instance.AddSource(testFilePath2); + + var parameters = new Dictionary(); + parameters.Add("verbosity", "normal"); + this.consoleLogger.Initialize(loggerEvents, parameters); + + var testRunStartEventArgs = new TestRunStartEventArgs(new TestRunCriteria(new List { "C:\\DummyTestFile.dll" }, 1)); + loggerEvents.RaiseTestRunStart(testRunStartEventArgs); + loggerEvents.WaitForEventCompletion(); + + this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestSourcesDiscovered, CommandLineOptions.Instance.Sources.Count()), OutputLevel.Information), Times.Once()); + this.mockOutput.Verify(o => o.WriteLine("C:\\DummyTestFile.dll", OutputLevel.Information), Times.Never); + this.mockOutput.Verify(o => o.WriteLine("C:\\DummyTestFile2.dll", OutputLevel.Information), Times.Never); + } + [TestMethod] public void PrintTimeHandlerShouldPrintElapsedTimeOnConsole() { @@ -882,7 +973,7 @@ public void DisplayFullInformationShouldWriteStdMessageWithNewLine() this.mockOutput.Verify(o => o.Write(PassedTestIndicator, OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine("TestName", OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(" Hello", OutputLevel.Information), Times.Once()); - this.mockOutput.Verify(o => o.WriteLine(String.Empty, OutputLevel.Information), Times.Once()); + this.mockOutput.Verify(o => o.WriteLine(String.Empty, OutputLevel.Information), Times.AtLeastOnce); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Internal/FilePatternParserTests.cs b/test/vstest.console.UnitTests/Internal/FilePatternParserTests.cs new file mode 100644 index 0000000000..7117a7f0ac --- /dev/null +++ b/test/vstest.console.UnitTests/Internal/FilePatternParserTests.cs @@ -0,0 +1,113 @@ +// Copyright(c) Microsoft Corporation.All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace vstest.console.UnitTests.Internal +{ + using Microsoft.Extensions.FileSystemGlobbing; + using Microsoft.Extensions.FileSystemGlobbing.Abstractions; + using Microsoft.VisualStudio.TestPlatform.CommandLine; + using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Moq; + using System.Collections.Generic; + using vstest.console.Internal; + + [TestClass] + public class FilePatternParserTests + { + private FilePatternParser filePatternParser; + private Mock mockMatcherHelper; + private Mock mockFileHelper; + + [TestInitialize] + public void TestInit() + { + this.mockMatcherHelper = new Mock(); + this.mockFileHelper = new Mock(); + this.filePatternParser = new FilePatternParser(this.mockMatcherHelper.Object, this.mockFileHelper.Object); + } + + [TestMethod] + public void FilePatternParserShouldCorrectlySplitPatternAndDirectory() + { + var patternMatchingResult = new PatternMatchingResult(new List()); + this.mockMatcherHelper.Setup(x => x.Execute(It.IsAny())).Returns(patternMatchingResult); + this.filePatternParser.GetMatchingFiles(@"C:\Users\vanidhi\Desktop\a\c\*bc.dll"); + + // Assert + this.mockMatcherHelper.Verify(x => x.AddInclude(@"*bc.dll")); + this.mockMatcherHelper.Verify(x => x.Execute(It.Is(y => y.FullName.Equals(@"C:\Users\vanidhi\Desktop\a\c")))); + } + + [TestMethod] + public void FilePatternParserShouldCorrectlySplitWithArbitraryDirectoryDepth() + { + var patternMatchingResult = new PatternMatchingResult(new List()); + this.mockMatcherHelper.Setup(x => x.Execute(It.IsAny())).Returns(patternMatchingResult); + this.filePatternParser.GetMatchingFiles(@"C:\Users\vanidhi\**\c\*bc.txt"); + + // Assert + this.mockMatcherHelper.Verify(x => x.AddInclude(@"**\c\*bc.txt")); + this.mockMatcherHelper.Verify(x => x.Execute(It.Is(y => y.FullName.Equals(@"C:\Users\vanidhi")))); + } + + [TestMethod] + public void FilePatternParserShouldCorrectlySplitWithWildCardInMultipleDirectory() + { + var patternMatchingResult = new PatternMatchingResult(new List()); + this.mockMatcherHelper.Setup(x => x.Execute(It.IsAny())).Returns(patternMatchingResult); + this.filePatternParser.GetMatchingFiles(@"E:\path\to\project\tests\**.Tests\**\*.Tests.dll"); + + // Assert + this.mockMatcherHelper.Verify(x => x.AddInclude(@"**.Tests\**\*.Tests.dll")); + this.mockMatcherHelper.Verify(x => x.Execute(It.Is(y => y.FullName.Equals(@"E:\path\to\project\tests")))); + } + + [TestMethod] + public void FilePatternParserShouldCorrectlySplitWithMultpleWildCardInPattern() + { + var patternMatchingResult = new PatternMatchingResult(new List()); + this.mockMatcherHelper.Setup(x => x.Execute(It.IsAny())).Returns(patternMatchingResult); + this.filePatternParser.GetMatchingFiles(@"E:\path\to\project\tests\Tests*.Blame*.dll"); + + // Assert + this.mockMatcherHelper.Verify(x => x.AddInclude(@"Tests*.Blame*.dll")); + this.mockMatcherHelper.Verify(x => x.Execute(It.Is(y => y.FullName.Equals(@"E:\path\to\project\tests")))); + } + + [TestMethod] + public void FilePatternParserShouldCorrectlySplitWithMultpleWildCardInMultipleDirectory() + { + var patternMatchingResult = new PatternMatchingResult(new List()); + this.mockMatcherHelper.Setup(x => x.Execute(It.IsAny())).Returns(patternMatchingResult); + this.filePatternParser.GetMatchingFiles(@"E:\path\to\project\*tests\Tests*.Blame*.dll"); + + // Assert + this.mockMatcherHelper.Verify(x => x.AddInclude(@"*tests\Tests*.Blame*.dll")); + this.mockMatcherHelper.Verify(x => x.Execute(It.Is(y => y.FullName.Equals(@"E:\path\to\project")))); + } + + [TestMethod] + public void FilePatternParserShouldCheckIfFileExistsIfFullPathGiven() + { + var patternMatchingResult = new PatternMatchingResult(new List()); + this.mockFileHelper.Setup(x => x.Exists(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll")).Returns(true); + this.mockMatcherHelper.Setup(x => x.Execute(It.IsAny())).Returns(patternMatchingResult); + var matchingFiles = this.filePatternParser.GetMatchingFiles(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll"); + + // Assert + this.mockFileHelper.Verify(x => x.Exists(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll")); + Assert.IsTrue(matchingFiles.Contains(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll")); + } + + [TestMethod] + public void FilePatternParserShouldThrowCommandLineExceptionIfFileDoesNotExist() + { + var patternMatchingResult = new PatternMatchingResult(new List()); + this.mockFileHelper.Setup(x => x.Exists(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll")).Returns(false); + this.mockMatcherHelper.Setup(x => x.Execute(It.IsAny())).Returns(patternMatchingResult); + + Assert.ThrowsException(() => this.filePatternParser.GetMatchingFiles(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll")); + } + } +} diff --git a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs index 90067b0b14..56e617f45e 100644 --- a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs @@ -11,7 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using System.Threading.Tasks; using CoreUtilities.Tracing.Interfaces; - + using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.VisualStudio.TestPlatform.Client; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors; @@ -25,6 +25,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using ObjectModel.Client; using TestPlatform.Utilities; using TestPlatformHelpers; + using vstest.console.Internal; using vstest.console.UnitTests.Processors; // @@ -119,6 +120,7 @@ public void CapabilitiesShouldReturnAppropriateProperties() public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() { CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; + CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var executor = GetExecutor(testRequestManager, null); @@ -320,6 +322,7 @@ private void ResetAndAddSourceToCommandLineOptions(bool legitPath) CommandLineOptions.Instance.Reset(); CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; + CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); CommandLineOptions.Instance.AddSource(this.dummyTestFilePath); if (legitPath) { diff --git a/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs index 0407de27fb..40c0109145 100644 --- a/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs @@ -10,7 +10,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using System.Threading.Tasks; using CoreUtilities.Tracing.Interfaces; - + using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.VisualStudio.TestPlatform.Client; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors; @@ -24,6 +24,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using ObjectModel.Client; using TestPlatform.Utilities; using TestPlatformHelpers; + using vstest.console.Internal; using vstest.console.UnitTests.Processors; // @@ -120,7 +121,7 @@ public void CapabilitiesShouldReturnAppropriateProperties() public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() { CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; - + CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var executor = GetExecutor(testRequestManager, null); @@ -268,6 +269,7 @@ private void ResetAndAddSourceToCommandLineOptions() CommandLineOptions.Instance.Reset(); CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; + CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); CommandLineOptions.Instance.AddSource(this.dummyTestFilePath); } } diff --git a/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs index a569d331c9..08c10972c5 100644 --- a/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs @@ -11,7 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using CommandLineUtilities; using CoreUtilities.Tracing.Interfaces; - + using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.VisualStudio.TestPlatform.Client; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors; @@ -24,6 +24,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; + using vstest.console.Internal; using vstest.console.UnitTests.Processors; [TestClass] @@ -546,6 +547,7 @@ private void ResetAndAddSourceToCommandLineOptions() { CommandLineOptions.Instance.Reset(); CommandLineOptions.Instance.TestCaseFilterValue = null; + CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; CommandLineOptions.Instance.AddSource(this.dummyTestFilePath); } diff --git a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs index 61cd561cbf..7aea9780e9 100644 --- a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs @@ -11,7 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using System.Reflection; using System.Runtime.Versioning; using System.Threading.Tasks; - + using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.VisualStudio.TestPlatform.Client; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal; @@ -28,6 +28,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; + using vstest.console.Internal; using vstest.console.UnitTests.Processors; /// @@ -83,7 +84,7 @@ public void CapabilitiesShouldReturnAppropriateProperties() { RunTestsArgumentProcessorCapabilities capabilities = new RunTestsArgumentProcessorCapabilities(); Assert.AreEqual("/RunTests", capabilities.CommandName); - Assert.AreEqual("[TestFileNames]" + Environment.NewLine + " Run tests from the specified files. Separate multiple test file names" + Environment.NewLine + " by spaces." + Environment.NewLine + " Examples: mytestproject.dll" + Environment.NewLine + " mytestproject.dll myothertestproject.exe", capabilities.HelpContentResourceName); + Assert.AreEqual("[TestFileNames]" + Environment.NewLine + " Run tests from the specified files or wild card pattern. Separate multiple test file names or pattern" + Environment.NewLine + " by spaces. Set console logger verbosity to detailed to view matched test files." + Environment.NewLine + " Examples: mytestproject.dll" + Environment.NewLine + " mytestproject.dll myothertestproject.exe" + Environment.NewLine + @" testproject*.dll my*project.dll", capabilities.HelpContentResourceName); Assert.AreEqual(HelpContentPriority.RunTestsArgumentProcessorHelpPriority, capabilities.HelpPriority); Assert.AreEqual(true, capabilities.IsAction); @@ -258,6 +259,7 @@ private void ResetAndAddSourceToCommandLineOptions() CommandLineOptions.Instance.Reset(); CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; + CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); CommandLineOptions.Instance.AddSource(this.dummyTestFilePath); } diff --git a/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs index 8d23ff924c..bf3fcb4f88 100644 --- a/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs @@ -5,12 +5,13 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors { using System; using System.Linq; - + using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; + using vstest.console.Internal; // // Tests for TestSourceArgumentProcessor @@ -94,6 +95,7 @@ public void ExecuterInitializeWithValidSourceShouldAddItToTestSources() var options = CommandLineOptions.Instance; options.Reset(); options.FileHelper = mockFileHelper.Object; + options.FilePatternParser = new FilePatternParser(new Mock().Object, mockFileHelper.Object); var executor = new TestSourceArgumentExecutor(options); executor.Initialize(testFilePath);