diff --git a/Source/IntegrationTests/LitTests.cs b/Source/IntegrationTests/LitTests.cs index 0f559ce7d50..b91a4b5fa44 100644 --- a/Source/IntegrationTests/LitTests.cs +++ b/Source/IntegrationTests/LitTests.cs @@ -136,6 +136,8 @@ IEnumerable AddExtraArgs(IEnumerable args, IEnumerable l "%mv", (args, config) => MvCommand.Parse(args.ToArray()) }, { "%rm", (args, config) => RmCommand.Parse(args.ToArray()) + }, { + "%cp", (args, config) => CpCommand.Parse(args.ToArray()) }, { "%OutputCheck", OutputCheckCommand.Parse } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/DerivedModule.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/DerivedModule.dfy index 696c15acf2d..b95ecb1d1b1 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/DerivedModule.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/DerivedModule.dfy @@ -1,7 +1,8 @@ // RUN: %baredafny translate go --go-module-name=GoModule2 --library="%S/test.doo" --translation-record "%S/test-go.dtr" --output "%S/test3" "%s" -// RUN: cp -r "%S/go.*" "%S/test3-go/" -// RUN: cp -r "%S/../../../../../../../../../DafnyRuntime/DafnyRuntimeGo-gomod" "%S" -// RUN: cp -r "%S/DafnyModule1" "%S/test3-go/" +// RUN: %cp -rf "%S/go.mod" "%S/test3-go/go.mod" +// RUN: %cp -rf "%S/go.sum" "%S/test3-go/go.sum" +// RUN: %cp -rf "%S/../../../../../../../../../DafnyRuntime/DafnyRuntimeGo-gomod" "%S" +// RUN: %cp -rf "%S/DafnyModule1" "%S/test3-go/" // RUN: go run -C %S/test3-go/ test3.go > %t // RUN: %diff "%s.expect" "%t" module DafnyModule3 { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/dafnysource/helloworld.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/dafnysource/helloworld.dfy new file mode 100644 index 00000000000..75e0ff227c4 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/dafnysource/helloworld.dfy @@ -0,0 +1,9 @@ +// This file is used to regenerate PythonModule1.doo +// RUN: echo 'lit should ignore this file' + +module DafnyModule1 { + method HelloWorld() + { + print "Hello World"; + } +} diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/test-go.dtr b/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/test-go.dtr index c09c81885fb..d9d364ca0a9 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/test-go.dtr +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/test-go.dtr @@ -1,4 +1,4 @@ file_format_version = "1.0" -dafny_version = "4.7.0.0" +dafny_version = "4.8.0.0" [options_by_module.DafnyModule1] go-module-name = "GoModule1" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/test.doo b/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/test.doo index ce95bf59f7b..507fc7e0335 100644 Binary files a/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/test.doo and b/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/test.doo differ diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/singlemodule/dafnysource/helloworld.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/singlemodule/dafnysource/helloworld.dfy index 3b364b53539..07344c82f78 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/singlemodule/dafnysource/helloworld.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/singlemodule/dafnysource/helloworld.dfy @@ -1,6 +1,7 @@ // RUN: %baredafny translate go --go-module-name=GoModule1 "%s" --output "%S/test" -// RUN: cp -r "%S/go.*" "%S/test-go/" -// RUN: cp -r "%S/../../../../../../../../../../DafnyRuntime/DafnyRuntimeGo-gomod" "%S" +// RUN: %cp -rf "%S/go.mod" "%S/test-go/go.mod" +// RUN: %cp -rf "%S/go.sum" "%S/test-go/go.sum" +// RUN: %cp -rf "%S/../../../../../../../../../../DafnyRuntime/DafnyRuntimeGo-gomod" "%S" // RUN: go run -C %S/test-go/ test.go > %t // RUN: %diff "%s.expect" "%t" module DafnyModule1 { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/multimodule/PythonModule1.doo b/Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/multimodule/PythonModule1.doo index 73cac5cbf23..d02fd1ee749 100644 Binary files a/Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/multimodule/PythonModule1.doo and b/Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/multimodule/PythonModule1.doo differ diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/nestedmodule/SomeNestedModule.doo b/Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/nestedmodule/SomeNestedModule.doo index df92ea9bec1..984fce8d142 100644 Binary files a/Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/nestedmodule/SomeNestedModule.doo and b/Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/nestedmodule/SomeNestedModule.doo differ diff --git a/Source/XUnitExtensions/Lit/CpCommand.cs b/Source/XUnitExtensions/Lit/CpCommand.cs new file mode 100644 index 00000000000..c210dbb83ed --- /dev/null +++ b/Source/XUnitExtensions/Lit/CpCommand.cs @@ -0,0 +1,109 @@ +using System; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Xunit; +using Xunit.Abstractions; +using Xunit.Sdk; + +namespace XUnitExtensions.Lit { + public class CpCommand : ILitCommand { + + private readonly string options; + private readonly string fileOrFolder; + private readonly string destination; + + private CpCommand(string options, string fileOrFolder, string destination) { + this.options = options; + this.fileOrFolder = fileOrFolder; + this.destination = destination; + } + + public static ILitCommand Parse(string[] args) { + if (args.Length != 2 && args.Length != 3) { + throw new ArgumentException($"Wrong number of arguments for cp, expected 2 or 3 but got {args.Length}: " + string.Join(", ", args)); + } + + string fileOrFolder; + string destination; + string options; + + if (args.Length == 2) { + options = ""; + fileOrFolder = args[0]; + destination = args[1]; + } else { + options = args[0]; + fileOrFolder = args[1]; + destination = args[2]; + } + return new CpCommand(options, fileOrFolder, destination); + } + static void CopyDirectory(string sourceDir, string destinationDir, bool recursive, bool force) + { + // Get information about the source directory + var dir = new DirectoryInfo(sourceDir); + + // Check if the source directory exists + if (!dir.Exists) + throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}"); + + // Cache directories before we start copying + DirectoryInfo[] dirs = dir.GetDirectories(); + + // Create the destination directory + Directory.CreateDirectory(destinationDir); + + // Get the files in the source directory and copy to the destination directory + foreach (FileInfo file in dir.GetFiles()) + { + string targetFilePath = Path.Combine(destinationDir, file.Name); + if (force && File.Exists(targetFilePath)) { + File.Delete(targetFilePath); + } + file.CopyTo(targetFilePath); + } + + // If recursive and copying subdirectories, recursively call this method + if (recursive) { + foreach (DirectoryInfo subDir in dirs) { + string newDestinationDir = Path.Combine(destinationDir, subDir.Name); + CopyDirectory(subDir.FullName, newDestinationDir, true, force); + } + } + } + public async Task Execute(TextReader inputReader, + TextWriter outputWriter, TextWriter errorWriter) { + if (File.Exists(fileOrFolder)) { + try { + if (File.Exists(destination) && options.Contains('f')) { + File.Delete(destination); + } + File.Copy(fileOrFolder, destination); + } catch (Exception e) { + await outputWriter.WriteLineAsync(e.ToString()); + return 1; + } + } else if (Directory.Exists(fileOrFolder)) { + try { + var actualDestination = Directory.Exists(destination) + ? Path.Combine(destination, Path.GetFileName(fileOrFolder)) + : destination; + CopyDirectory(fileOrFolder, actualDestination, options.Contains('r'), options.Contains('f')); + } catch (Exception e) { + await outputWriter.WriteLineAsync(e.ToString()); + return 1; + } + } else { + throw new ArgumentException("File or folder " + fileOrFolder + " not found"); + } + + return 0; + } + + public override string ToString() { + return $"%cp {(options != "" ? options + " " : "")}{fileOrFolder} {destination}"; + } + } +} diff --git a/Source/XUnitExtensions/Lit/MvCommand.cs b/Source/XUnitExtensions/Lit/MvCommand.cs index 8a8808b1c13..8ab0a593516 100644 --- a/Source/XUnitExtensions/Lit/MvCommand.cs +++ b/Source/XUnitExtensions/Lit/MvCommand.cs @@ -44,7 +44,7 @@ public async Task Execute(TextReader inputReader, return 1; } } else { - throw new ArgumentException("File " + fileOrFolder + " not found"); + throw new ArgumentException("File or folder " + fileOrFolder + " not found"); } return 0;