public void InitialMatchers() { var matchers = new IssueMatchersConfig { Matchers = { new IssueMatcherConfig { Owner = "my-matcher-1", Patterns = new[] { new IssuePatternConfig { Pattern = "ERROR: (.+)", Message = 1, }, }, }, new IssueMatcherConfig { Owner = "my-matcher-2", Patterns = new[] { new IssuePatternConfig { Pattern = "NOT GOOD: (.+)", Message = 1, }, }, }, }, }; using (Setup(matchers: matchers)) using (_outputManager) { Process("ERROR: it is broken"); Process("NOT GOOD: that did not work"); Assert.Equal(2, _issues.Count); Assert.Equal("it is broken", _issues[0].Item1.Message); Assert.Equal("that did not work", _issues[1].Item1.Message); Assert.Equal(0, _commands.Count); Assert.Equal(0, _messages.Count); } }
public void MatcherLineColumn() { var matchers = new IssueMatchersConfig { Matchers = { new IssueMatcherConfig { Owner = "my-matcher-1", Patterns = new[] { new IssuePatternConfig { Pattern = @"\((.+),(.+)\): (.+)", Line = 1, Column = 2, Message = 3, }, }, }, }, }; using (Setup(matchers: matchers)) using (_outputManager) { Process("(12,34): real bad"); Process("(12,thirty-four): it is broken"); Process("(twelve,34): not working"); Assert.Equal(3, _issues.Count); Assert.Equal("real bad", _issues[0].Item1.Message); Assert.Equal("12", _issues[0].Item1.Data["line"]); Assert.Equal("34", _issues[0].Item1.Data["col"]); Assert.Equal("it is broken", _issues[1].Item1.Message); Assert.Equal("12", _issues[1].Item1.Data["line"]); Assert.False(_issues[1].Item1.Data.ContainsKey("col")); Assert.Equal("not working", _issues[2].Item1.Message); Assert.False(_issues[2].Item1.Data.ContainsKey("line")); Assert.Equal("34", _issues[2].Item1.Data["col"]); Assert.Equal(0, _commands.Count); Assert.Equal(2, _messages.Count); Assert.Equal("##[debug]Unable to parse column number 'thirty-four'", _messages[0]); Assert.Equal("##[debug]Unable to parse line number 'twelve'", _messages[1]); } }
public void MatcherCode() { var matchers = new IssueMatchersConfig { Matchers = { new IssueMatcherConfig { Owner = "my-matcher-1", Patterns = new[] { new IssuePatternConfig { Pattern = @"(.*): (.+)", Code = 1, Message = 2, }, }, }, }, }; using (Setup(matchers: matchers)) using (_outputManager) { Process("BAD: real bad"); Process(": not working"); Assert.Equal(2, _issues.Count); Assert.Equal("real bad", _issues[0].Item1.Message); Assert.Equal("BAD", _issues[0].Item1.Data["code"]); Assert.Equal("not working", _issues[1].Item1.Message); Assert.False(_issues[1].Item1.Data.ContainsKey("code")); Assert.Equal(0, _commands.Count); Assert.Equal(0, _messages.Count); } }
public void AddMatcher_Prepend() { var matchers = new IssueMatchersConfig { Matchers = { new IssueMatcherConfig { Owner = "my-matcher-1", Patterns = new[] { new IssuePatternConfig { Pattern = "ERROR: (.+)", Message = 1, }, }, }, new IssueMatcherConfig { Owner = "my-matcher-2", Patterns = new[] { new IssuePatternConfig { Pattern = "NOT GOOD: (.+)", Message = 1, }, }, }, }, }; using (Setup(matchers: matchers)) using (_outputManager) { Process("ERROR: message 1"); Process("NOT GOOD: message 2"); Add(new IssueMatcherConfig { Owner = "new-matcher", Patterns = new[] { new IssuePatternConfig { Pattern = "ERROR: (.+) END MESSAGE", Message = 1, }, }, }); Process("ERROR: message 3 END MESSAGE"); Process("ERROR: message 4"); Process("NOT GOOD: message 5"); Assert.Equal(5, _issues.Count); Assert.Equal("message 1", _issues[0].Item1.Message); Assert.Equal("message 2", _issues[1].Item1.Message); Assert.Equal("message 3", _issues[2].Item1.Message); Assert.Equal("message 4", _issues[3].Item1.Message); Assert.Equal("message 5", _issues[4].Item1.Message); Assert.Equal(0, _commands.Count); Assert.Equal(0, _messages.Count); } }
public async void MatcherFile() { Environment.SetEnvironmentVariable("RUNNER_TEST_GET_REPOSITORY_PATH_FAILSAFE", "2"); var matchers = new IssueMatchersConfig { Matchers = { new IssueMatcherConfig { Owner = "my-matcher-1", Patterns = new[] { new IssuePatternConfig { Pattern = @"(.+): (.+)", File = 1, Message = 2, }, }, }, }, }; using (var hostContext = Setup(matchers: matchers)) using (_outputManager) { // Setup github.workspace, github.repository var workDirectory = hostContext.GetDirectory(WellKnownDirectory.Work); ArgUtil.NotNullOrEmpty(workDirectory, nameof(workDirectory)); Directory.CreateDirectory(workDirectory); var workspaceDirectory = Path.Combine(workDirectory, "workspace"); Directory.CreateDirectory(workspaceDirectory); _executionContext.Setup(x => x.GetGitHubContext("workspace")).Returns(workspaceDirectory); _executionContext.Setup(x => x.GetGitHubContext("repository")).Returns("my-org/workflow-repo"); // Setup some git repositories // <WORKSPACE>/workflow-repo // <WORKSPACE>/workflow-repo/nested-other-repo // <WORKSPACE>/other-repo // <WORKSPACE>/other-repo/nested-workflow-repo var workflowRepository = Path.Combine(workspaceDirectory, "workflow-repo"); var nestedOtherRepository = Path.Combine(workspaceDirectory, "workflow-repo", "nested-other-repo"); var otherRepository = Path.Combine(workspaceDirectory, workflowRepository, "nested-other-repo"); var nestedWorkflowRepository = Path.Combine(workspaceDirectory, "other-repo", "nested-workflow-repo"); await CreateRepository(hostContext, workflowRepository, "https://github.com/my-org/workflow-repo"); await CreateRepository(hostContext, nestedOtherRepository, "https://github.com/my-org/other-repo"); await CreateRepository(hostContext, otherRepository, "https://github.com/my-org/other-repo"); await CreateRepository(hostContext, nestedWorkflowRepository, "https://github.com/my-org/workflow-repo"); // Create test files var file_noRepository = Path.Combine(workspaceDirectory, "no-repo.txt"); var file_workflowRepository = Path.Combine(workflowRepository, "workflow-repo.txt"); var file_workflowRepository_nestedDirectory = Path.Combine(workflowRepository, "subdir", "subdir2", "workflow-repo-nested-dir.txt"); var file_workflowRepository_failsafe = Path.Combine(workflowRepository, "failsafe-subdir", "failsafe-subdir2", "failsafe-subdir3", "workflow-repo-failsafe.txt"); var file_nestedOtherRepository = Path.Combine(nestedOtherRepository, "nested-other-repo"); var file_otherRepository = Path.Combine(otherRepository, "other-repo.txt"); var file_nestedWorkflowRepository = Path.Combine(nestedWorkflowRepository, "nested-workflow-repo.txt"); foreach (var file in new[] { file_noRepository, file_workflowRepository, file_workflowRepository_nestedDirectory, file_workflowRepository_failsafe, file_nestedOtherRepository, file_otherRepository, file_nestedWorkflowRepository }) { Directory.CreateDirectory(Path.GetDirectoryName(file)); File.WriteAllText(file, ""); } // Process Process($"{file_noRepository}: some error 1"); Process($"{file_workflowRepository}: some error 2"); Process($"{file_workflowRepository.Substring(workspaceDirectory.Length + 1)}: some error 3"); // Relative path from workspace dir Process($"{file_workflowRepository_nestedDirectory}: some error 4"); Process($"{file_workflowRepository_failsafe}: some error 5"); Process($"{file_nestedOtherRepository}: some error 6"); Process($"{file_otherRepository}: some error 7"); Process($"{file_nestedWorkflowRepository}: some error 8"); Assert.Equal(8, _issues.Count); Assert.Equal("some error 1", _issues[0].Item1.Message); Assert.False(_issues[0].Item1.Data.ContainsKey("file")); Assert.Equal("some error 2", _issues[1].Item1.Message); Assert.Equal(file_workflowRepository.Substring(workflowRepository.Length + 1).Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), _issues[1].Item1.Data["file"]); Assert.Equal("some error 3", _issues[2].Item1.Message); Assert.Equal(file_workflowRepository.Substring(workflowRepository.Length + 1).Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), _issues[2].Item1.Data["file"]); Assert.Equal("some error 4", _issues[3].Item1.Message); Assert.Equal(file_workflowRepository_nestedDirectory.Substring(workflowRepository.Length + 1).Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), _issues[3].Item1.Data["file"]); Assert.Equal("some error 5", _issues[4].Item1.Message); Assert.False(_issues[4].Item1.Data.ContainsKey("file")); Assert.Equal("some error 6", _issues[5].Item1.Message); Assert.False(_issues[5].Item1.Data.ContainsKey("file")); Assert.Equal("some error 7", _issues[6].Item1.Message); Assert.False(_issues[6].Item1.Data.ContainsKey("file")); Assert.Equal("some error 8", _issues[7].Item1.Message); Assert.Equal(file_nestedWorkflowRepository.Substring(nestedWorkflowRepository.Length + 1).Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), _issues[7].Item1.Data["file"]); } Environment.SetEnvironmentVariable("RUNNER_TEST_GET_REPOSITORY_PATH_FAILSAFE", ""); }
public void ResetsOtherMatchers() { var matchers = new IssueMatchersConfig { Matchers = { new IssueMatcherConfig { Owner = "my-matcher-1", Patterns = new[] { new IssuePatternConfig { Pattern = "Matches both line 1: .+", }, new IssuePatternConfig { Pattern = "Matches 1 only line 2: (.+)", Message = 1, }, }, }, new IssueMatcherConfig { Owner = "my-matcher-2", Patterns = new[] { new IssuePatternConfig { Pattern = "Matches both line 1: (.+)", }, new IssuePatternConfig { Pattern = "(.+)", Message = 1, }, }, }, }, }; using (Setup(matchers: matchers)) using (_outputManager) { Process("Matches both line 1: hello"); Process("Matches 1 only line 2: it broke"); Process("regular message 1"); Process("regular message 2"); Process("Matches both line 1: hello again"); Process("oh no, another error"); Assert.Equal(2, _issues.Count); Assert.Equal("it broke", _issues[0].Item1.Message); Assert.Equal("oh no, another error", _issues[1].Item1.Message); Assert.Equal(0, _commands.Count); Assert.Equal(4, _messages.Count); Assert.Equal("Matches both line 1: hello", _messages[0]); Assert.Equal("regular message 1", _messages[1]); Assert.Equal("regular message 2", _messages[2]); Assert.Equal("Matches both line 1: hello again", _messages[3]); } }