Skip to content

Commit 96042ff

Browse files
Add --test-assumptions option (#3185)
### Changes Add the `--test-assumptions` option to all execution commands: run,build,translate,test Note that I've written the description of the option to be aspirational, so that it indicates what we want this option to do, with the note that it's experimental and after that an explanation of what it currently does. I've also simplified the option so it's just an off/on boolean, instead of allowing using to choose under what conditions they want to add tests, since I don't yet see a use-case for the previous `:TestExterns` option. Feel free to discuss! ### Testing Add the new option in a littish test <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
1 parent 01c924a commit 96042ff

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Source/DafnyCore/Options/CommonOptionBag.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.CommandLine;
3+
using System.Diagnostics.Tracing;
34
using System.Linq;
45

56
namespace Microsoft.Dafny;
@@ -124,13 +125,26 @@ Note that quantifier variable domains (<- <Domain>) are available in both syntax
124125
public static readonly Option<bool> IncludeRuntime = new("--include-runtime",
125126
"Include the Dafny runtime as source in the target language.");
126127

128+
public enum TestAssumptionsMode {
129+
None,
130+
Externs
131+
}
132+
133+
public static readonly Option<TestAssumptionsMode> TestAssumptions = new("--test-assumptions", () => TestAssumptionsMode.None, @"
134+
(experimental) When turned on, inserts runtime tests at locations where (implicit) assumptions occur, such as when calling or being called by external code and when using assume statements.
135+
136+
Functionality is still being expanded. Currently only checks contracts on every call to a function or method marked with the {:extern} attribute.".TrimStart());
137+
127138
static CommonOptionBag() {
128139
DafnyOptions.RegisterLegacyBinding(SolverPath, (options, value) => {
129140
if (!string.IsNullOrEmpty(value)) {
130141
options.ProverOptions.Add($"PROVER_PATH={value}");
131142
}
132143
});
133144

145+
DafnyOptions.RegisterLegacyBinding(TestAssumptions, (options, value) => {
146+
options.TestContracts = value == TestAssumptionsMode.Externs ? DafnyOptions.ContractTestingMode.Externs : DafnyOptions.ContractTestingMode.None;
147+
});
134148
DafnyOptions.RegisterLegacyBinding(ManualLemmaInduction, (options, value) => {
135149
if (value) {
136150
options.Induction = 1;

Source/DafnyCore/Options/ICommandSpec.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static ICommandSpec() {
3838
BoogieOptionBag.NoVerify,
3939
CommonOptionBag.EnforceDeterminism,
4040
CommonOptionBag.OptimizeErasableDatatypeWrapper,
41+
CommonOptionBag.TestAssumptions
4142
}.Concat(VerificationOptions).ToList();
4243

4344
public static IReadOnlyList<Option> ConsoleOutputOptions = new List<Option>(new Option[] {

Test/contract-wrappers/AllExterns.dfy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: ! %dafny /compile:4 /noVerify /runAllTests:1 /testContracts:Externs %s %s.externs.cs > %t
1+
// RUN: ! %baredafny test %args --no-verify --test-assumptions=externs %s %s.externs.cs > %t
22
// RUN: %diff "%s.expect" "%t"
33
// RUN: %OutputCheck --file-to-check "%S/AllExterns.cs" "%s"
44
// CHECK: .*Foo____dafny__checked\(x\).*

0 commit comments

Comments
 (0)