Open sandboxFocus

Class TestOptions

A set of test options, which can be included in the source text of tests using special comments like // @ReportOutputWarnings. This class is JSON-serializable. Another way to define options is to add a file named metalamaTests.json into the test directory or any parent directory.

Inheritance
TestOptions
Namespace: Metalama.Testing.AspectTesting
Assembly: Metalama.Testing.AspectTesting.dll
Syntax
[JsonObject]
public class TestOptions

Constructors

Name Description
TestOptions()

Properties

Name Description
AcceptInvalidInput

Gets or sets a value indicating whether the test should be executed even if the input compilation has errors. To enable this option in a test, add this comment to your test file: // @AcceptInvalidInput.

AddHtmlTitles

Gets or sets a value indicating whether titles (tooltips) should be added to HTML files. To enable this option in a test, add this comment to your test file: // @AddHtmlTitles.

AllowCompileTimeDynamicCode

Gets or sets a value indicating whether the test is allowed to have compile-time code that has dynamic calls. To enable this option in a test, add this comment to your test file: // @AllowCompileTimeDynamicCode.

AppliedCodeFixIndex

Gets or sets the zero-based index of the code fix to be applied when TestScenario is set to CodeFix or CodeFixPreview. To set this option in a test, add this comment to your test file: // @AppliedCodeFixIndex(id).

CheckMemoryLeaks

Gets or sets a value indicating whether memory leaks should be detected. This features is supported from .NET 6. Leaks are detected by trying to unload the AssemblyLoadContext. If it fails to unload in due time, it means that Metalama or the user code has a static reference to compile-time assemblies. To enable this option in a test, add this comment to your test file: // @CheckMemoryLeaks.

ClearIgnoredDiagnostics

Gets or sets a value indicating whether the list of IgnoredDiagnostics inherited from the parent level (directory or base directory) must be cleared before new diagnostics are added to this list. This option is not inherited from the base level. To enable this option in a test, add this comment to your test file: // @ClearIgnoredDiagnostics.

CompareProgramOutput

Gets or sets a value indicating whether the program output should be compared to its expected value. The default value is true. To disable this option in a test, add this comment to your test file: // @DisableCompareProgramOutput.

CompareWhitespace

Gets or sets a value indicating whether whitespace are taken into account while comparing the the expected output t.cs file with the actual output. The default behavior is false. To enable this option in a test, add this comment to your test file: // @PreserveWhitespace.

DefinedConstants

Gets the set of preprocessor symbols that are defined for this test. To add an item into this collection from a test, add this comment to your test file: // @DefinedConstant(constant). All constants of the test project and TESTRUNNER and METALAMA are defined by default. Constants added via DependencyDefinedConstants option are not added.

DependencyDefinedConstants

Gets the set of preprocessor symbols that are defined for this test dependency. To add an item into this collection from a test, add this comment to your test file: // @DependencyDefinedConstant(constant). All constants of the test project and TESTRUNNER and METALAMA are defined by default. Constants added via DefinedConstants option are not added.

DependencyLanguageVersion

Gets or sets the version of the C# language that the dependencies of the test should be compiled with. To set this option in a test, add this comment to your test file: // @DependencyLanguageVersion(version).

DependencyLicenseKey

Gets or sets the name of the license key used to compile the test dependency. The LicenseKeyProviderType property must be specified. To set this option in a test, add this comment to your test file: // @DependencyLicenseKey(name).

EnableLogging

Gets or sets a value indicating whether Metalama should produce logs and output them to the Xunit test log. To enable this option in a test, add this comment to your test file: // @EnableLogging.

ExcludeAssemblyAttributes

Gets or sets a value indicating that assembly-wide attributes should not be added to the test output. The default value is false. To enable this option in a test, add this comment to your test file: // @ExcludeAssemblyAttributes.

ExecuteProgram

Gets or sets a value indicating whether the Program.Main method should be executed if it exists. The default value is true. To disable this option in a test, add this comment to your test file: // @DisableExecuteProgram.

ExpectedEndOfLine

Gets or sets a value indicating which end-of-line sequence is expected. To set this option in a test, add this comment to your test file: // @ExpectedEndOfLine(eol) where EOL is CR, LF or CRLF.

ExpectedException

Gets or sets the fully qualified name of expected exception type to be thrown. To set this option in a test, add this comment to your test file: // @ExpectedException(fully qualified exception type name).

ForbiddenConstants

Gets the set of preprocessor symbols that are forbidden for this test, test would be skipped if any is present. To add an item into this collection from a test, add this comment to your test file: // @ForbiddenConstant(constant).

FormatCompileTimeCode

Gets or sets a value indicating whether code of the compile-time project should be formatted. The default value is false in the default test runner, but true in Aspect Workbench. To set this option in a test, add this comment to your test file: // @FormatCompileTimeCode(value) where value is true or false.

FormatOutput

Gets or sets a value indicating whether the output t.cs file should be formatted, which includes simplifying the code and adding using directives. The default behavior is true. To enable this option in a test, add this comment to your test file: // @FormatOutput.

IgnoreUserProfileLicenses

Gets or sets a value indicating whether the licenses registered in the user profile should be ignored. The default value is false. When this property is set to true, user-profile licenses are not loaded for this test.

IgnoredDiagnostics

Gets a list of warnings that are not reported even if ReportOutputWarnings is set to true. To add an item into this collection from a test, add this comment to your test file: // @IgnoredDiagnostic(id).

