From 5faf876b2c768c61044b8f87825385682b6e772d Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Wed, 28 Aug 2024 20:15:34 -0500 Subject: [PATCH] Fixed go tests for Windows --- Source/IntegrationTests/LitTests.cs | 2 + .../gomodule/multimodule/DerivedModule.dfy | 7 +- .../multimodule/dafnysource/helloworld.dfy | 9 ++ .../LitTest/gomodule/multimodule/test-go.dtr | 2 +- .../LitTest/gomodule/multimodule/test.doo | Bin 664 -> 664 bytes .../singlemodule/dafnysource/helloworld.dfy | 5 +- .../multimodule/PythonModule1.doo | Bin 664 -> 664 bytes .../nestedmodule/SomeNestedModule.doo | Bin 668 -> 668 bytes Source/XUnitExtensions/Lit/CpCommand.cs | 109 ++++++++++++++++++ Source/XUnitExtensions/Lit/MvCommand.cs | 2 +- 10 files changed, 129 insertions(+), 7 deletions(-) create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/dafnysource/helloworld.dfy create mode 100644 Source/XUnitExtensions/Lit/CpCommand.cs 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 ce95bf59f7bb89de36a61ec60edd1c7dccf94935..507fc7e0335796bc92c068aa985db220d0b5d4e4 100644 GIT binary patch delta 111 zcmbQiI)jxbz?+#xgn@y9gW=rljXX0LdC$$3iB#TpZc{K&FnRJuMms|rhgXLkUzwUT xE>e(WZEad~W{(i7>V`Q?5kV)VGy+eDo@QkT@MdHZVSt%4S%JwC&73qQBLIvUB8>n5 delta 111 zcmbQiI)jxbz?+#xgn@y9gQ2@_BhL&*-tIb?$g^>Ze}aL6v6DA4+8Nde8-F%2X{?zr wqshrJFfFdLX%hPhk=B9 %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 73cac5cbf231d0ad36acd4ca7622cc285caa16b2..d02fd1ee749dc029853701729d0c43ae7326c4e6 100644 GIT binary patch delta 42 tcmbQiI)jxbz?+#xgn@y9gW>e-jXX0LnNH81yo|8|L@6*?f~aUFTLAKt48{Ne delta 42 tcmbQiI)jxbz?+#xgn@y9gQ2r-BhL&*rp~&_%NQ#_lme3_h>B*i1pwNK3rYY0 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/nestedmodule/SomeNestedModule.doo b/Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/nestedmodule/SomeNestedModule.doo index df92ea9bec162dab2e586d0ce06e517ff4d46ec0..984fce8d142d402a72aa113421fee8f0558d1987 100644 GIT binary patch delta 42 tcmbQkI){}fz?+#xgn@y9gW=5VjXX0Lna<3fyo|91M5!=Yf~a^VTLAQp4Bh|$ delta 42 tcmbQkI){}fz?+#xgn@y9gQ2T#BhL&*rmnil%NT1wlnRq2h>B;j1pwTG3t|8O 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;