Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: third_party/grpc/src/csharp/Grpc.Core.Tests/SanityTest.cs

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #region Copyright notice and license
2
3 // Copyright 2015, Google Inc.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 // * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 #endregion
33
34 using System;
35 using System.Collections.Generic;
36 using System.IO;
37 using System.Reflection;
38 using Grpc.Core;
39 using Grpc.Core.Internal;
40 using Grpc.Core.Utils;
41 using NUnit.Framework;
42
43 namespace Grpc.Core.Tests
44 {
45 public class SanityTest
46 {
47 /// <summary>
48 /// Because we depend on a native library, sometimes when things go wron g, the
49 /// entire NUnit test process crashes. To be able to track down problems better,
50 /// the NUnit tests are run by run_tests.py script in a separate process per test class.
51 /// The list of tests to run is stored in src/csharp/tests.json.
52 /// This test checks that the tests.json file is up to date by discoveri ng all the
53 /// existing NUnit tests in all test assemblies and comparing to content s of tests.json.
54 /// </summary>
55 [Test]
56 public void TestsJsonUpToDate()
57 {
58 var testClasses = DiscoverAllTestClasses();
59 string testsJson = GetTestsJson();
60
61 // we don't have a JSON parser at hand, but check that the test clas s
62 // name is contained in the file instead.
63 foreach (var className in testClasses) {
64 Assert.IsTrue(testsJson.Contains(className),
65 string.Format("Test class \"{0}\" is missing in C# tests.jso n file", className));
66 }
67 }
68
69 /// <summary>
70 /// Gets list of all test classes obtained by inspecting all the test as semblies.
71 /// </summary>
72 private List<string> DiscoverAllTestClasses()
73 {
74 var assemblies = GetTestAssemblies();
75
76 var testClasses = new List<string>();
77 foreach (var assembly in assemblies)
78 {
79 foreach (var t in assembly.GetTypes())
80 {
81 foreach (var m in t.GetMethods())
82 {
83 var attributes = m.GetCustomAttributes(typeof(NUnit.Fram ework.TestAttribute), true);
84 if (attributes.Length > 0)
85 {
86 testClasses.Add(t.FullName);
87 break;
88 }
89
90 }
91 }
92 }
93 testClasses.Sort();
94 return testClasses;
95 }
96
97 private string GetTestsJson()
98 {
99 var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembl y().Location);
100 var testsJsonFile = Path.Combine(assemblyDir, "..", "..", "..", "tes ts.json");
101
102 return File.ReadAllText(testsJsonFile);
103 }
104
105 private List<Assembly> GetTestAssemblies()
106 {
107 var result = new List<Assembly>();
108 var executingAssembly = Assembly.GetExecutingAssembly();
109
110 result.Add(executingAssembly);
111
112 var otherAssemblies = new[] {
113 "Grpc.Examples.Tests",
114 "Grpc.HealthCheck.Tests",
115 "Grpc.IntegrationTesting"
116 };
117 foreach (var assemblyName in otherAssemblies)
118 {
119 var location = executingAssembly.Location.Replace("Grpc.Core.Tes ts", assemblyName);
120 result.Add(Assembly.LoadFrom(location));
121 }
122 return result;
123 }
124 }
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698