-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Change WriteCodeFragment task to create directory #8558
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
Changes from all commits
20a5b08
b4f8f9f
2620429
4042789
c7a00e1
44941ec
9565068
40d9c92
7057970
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,51 @@ public void CombineFileDirectory() | |
| string file = Path.Combine(Path.GetTempPath(), "CombineFileDirectory.tmp"); | ||
| Assert.Equal(file, task.OutputFile.ItemSpec); | ||
| Assert.True(File.Exists(file)); | ||
|
|
||
| File.Delete(task.OutputFile.ItemSpec); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Combine file and directory where the directory does not already exist | ||
| /// </summary> | ||
| [Fact] | ||
| public void CombineFileDirectoryAndDirectoryDoesNotExist() | ||
| { | ||
| using TestEnvironment env = TestEnvironment.Create(); | ||
|
|
||
| TaskItem folder = new TaskItem(env.CreateFolder(folderPath: null, createFolder: false).Path); | ||
|
|
||
| TaskItem file = new TaskItem("CombineFileDirectory.tmp"); | ||
|
|
||
| string expectedFile = Path.Combine(folder.ItemSpec, file.ItemSpec); | ||
| WriteCodeFragment task = CreateTask("c#", folder, file, new TaskItem[] { new TaskItem("aa") }); | ||
| MockEngine engine = new MockEngine(true); | ||
| task.BuildEngine = engine; | ||
| bool result = task.Execute(); | ||
|
|
||
| Assert.True(result); | ||
| Assert.Equal(expectedFile, task.OutputFile.ItemSpec); | ||
| Assert.True(File.Exists(expectedFile)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Combine file and directory where the directory does not already exist | ||
| /// </summary> | ||
| [Fact] | ||
| public void FileWithPathAndDirectoryDoesNotExist() | ||
| { | ||
| using TestEnvironment env = TestEnvironment.Create(); | ||
|
|
||
| TaskItem file = new TaskItem(Path.Combine(env.CreateFolder(folderPath: null, createFolder: false).Path, "File.tmp")); | ||
|
|
||
| WriteCodeFragment task = CreateTask("c#", null, file, new TaskItem[] { new TaskItem("aa") }); | ||
| MockEngine engine = new MockEngine(true); | ||
| task.BuildEngine = engine; | ||
| bool result = task.Execute(); | ||
|
|
||
| Assert.True(result); | ||
| Assert.Equal(file.ItemSpec, task.OutputFile.ItemSpec); | ||
| Assert.True(File.Exists(task.OutputFile.ItemSpec)); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -176,7 +221,7 @@ public void NoAttributesShouldEmitNoFile2() | |
| /// <summary> | ||
| /// Bad file path | ||
| /// </summary> | ||
| [Fact] | ||
| [WindowsOnlyFact(additionalMessage: "No invalid characters on Unix.")] | ||
|
Contributor
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. Why did this test work on Unix before?
Contributor
Author
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. It worked before because the path didn't exist. Now that we ensure that the path is created, the test fails because there is not an
Contributor
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. Ah, looks like 3713 is a very generic error for any failure after our initial validation. Makes sense, thanks! |
||
| public void InvalidFilePath() | ||
| { | ||
| WriteCodeFragment task = new WriteCodeFragment(); | ||
|
|
@@ -317,6 +362,27 @@ public void ToDirectory() | |
| File.Delete(task.OutputFile.ItemSpec); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Specify directory where the directory does not already exist | ||
| /// </summary> | ||
| [Fact] | ||
| public void ToDirectoryAndDirectoryDoesNotExist() | ||
| { | ||
| using TestEnvironment env = TestEnvironment.Create(); | ||
|
|
||
| TaskItem folder = new TaskItem(env.CreateFolder(folderPath: null, createFolder: false).Path); | ||
|
|
||
| WriteCodeFragment task = CreateTask("c#", folder, null, new TaskItem[] { new TaskItem("System.AssemblyTrademarkAttribute") }); | ||
| MockEngine engine = new MockEngine(true); | ||
| task.BuildEngine = engine; | ||
| bool result = task.Execute(); | ||
|
|
||
| Assert.True(result); | ||
| Assert.True(File.Exists(task.OutputFile.ItemSpec)); | ||
| Assert.Equal(folder.ItemSpec, task.OutputFile.ItemSpec.Substring(0, folder.ItemSpec.Length)); | ||
| Assert.Equal(".cs", task.OutputFile.ItemSpec.Substring(task.OutputFile.ItemSpec.Length - 3)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Regular case | ||
| /// </summary> | ||
|
|
@@ -874,7 +940,7 @@ public void InferredTypeForNamedParameter() | |
| } | ||
|
|
||
| /// <summary> | ||
| /// For backward-compatibility, if multiple constructors are found with the same number | ||
| /// For backward-compatibility, if multiple constructors are found with the same number | ||
| /// of position arguments that was specified in the metadata, then the constructor that | ||
| /// has strings for every parameter should be used. | ||
| /// </summary> | ||
|
|
@@ -985,11 +1051,18 @@ public void UsingInferredDeclaredTypesAndLiteralsInSameAttribute() | |
|
|
||
| private WriteCodeFragment CreateTask(string language, params TaskItem[] attributes) | ||
| { | ||
| WriteCodeFragment task = new(); | ||
| task.Language = language; | ||
| task.OutputDirectory = new TaskItem(Path.GetTempPath()); | ||
| task.AssemblyAttributes = attributes; | ||
| return task; | ||
| return CreateTask(language, new TaskItem(Path.GetTempPath()), null, attributes); | ||
| } | ||
|
|
||
| private WriteCodeFragment CreateTask(string language, TaskItem outputDirectory, TaskItem outputFile, params TaskItem[] attributes) | ||
| { | ||
| return new WriteCodeFragment() | ||
| { | ||
| Language = language, | ||
| OutputDirectory = outputDirectory, | ||
| OutputFile = outputFile, | ||
| AssemblyAttributes = attributes | ||
| }; | ||
| } | ||
|
|
||
| private void ExecuteAndVerifySuccess(WriteCodeFragment task, params string[] expectedAttributes) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.