IncludeAllSeverities

Gets or sets a value indicating whether diagnostics of all severities should be included in the rest result. By default, only warnings and errors are included. To enable this option in a test, add this comment to your test file: // @IncludeAllSeverities.

IncludeLineNumberInDiagnosticReport

Gets or sets a value indicating whether the line number should be included in reports of warnings or errors in the consolidated test output. The default value is false. To enable this option in a test, add this comment to your test file: // @IncludeLineNumberInDiagnosticReport.

IncludedFiles

Gets the list of source code files that should be included in the compilation. To enable this option in a test, add this comment to your test file: // @Include(relativePath).

InvalidSourceOptions
IsSkipped

Gets a value indicating whether the current test must be skipped.

KeepDisabledCode

Gets or sets a value indicating whether disabled code should be kept as trivia. To set this option in a test, add this comment to your test file: // @KeepDisabledCode.

LanguageFeatures

Gets or sets the list of C# language features that the test should be compiled with. To set this option in a test, add this comment to your test file: // @LanguageFeature(feature) or // @LanguageFeature(feature=value).

LanguageVersion

Gets or sets the version of the C# language that the test should be compiled with. To set this option in a test, add this comment to your test file: // @LanguageVersion(version).

LaunchDebugger

Gets or sets a value indicating whether the JIT debugger should be launched before executing the test. The default value is false. To enable this option in a test, add this comment to your test file: // @LaunchDebugger.

LicenseKey

Gets or sets the name of the license key used to compile the test input. The LicenseKeyProviderType property must be specified. To set this option in a test, add this comment to your test file: // @LicenseKey(name).

LicenseKeyProviderType

Gets or sets the name of the type implementing the ILicenseKeyProvider. This property is required when LicenseKey or DependencyLicenseKey is specified.

MainMethod

Gets or sets the name of the Main method. The default value of this property is Main. This option is useful to work around the CS0017 error. To set this option in a test, add this comment to your test file: // @MainMethod(name).

NullabilityDisabled

Gets or sets a value indicating whether C# nullability is disabled for the compilation. To enable this option in a test, add this comment to your test file: // @NullabilityDisabled.

OutputAssemblyType

Gets or sets a value indicating which type of the output assembly should be used for the test. Currently valid values are DllExe (default).

OutputCompilationDisabled

Gets or sets a value indicating whether the output file must be compiled into a binary (e.g. emitted). To enable this option in a test, add this comment to your test file: // @OutputCompilationDisabled.

PreserveWhitespace
ProjectName

Gets or sets the project of the test. By default, the test file name without extension is used.

References

Gets the list of assembly names that should be included in the compilation. To add a named assembly reference, add this comment to your test file: // @AssemblyReference(assemblyName).

RemoveDiagnosticMessage

Gets or sets a value indicating that the test output should not include the diagnostic message, but only the diagnostic ID. The default value is false. To enable this option in a test, add this comment to your test file: // @RemoveDiagnosticMessage.

RemoveOutputCode

Gets or sets a value indicating that the test output should not include the transformed code, but only the diagnostics. The default value is false. To enable this option in a test, add this comment to your test file: // @RemoveOutputCode.

ReportErrorMessage

Gets or sets a value indicating whether the ErrorMessage should be added to the test output. You can only define this option in the metalamaTests.json file of a directory.

ReportOutputWarnings

Gets or sets a value indicating whether the diagnostics of the compilation of the transformed target code should be included in the test result. This is useful when diagnostic suppression is being tested. To enable this option in a test, add this comment to your test file: // @ReportOutputWarnings.

RequireOrderedAspects

Gets or sets a value indicating whether an error should be reported if the compilation uses aspects that are not explicitly ordered. To enable this option in a test, add this comment to your test file: // @RequireOrderedAspects.

RequiredConstants

Gets the set of preprocessor symbols that are required for this test, otherwise the test would be skipped. To add an item into this collection from a test, add this comment to your test file: // @RequiredConstant(constant).

SkipAddingSystemFiles

Gets or sets a value indicating whether adding system files to the test compilation should be skipped. Namely, there is one file that adds the System.Runtime.CompilerServices.IsExternalInit type on .Net Framework. To enable this option in a test, add this comment to your test file: // @SkipAddingSystemFiles.

SkipReason

Gets or sets the reason for which the test must be skipped, or null if the test must not be skipped. To skip a test, add this comment to your test file: // @Skipped(reason).

TargetSyntaxTreeSuffix

Gets or sets a value indicating the target syntax tree suffix. This allows the selection of a different syntax tree for the test scenario. This is currently valid only for Preview scenario.

TestRunnerFactoryType

Gets or sets the name of the test runner factory type (implementing ITestRunnerFactory). You can only define this option in the metalamaTests.json file of a directory. This setting is for Metalama internal use only.

TestScenario

Gets or sets a value indicating the test scenario. See TestScenario enum values for details.

TestUnformattedOutput
WriteInputHtml

Gets or sets a value indicating whether HTML of syntax-highlighted files should be produced for input files. If true, these files are created to the obj/html directory. To enable this option in a test, add this comment to your test file: // @WriteInputHtml.

WriteOutputHtml

Gets or sets a value indicating whether HTML of syntax-highlighted files should be produced for the consolidated output file. If true, this file is created to the obj/html directory. Setting this property to true automatically sets the FormatOutput property to true. To enable this option in a test, add this comment to your test file: // @WriteOutputHtml.