Skip to content

Commit 4f9a6f2

Browse files
levimatheriLevi Muriuki
and
Levi Muriuki
authored
Decompile-params: Resolve bicep file path relative to current directory (#15986)
Resolves #13785. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/15986) --------- Co-authored-by: Levi Muriuki <[email protected]>
1 parent 8e9cd2e commit 4f9a6f2

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/Bicep.Cli.IntegrationTests/CliScenarioTests.cs

+48
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using Bicep.Core.FileSystem;
45
using Bicep.Core.UnitTests.Assertions;
56
using Bicep.Core.UnitTests.Utils;
67
using FluentAssertions;
8+
using FluentAssertions.Execution;
79
using Microsoft.VisualStudio.TestTools.UnitTesting;
810

911
namespace Bicep.Cli.IntegrationTests
@@ -187,5 +189,51 @@ param roleAssignmentName string
187189
188190
""");
189191
}
192+
193+
[TestMethod]
194+
public async Task Test_Issue13785()
195+
{
196+
var paramFile =
197+
"""
198+
{
199+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
200+
"contentVersion": "1.0.0.0",
201+
"parameters": {
202+
"foo": {
203+
"value": "bar"
204+
}
205+
}
206+
}
207+
""";
208+
var expectedOutput =
209+
"""
210+
using '../main.bicep'
211+
212+
param foo = 'bar'
213+
214+
""";
215+
216+
var (jsonPath, bicepparamPath) = Setup(TestContext, paramFile);
217+
Directory.SetCurrentDirectory(Path.GetDirectoryName(jsonPath)!);
218+
var (output, _, result) = await Bicep("decompile-params", jsonPath, "--bicep-file", "../main.bicep");
219+
220+
using (new AssertionScope())
221+
{
222+
output.Should().BeEmpty();
223+
result.Should().Be(0);
224+
File.ReadAllText(bicepparamPath).Should().BeEquivalentToIgnoringNewlines(expectedOutput);
225+
}
226+
}
227+
228+
private static (string jsonPath, string bicepparamPath) Setup(TestContext context, string template, string? inputFile = null, string? outputDir = null)
229+
{
230+
var jsonPath = FileHelper.SaveResultFile(context, inputFile ?? "param.json", template);
231+
232+
var bicepparamPath = outputDir is null
233+
? PathHelper.GetDefaultDecompileparamOutputPath(jsonPath)
234+
: FileHelper.GetResultFilePath(context, outputDir);
235+
236+
return (jsonPath, bicepparamPath);
237+
}
190238
}
191239
}

src/Bicep.Cli/Commands/DecompileParamsCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public int Run(DecompileParamsArguments args)
3737
var inputUri = PathHelper.FilePathToFileUrl(PathHelper.ResolvePath(args.InputFile));
3838
var outputPath = PathHelper.ResolveDefaultOutputPath(inputUri.LocalPath, args.OutputDir, args.OutputFile, PathHelper.GetDefaultDecompileparamOutputPath);
3939
var outputUri = PathHelper.FilePathToFileUrl(outputPath);
40-
var bicepUri = args.BicepFilePath is { } ? PathHelper.FilePathToFileUrl(args.BicepFilePath) : null;
40+
var bicepUri = args.BicepFilePath is { } ? PathHelper.FilePathToFileUrl(PathHelper.ResolvePath(args.BicepFilePath)) : null;
4141

4242
try
4343
{

0 commit comments

Comments
 (0)