-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exposing --output and --spill-translation in dafny test, per Issue 3612 #3769
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8e1da2e
Exposing --output and --spill-translation in dafny test, per Issue 3612
80e37f4
Adding news
4cd321d
Merge branch 'master' into cok-3612-test-command
davidcok 8289059
removing hidden flag for --spill-translation
007348d
Improving test command: Issues 3744, 3369, 3612, 3221
7236725
Adding documentation
de5de9c
Adding documentation
2b0763e
Merge branch 'master' into cok-3612-test-command
atomb 0829a1f
Merge branch 'master' into cok-3612-test-command
davidcok 233c9e7
Merge branch 'master' of https://github.com/dafny-lang/dafny into cok…
7978c88
Merge branch 'master' into cok-3612-test-command
davidcok 6437fe0
Merge branch 'cok-3612-test-command' of https://github.com/davidcok/d…
213fa78
Fixing test failures
af232cd
Checking for empty string
5e14a21
Merge branch 'master' into cok-3612-test-command
davidcok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,17 @@ | |
using System.Diagnostics.Contracts; | ||
using System.Linq; | ||
using Microsoft.Boogie; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Microsoft.Dafny; | ||
|
||
public class RunAllTestsMainMethod : IRewriter { | ||
|
||
/** The name used for Main when executing tests. Should be a name that cannot be a Dafny name, | ||
that Dafny will not use as a mangled Dafny name for any backend, and that is not likely | ||
to be chosen by the user as an extern name. **/ | ||
public static string SyntheticTestMainName = "_Test__Main_"; | ||
|
||
public RunAllTestsMainMethod(ErrorReporter reporter) : base(reporter) { | ||
} | ||
|
||
|
@@ -19,17 +25,12 @@ public RunAllTestsMainMethod(ErrorReporter reporter) : base(reporter) { | |
/// errors much earlier in the pipeline. | ||
/// </summary> | ||
internal override void PreResolve(Program program) { | ||
var hasMain = Compilers.SinglePassCompiler.HasMain(program, out var mainMethod); | ||
if (hasMain) { | ||
Reporter.Error(MessageSource.Rewriter, mainMethod.tok, "Cannot use /runAllTests on a program with a main method"); | ||
return; | ||
} | ||
|
||
// Verifying the method isn't yet possible since the translation of try/recover statments is not implemented, | ||
// and would be low-value anyway. | ||
var noVerifyAttribute = new Attributes("verify", new List<Expression> { new LiteralExpr(Token.NoToken, false) }, null); | ||
|
||
mainMethod = new Method(RangeToken.NoToken, new Name("Main"), false, false, | ||
var mainMethod = new Method(RangeToken.NoToken, new Name(SyntheticTestMainName), false, false, | ||
new List<TypeParameter>(), new List<Formal>(), new List<Formal>(), | ||
new List<AttributedExpression>(), | ||
new Specification<FrameExpression>(new List<FrameExpression>(), null), | ||
|
@@ -98,6 +99,12 @@ internal override void PostResolve(Program program) { | |
foreach (var moduleDefinition in program.CompileModules) { | ||
foreach (var callable in ModuleDefinition.AllCallables(moduleDefinition.TopLevelDecls)) { | ||
if ((callable is Method method) && Attributes.Contains(method.Attributes, "test")) { | ||
var regex = program.Options.MethodsToTest; | ||
if (regex != null) { | ||
string name = method.FullDafnyName; | ||
if (!Regex.Match(name, regex).Success) continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should have braces, as the CI complains about. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
} | ||
|
||
// print "TestMethod: "; | ||
mainMethodStatements.Add(Statement.CreatePrintStmt(tok, | ||
Expression.CreateStringLiteral(tok, $"{method.FullDafnyName}: "))); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %baredafny test "%s" > "%t" | ||
// RUN: %baredafny test --methods-to-test='q' "%s" >> "%t" | ||
// RUN: %baredafny test --methods-to-test='m' "%s" >> "%t" | ||
// RUN: %baredafny test --methods-to-test='M.*' "%s" >> "%t" | ||
// RUN: %baredafny test --methods-to-test='^.$' "%s" >> "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
method {:test} m() { | ||
print "Testing m\n"; | ||
} | ||
method {:test} q() { | ||
print "Testing q\n"; | ||
} | ||
method {:test} pp() { | ||
print "Testing pp\n"; | ||
} | ||
|
||
module M { | ||
|
||
method {:test} m() { | ||
print "Testing M.m\n"; | ||
} | ||
method {:test} t() { | ||
print "Testing M.t\n"; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
Dafny program verifier finished with 0 verified, 0 errors | ||
M.m: Testing M.m | ||
PASSED | ||
M.t: Testing M.t | ||
PASSED | ||
m: Testing m | ||
PASSED | ||
q: Testing q | ||
PASSED | ||
pp: Testing pp | ||
PASSED | ||
|
||
Dafny program verifier finished with 0 verified, 0 errors | ||
q: Testing q | ||
PASSED | ||
|
||
Dafny program verifier finished with 0 verified, 0 errors | ||
M.m: Testing M.m | ||
PASSED | ||
m: Testing m | ||
PASSED | ||
|
||
Dafny program verifier finished with 0 verified, 0 errors | ||
M.m: Testing M.m | ||
PASSED | ||
M.t: Testing M.t | ||
PASSED | ||
|
||
Dafny program verifier finished with 0 verified, 0 errors | ||
m: Testing m | ||
PASSED | ||
q: Testing q | ||
PASSED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// RUN: %baredafny test "%s" > "%t" | ||
// RUN: %baredafny run "%s" >> "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
method Main() { | ||
print "Main\n"; | ||
} | ||
|
||
method {:test} Test() { | ||
print "Test\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
Dafny program verifier finished with 0 verified, 0 errors | ||
Test: Test | ||
PASSED | ||
|
||
Dafny program verifier finished with 0 verified, 0 errors | ||
Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* dafny test accepts a --methods-to-test option whose value is a regular expression selecting which tests to include in the test run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* Exposes the --output and --spill-translation options for the dafny test command | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Main and {:test} methods may now be in the same program |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code at the end of this file still calls
hasMain
and an assertion fails when running with/testContracts
. I wonder whether the implementation ofHasMain
need to be updated to account for the possibility of the new synthetic name you're using?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was a satisfyingly simple fix. :)