MetalamaAPI documentationAdvanced APIMetalama.​Testing.​Aspect­TestingTest­Options
Open sandboxFocus

TestOptions Class

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
System.Object
TestOptions
Namespace: Metalama.Testing.AspectTesting
Assembly: Metalama.Testing.AspectTesting.dll
Syntax
public class TestOptions : Object

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 ApplyCodeFix or PreviewCodeFix. 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.

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).

DependencyLicenseExpression
DependencyLicenseFile

Gets or sets the name of a file in the project directory containing the license key to be used to compile the dependency. To set this option in a test, add this comment to your test file: // @DependencyLicenseFile(file).

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).

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.

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.

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).

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.

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.

LicenseExpression
LicenseFile

Gets or sets the name of a file in the project directory containing the license key. To set this option in a test, add this comment to your test file: // @LicenseFile(file).

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.

OutputAllSyntaxTrees

Gets or sets a value indicating whether all input syntax trees should be used as a part of test output. If false only the primary syntax tree is processed and used as test output. If true, all syntax trees are processed and used as test output. To set this option in a test, add this comment to your test file: // @OutputAllSyntaxTrees.

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

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.

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 Metalama.Testing.AspectTesting.TestResult.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.

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).

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.

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).

TestRunnerFactoryType

Gets or sets the name of the test runner factory type (implementing Metalama.Testing.AspectTesting.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.

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.