Skip to content

Commit 5faf876

Browse files
committed
Fixed go tests for Windows
1 parent 73f2e43 commit 5faf876

File tree

10 files changed

+129
-7
lines changed

10 files changed

+129
-7
lines changed

Source/IntegrationTests/LitTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ IEnumerable<string> AddExtraArgs(IEnumerable<string> args, IEnumerable<string> l
136136
"%mv", (args, config) => MvCommand.Parse(args.ToArray())
137137
}, {
138138
"%rm", (args, config) => RmCommand.Parse(args.ToArray())
139+
}, {
140+
"%cp", (args, config) => CpCommand.Parse(args.ToArray())
139141
}, {
140142
"%OutputCheck", OutputCheckCommand.Parse
141143
}

Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/multimodule/DerivedModule.dfy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// RUN: %baredafny translate go --go-module-name=GoModule2 --library="%S/test.doo" --translation-record "%S/test-go.dtr" --output "%S/test3" "%s"
2-
// RUN: cp -r "%S/go.*" "%S/test3-go/"
3-
// RUN: cp -r "%S/../../../../../../../../../DafnyRuntime/DafnyRuntimeGo-gomod" "%S"
4-
// RUN: cp -r "%S/DafnyModule1" "%S/test3-go/"
2+
// RUN: %cp -rf "%S/go.mod" "%S/test3-go/go.mod"
3+
// RUN: %cp -rf "%S/go.sum" "%S/test3-go/go.sum"
4+
// RUN: %cp -rf "%S/../../../../../../../../../DafnyRuntime/DafnyRuntimeGo-gomod" "%S"
5+
// RUN: %cp -rf "%S/DafnyModule1" "%S/test3-go/"
56
// RUN: go run -C %S/test3-go/ test3.go > %t
67
// RUN: %diff "%s.expect" "%t"
78
module DafnyModule3 {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file is used to regenerate PythonModule1.doo
2+
// RUN: echo 'lit should ignore this file'
3+
4+
module DafnyModule1 {
5+
method HelloWorld()
6+
{
7+
print "Hello World";
8+
}
9+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
file_format_version = "1.0"
2-
dafny_version = "4.7.0.0"
2+
dafny_version = "4.8.0.0"
33
[options_by_module.DafnyModule1]
44
go-module-name = "GoModule1"
Binary file not shown.

Source/IntegrationTests/TestFiles/LitTests/LitTest/gomodule/singlemodule/dafnysource/helloworld.dfy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %baredafny translate go --go-module-name=GoModule1 "%s" --output "%S/test"
2-
// RUN: cp -r "%S/go.*" "%S/test-go/"
3-
// RUN: cp -r "%S/../../../../../../../../../../DafnyRuntime/DafnyRuntimeGo-gomod" "%S"
2+
// RUN: %cp -rf "%S/go.mod" "%S/test-go/go.mod"
3+
// RUN: %cp -rf "%S/go.sum" "%S/test-go/go.sum"
4+
// RUN: %cp -rf "%S/../../../../../../../../../../DafnyRuntime/DafnyRuntimeGo-gomod" "%S"
45
// RUN: go run -C %S/test-go/ test.go > %t
56
// RUN: %diff "%s.expect" "%t"
67
module DafnyModule1 {
Binary file not shown.
Binary file not shown.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Xunit.Abstractions;
8+
using Xunit.Sdk;
9+
10+
namespace XUnitExtensions.Lit {
11+
public class CpCommand : ILitCommand {
12+
13+
private readonly string options;
14+
private readonly string fileOrFolder;
15+
private readonly string destination;
16+
17+
private CpCommand(string options, string fileOrFolder, string destination) {
18+
this.options = options;
19+
this.fileOrFolder = fileOrFolder;
20+
this.destination = destination;
21+
}
22+
23+
public static ILitCommand Parse(string[] args) {
24+
if (args.Length != 2 && args.Length != 3) {
25+
throw new ArgumentException($"Wrong number of arguments for cp, expected 2 or 3 but got {args.Length}: " + string.Join(", ", args));
26+
}
27+
28+
string fileOrFolder;
29+
string destination;
30+
string options;
31+
32+
if (args.Length == 2) {
33+
options = "";
34+
fileOrFolder = args[0];
35+
destination = args[1];
36+
} else {
37+
options = args[0];
38+
fileOrFolder = args[1];
39+
destination = args[2];
40+
}
41+
return new CpCommand(options, fileOrFolder, destination);
42+
}
43+
static void CopyDirectory(string sourceDir, string destinationDir, bool recursive, bool force)
44+
{
45+
// Get information about the source directory
46+
var dir = new DirectoryInfo(sourceDir);
47+
48+
// Check if the source directory exists
49+
if (!dir.Exists)
50+
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
51+
52+
// Cache directories before we start copying
53+
DirectoryInfo[] dirs = dir.GetDirectories();
54+
55+
// Create the destination directory
56+
Directory.CreateDirectory(destinationDir);
57+
58+
// Get the files in the source directory and copy to the destination directory
59+
foreach (FileInfo file in dir.GetFiles())
60+
{
61+
string targetFilePath = Path.Combine(destinationDir, file.Name);
62+
if (force && File.Exists(targetFilePath)) {
63+
File.Delete(targetFilePath);
64+
}
65+
file.CopyTo(targetFilePath);
66+
}
67+
68+
// If recursive and copying subdirectories, recursively call this method
69+
if (recursive) {
70+
foreach (DirectoryInfo subDir in dirs) {
71+
string newDestinationDir = Path.Combine(destinationDir, subDir.Name);
72+
CopyDirectory(subDir.FullName, newDestinationDir, true, force);
73+
}
74+
}
75+
}
76+
public async Task<int> Execute(TextReader inputReader,
77+
TextWriter outputWriter, TextWriter errorWriter) {
78+
if (File.Exists(fileOrFolder)) {
79+
try {
80+
if (File.Exists(destination) && options.Contains('f')) {
81+
File.Delete(destination);
82+
}
83+
File.Copy(fileOrFolder, destination);
84+
} catch (Exception e) {
85+
await outputWriter.WriteLineAsync(e.ToString());
86+
return 1;
87+
}
88+
} else if (Directory.Exists(fileOrFolder)) {
89+
try {
90+
var actualDestination = Directory.Exists(destination)
91+
? Path.Combine(destination, Path.GetFileName(fileOrFolder))
92+
: destination;
93+
CopyDirectory(fileOrFolder, actualDestination, options.Contains('r'), options.Contains('f'));
94+
} catch (Exception e) {
95+
await outputWriter.WriteLineAsync(e.ToString());
96+
return 1;
97+
}
98+
} else {
99+
throw new ArgumentException("File or folder " + fileOrFolder + " not found");
100+
}
101+
102+
return 0;
103+
}
104+
105+
public override string ToString() {
106+
return $"%cp {(options != "" ? options + " " : "")}{fileOrFolder} {destination}";
107+
}
108+
}
109+
}

Source/XUnitExtensions/Lit/MvCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public async Task<int> Execute(TextReader inputReader,
4444
return 1;
4545
}
4646
} else {
47-
throw new ArgumentException("File " + fileOrFolder + " not found");
47+
throw new ArgumentException("File or folder " + fileOrFolder + " not found");
4848
}
4949

5050
return 0;

0 commit comments

Comments
 (0)