public void RecievesParserYamlAction() { var tapContent = "TAP version 13\r\n" + "1..4\r\n" + "ok 1 - Input file opened\r\n" + "not ok 2 - First line of the input valid\r\n" + " ---\r\n" + " message: \'First line invalid\'\r\n" + " ...\r\n" + "ok 3 - Read the rest of the file\r\n"; TestLine line = null; dynamic yaml = null; var parser = new TAPParser(); var ev = new ManualResetEvent(false); parser.OnYaml += (tl, o) => { line = tl; yaml = o; ev.Set(); }; var t = parser.ParseAsync(CreateMemoryStream(tapContent)); Assert.True(ev.WaitOne()); Assert.NotNull(yaml); Assert.NotNull(line); Assert.Equal(yaml, line.YAML); Assert.Equal("First line invalid", yaml["message"]); Assert.Equal("First line of the input valid", line.Description); t.Wait(); }
public void RecievesParserBailOutAction() { var tapContent = "TAP version 13\r\n" + "1..4\r\n" + "ok 1 - Input file opened\r\n" + "not ok 2 - First line of the input valid\r\n" + "BAIL OUT! SUNE LEFT THE BUILDING!"; var parser = new TAPParser(); var ev = new ManualResetEvent(false); string bailoutMessage = String.Empty; parser.OnBailout += s => { bailoutMessage = s; ev.Set(); }; var t = parser.ParseAsync(CreateMemoryStream(tapContent)); Assert.True(ev.WaitOne()); Assert.Equal("SUNE LEFT THE BUILDING!", bailoutMessage); var res = t.Result; Assert.True(res.BailedOut); }
public void RecievesParserTestLineAction() { var tapContent = "TAP version 13\n" + "1..3\n" + "ok - Sune\n" + "not ok 2 - Bune\n" + "not ok - Lune\n"; var ev = new CountdownEvent(3); var parser = new TAPParser(); TestLine testLine = null; parser.OnTestResult += line => { testLine = line; ev.Signal(); }; var t = parser.ParseAsync(CreateMemoryStream(tapContent)); ev.Wait(); Assert.Equal(0, ev.CurrentCount); Assert.NotNull(testLine); Assert.Equal("Lune", testLine.Description); t.Wait(); }
public void RecievesParserTestLineDiagnosticAction() { var tapContent = "TAP version 13\n" + "# Some diagnostics\n" + "# Some more diagnostics\n" + "ok # TODO Sune\n" + "# Some test diagnostic\n"; string diagnosticsMessage = string.Empty; int recievedCount = 0; TestLine testLine = null; var ev = new ManualResetEvent(false); var parser = new TAPParser(); parser.OnTestResultDiagnostic += (tl, message) => { recievedCount++; diagnosticsMessage = message; testLine = tl; ev.Set(); }; var t = parser.ParseAsync(CreateMemoryStream(tapContent)); Assert.True(ev.WaitOne()); Assert.Equal(1, recievedCount); Assert.Equal("Some test diagnostic", diagnosticsMessage); Assert.Equal("Sune", testLine.Directive); t.Wait(); }
public void RecievesParserDiagnosticAction() { var tapContent = "TAP version 13\n" + "# Some diagnostics\n" + "# Some more diagnostics\n" + "ok # TODO Sune\n" + "# Some test diagnostic\n" + "not ok # Skip Sune\n"; var diagnosticMessages = new List <string>(); var ev = new CountdownEvent(2); var parser = new TAPParser(); parser.OnDiagnostic += message => { diagnosticMessages.Add(message); ev.Signal(); }; var t = parser.ParseAsync(CreateMemoryStream(tapContent)); ev.Wait(); Assert.Equal(2, diagnosticMessages.Count); Assert.Equal("Some diagnostics", diagnosticMessages[0]); Assert.Equal("Some more diagnostics", diagnosticMessages[1]); t.Wait(); }
public void RecievesParserTestPlanAction() { var tapContent = "TAP version 13\n" + "1..5\n"; uint firstIndex = 0; uint lastIndex = 0; var ev = new ManualResetEvent(false); var parser = new TAPParser(); parser.OnTestPlan += u => { firstIndex = u.FirstTestIndex; lastIndex = u.LastTestIndex; ev.Set(); }; var t = parser.ParseAsync(CreateMemoryStream(tapContent)); Assert.True(ev.WaitOne()); Assert.Equal(1u, firstIndex); Assert.Equal(5u, lastIndex); t.Wait(); }
public void RecievesParserErrorAction() { var tapContent = "asdsdagsfad #¤)=/=!(¤=!¤9"; var ev = new ManualResetEvent(false); var parser = new TAPParser(); parser.OnError += exception => { ev.Set(); }; var t = parser.ParseAsync(CreateMemoryStream(tapContent)); Assert.True(ev.WaitOne()); t.Wait(); }
public void RecievesParserVersionAction() { var tapContent = "TAP version 13\n"; uint version = 0; var ev = new ManualResetEvent(false); var parser = new TAPParser(); parser.OnVersion += u => { version = u; ev.Set(); }; var t = parser.ParseAsync(CreateMemoryStream(tapContent)); Assert.True(ev.WaitOne()); Assert.Equal(13u, version); t.Wait(); }
public void ParseAsyncCancellation() { var tapContent = "TAP version 13\r\n" + "1..4\r\n" + "ok 1 - Input file opened\r\n" + "not ok 2 - First line of the input valid\r\n" + " ---\r\n" + " message: \'First line invalid\'\r\n" + " severity: fail\r\n" + " data:\r\n" + " got: \'Flirble\'\r\n" + " expect: \'Fnible\'\r\n" + " ...\r\n" + "ok 3 - Read the rest of the file\r\n" + "not ok 4 - Summarized correctly # TODO Not written yet\r\n" + " ---\r\n" + " message: \"Can\'t make summary yet\"\r\n" + " severity: todo\r\n" + " ..."; var parser = new TAPParser(); var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; tokenSource.Cancel(); bool recievedCancelledException = false; try { var res = parser.ParseAsync(CreateMemoryStream(tapContent), false, token).Result; } catch (AggregateException e) { if (e?.InnerException.GetType() == typeof(TaskCanceledException)) { recievedCancelledException = true; } } Assert.True(recievedCancelledException, "Failed to catch task cancelled exception."); }