-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In progress for #1363 This is an early preview of the work for allowing lexical scoping (nesting) of child resources. This changeset doesn't totally match the current proposal. It will need to be updated based on decisions tracker there and the loops/scoping work that is happening right now.
- Loading branch information
Showing
21 changed files
with
21,619 additions
and
9,432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using System.Linq; | ||
using Bicep.Core.Diagnostics; | ||
using Bicep.Core.Semantics; | ||
using Bicep.Core.UnitTests.Assertions; | ||
using Bicep.Core.UnitTests.Utils; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Bicep.Core.IntegrationTests | ||
{ | ||
[TestClass] | ||
public class ResourceTests | ||
{ | ||
[TestMethod] | ||
public void NestedResources_child_cycle_is_detected_correctly() | ||
{ | ||
var program = @" | ||
resource parent 'My.RP/parentType@2020-01-01' = { | ||
name: 'parent' | ||
properties: { | ||
style: child.properties.style | ||
} | ||
resource child 'My.RP/parentType/childType@2020-01-01' = { | ||
name: 'child' | ||
properties: { | ||
style: 'very cool' | ||
} | ||
} | ||
} | ||
"; | ||
|
||
var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program)); | ||
compilation.GetEntrypointSemanticModel().GetAllDiagnostics().Should().HaveDiagnostics(new[] { | ||
("BCP080", DiagnosticLevel.Error, "The expression is involved in a cycle (\"child\" -> \"parent\")."), | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public void NestedResources_grandchild_cycle_is_detected_correctly() | ||
{ | ||
var program = @" | ||
resource parent 'My.RP/parentType@2020-01-01' = { | ||
name: 'parent' | ||
properties: { | ||
style: grandchild.properties.style | ||
} | ||
resource child 'My.RP/parentType/childType@2020-01-01' = { | ||
name: 'child' | ||
properties: { | ||
} | ||
resource grandchild 'My.RP/parentType/childType/grandchildType@2020-01-01' = { | ||
name: 'grandchild' | ||
properties: { | ||
style: 'very cool' | ||
} | ||
} | ||
} | ||
} | ||
"; | ||
|
||
var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program)); | ||
compilation.GetEntrypointSemanticModel().GetAllDiagnostics().Should().HaveDiagnostics(new[] { | ||
("BCP080", DiagnosticLevel.Error, "The expression is involved in a cycle (\"grandchild\" -> \"parent\")."), | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public void NestedResources_ancestors_are_detected() | ||
{ | ||
var program = @" | ||
resource parent 'My.RP/parentType@2020-01-01' = { | ||
name: 'parent' | ||
properties: { | ||
} | ||
resource child 'My.RP/parentType/childType@2020-01-01' = { | ||
name: 'child' | ||
properties: { | ||
} | ||
resource grandchild 'My.RP/parentType/childType/grandchildType@2020-01-01' = { | ||
name: 'grandchild' | ||
properties: { | ||
} | ||
} | ||
} | ||
} | ||
"; | ||
|
||
var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText(program)); | ||
var model = compilation.GetEntrypointSemanticModel(); | ||
model.GetAllDiagnostics().Should().BeEmpty(); | ||
|
||
var parent = model.Root.ResourceDeclarations.Single(r => r.Name == "parent"); | ||
model.ResourceAncestors.GetAncestors(parent).Should().BeEmpty(); | ||
|
||
var child = model.Root.ResourceDeclarations.Single(r => r.Name == "child"); | ||
model.ResourceAncestors.GetAncestors(child).Should().Equal(new []{ parent, }); | ||
|
||
var grandchild = model.Root.ResourceDeclarations.Single(r => r.Name == "grandchild"); | ||
model.ResourceAncestors.GetAncestors(grandchild).Should().Equal(new []{ parent, child, }); // order matters | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.