Skip to content

Commit 6bb61ce

Browse files
Make FromUrl and FromSource more friendly (#1910)
* BenchmarkRunner.FromUrl/FromSource more friendly * Hide them because they don't work * Change ArgumentException with InvalidBenchmarkDeclarationException
1 parent c99ba30 commit 6bb61ce

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/BenchmarkDotNet/Running/BenchmarkConverter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static partial class BenchmarkConverter
2121
public static BenchmarkRunInfo TypeToBenchmarks(Type type, IConfig config = null)
2222
{
2323
if (type.IsGenericTypeDefinition)
24-
throw new ArgumentException($"{type.Name} is generic type definition, use BenchmarkSwitcher for it"); // for "open generic types" should be used BenchmarkSwitcher
24+
throw new InvalidBenchmarkDeclarationException($"{type.Name} is generic type definition, use BenchmarkSwitcher for it"); // for "open generic types" should be used BenchmarkSwitcher
2525

2626
// We should check all methods including private to notify users about private methods with the [Benchmark] attribute
2727
var benchmarkMethods = GetOrderedBenchmarkMethods(type.GetMethods(AllMethodsFlags));

src/BenchmarkDotNet/Running/BenchmarkRunnerDirty.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Linq;
34
using System.Reflection;
45
using System.Runtime.CompilerServices;
@@ -65,14 +66,22 @@ public static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
6566
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(benchmarkRunInfos));
6667
}
6768

69+
/// <summary>
70+
/// Supported only on Full .NET Framework. Not recommended.
71+
/// </summary>
6872
[PublicAPI]
73+
[EditorBrowsable(EditorBrowsableState.Never)]
6974
public static Summary RunUrl(string url, IConfig config = null)
7075
{
7176
using (DirtyAssemblyResolveHelper.Create())
7277
return RunWithExceptionHandling(() => RunUrlWithDirtyAssemblyResolveHelper(url, config));
7378
}
7479

80+
/// <summary>
81+
/// Supported only on Full .NET Framework. Not recommended.
82+
/// </summary>
7583
[PublicAPI]
84+
[EditorBrowsable(EditorBrowsableState.Never)]
7685
public static Summary RunSource(string source, IConfig config = null)
7786
{
7887
using (DirtyAssemblyResolveHelper.Create())
@@ -110,13 +119,13 @@ private static Summary[] RunWithDirtyAssemblyResolveHelper(BenchmarkRunInfo[] be
110119
private static Summary RunUrlWithDirtyAssemblyResolveHelper(string url, IConfig config = null)
111120
=> RuntimeInformation.IsFullFramework
112121
? BenchmarkRunnerClean.Run(BenchmarkConverter.UrlToBenchmarks(url, config)).Single()
113-
: throw new NotSupportedException("Supported only on Full .NET Framework");
122+
: throw new InvalidBenchmarkDeclarationException("Supported only on Full .NET Framework");
114123

115124
[MethodImpl(MethodImplOptions.NoInlining)]
116125
private static Summary RunSourceWithDirtyAssemblyResolveHelper(string source, IConfig config = null)
117126
=> RuntimeInformation.IsFullFramework
118127
? BenchmarkRunnerClean.Run(BenchmarkConverter.SourceToBenchmarks(source, config)).Single()
119-
: throw new NotSupportedException("Supported only on Full .NET Framework");
128+
: throw new InvalidBenchmarkDeclarationException("Supported only on Full .NET Framework");
120129

121130
private static Summary RunWithExceptionHandling(Func<Summary> run)
122131
{

src/BenchmarkDotNet/Running/ClassicBenchmarkConverter.cs

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using BenchmarkDotNet.Configs;
1212
using BenchmarkDotNet.Environments;
1313
using BenchmarkDotNet.Loggers;
14+
using BenchmarkDotNet.Portability;
1415
using Microsoft.CSharp;
1516

1617
namespace BenchmarkDotNet.Running
@@ -23,6 +24,9 @@ public static partial class BenchmarkConverter
2324

2425
public static BenchmarkRunInfo[] UrlToBenchmarks(string url, IConfig config = null)
2526
{
27+
if (!RuntimeInformation.IsFullFramework)
28+
throw new NotSupportedException("Supported only on Full .NET Framework.");
29+
2630
var logger = HostEnvironmentInfo.FallbackLogger;
2731

2832
url = GetRawUrl(url);
@@ -63,6 +67,9 @@ public static BenchmarkRunInfo[] UrlToBenchmarks(string url, IConfig config = nu
6367

6468
public static BenchmarkRunInfo[] SourceToBenchmarks(string source, IConfig config = null)
6569
{
70+
if (!RuntimeInformation.IsFullFramework)
71+
throw new NotSupportedException("Supported only on Full .NET Framework.");
72+
6673
string benchmarkContent = source;
6774
CompilerResults compilerResults;
6875
using (var cSharpCodeProvider = new CSharpCodeProvider()) {

0 commit comments

Comments
 (0)