Skip to content

Commit

Permalink
Fix: Other CLI files that are not found do not trigger exceptions (da…
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelMayer authored and davidcok committed Jan 20, 2023
1 parent 6fd8891 commit aa4f204
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Source/DafnyCore/DafnyMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public DafnyFile(string filePath, bool useStdin = false) {
}

private static string GetDafnySourceAttributeText(string dllPath) {
if (!File.Exists(dllPath)) {
throw new IllegalDafnyFile();
}
using var dllFs = new FileStream(dllPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var dllPeReader = new PEReader(dllFs);
var dllMetadataReader = dllPeReader.GetMetadataReader();
Expand Down
8 changes: 7 additions & 1 deletion Source/DafnyDriver/DafnyDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,13 @@ public static CommandLineArgumentsResult ProcessCommandLineArguments(string[] ar

var supportedExtensions = options.Compiler.SupportedExtensions;
if (supportedExtensions.Contains(extension)) {
otherFiles.Add(file);
// .h files are not part of the build, they are just emitted as includes
if (File.Exists(file) || extension == ".h") {
otherFiles.Add(file);
} else {
options.Printer.ErrorWriteLine(Console.Out, $"*** Error: file {file} not found");
return CommandLineArgumentsResult.PREPROCESSING_ERROR;
}
} else if (!isDafnyFile) {
if (string.IsNullOrEmpty(extension) && file.Length > 0 && (file[0] == '/' || file[0] == '-')) {
options.Printer.ErrorWriteLine(Console.Out,
Expand Down
2 changes: 2 additions & 0 deletions Test/git-issues/git-issue-2719.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// RUN: %exits-with 1 %baredafny foobar.dll "%s" > "%t"
// RUN: %diff "%s.expect" "%t"
1 change: 1 addition & 0 deletions Test/git-issues/git-issue-2719.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*** Error: file foobar.dll not found
2 changes: 1 addition & 1 deletion Test/git-issues/git-issue-590.dfy.expect
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*** Error: The command-line contains no .dfy files
*** Error: file x.cs not found
1 change: 1 addition & 0 deletions docs/dev/news/2719.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Nonexistent files passed on the CLI result in a graceful exit

0 comments on commit aa4f204

Please sign in to comment.