@@ -76,6 +76,60 @@ class ClassWithNoParent
76
76
{
77
77
[Write] Boolean Anonymous;
78
78
};
79
+ "@
80
+
81
+ # Act - run scriptanalyzer
82
+ $violations = Invoke-ScriptAnalyzer - Path $noParentClassFilepath - IncludeRule $ruleName - ErrorAction Stop
83
+ $violations.Count | Should - Be 0
84
+ }
85
+ }
86
+
87
+ Context " When a CIM class has no parent, but does contain a subclass which should not be processed" {
88
+ # regression test for #1192 - just check no uncaught exception
89
+ It " Should find no violations, and throw no exceptions" - Skip:($IsLinux -or $IsMacOS ) {
90
+
91
+ # Arrange test content in testdrive
92
+ $dscResources = Join-Path - Path " TestDrive:" - ChildPath " DSCResources"
93
+ $noparentClassDir = Join-Path - Path $dscResources " ClassWithNoParent"
94
+
95
+ # need a fake module
96
+ $fakeModulePath = Join-Path - Path " TestDrive:" - ChildPath " test.psd1"
97
+ Set-Content - Path $fakeModulePath - Value @"
98
+ @{
99
+ ModuleVersion = '1.0'
100
+ GUID = 'fe2acc06-d9e6-4ca6-b57d-068e8fc5ad57'
101
+ Author = 'DummyAuthor'
102
+ }
103
+ "@
104
+ # and under it a directory called dscresources\something
105
+ New-Item - ItemType Directory - Path $noParentClassDir
106
+ $noparentClassFilepath = Join-Path - Path $noParentClassDir - ChildPath ' MSFT_ClassWithNoParent.psm1'
107
+ $noparentClassMofFilepath = Join-Path - Path $noParentClassDir - ChildPath ' MSFT_ClassWithNoParent.schema.mof'
108
+
109
+ # containing a .psm1 file and a .schema.mof file with same base name
110
+ Set-Content - Path $noParentClassFilepath - Value @"
111
+ #requires -Version 4.0 -Modules CimCmdlets
112
+ function Get-TargetResource { }
113
+ function Set-TargetResource { }
114
+ function Test-TargetResource { }
115
+ Export-ModuleMember -Function *-TargetResource
116
+ "@
117
+
118
+ Set-Content - Path $noParentClassMofFilePath - Value @"
119
+ [ClassVersion("1.0.0.0")]
120
+ Class MSFT_SubClass
121
+ {
122
+ [Key, Description("Key of the subclass")] String Name;
123
+ [Required, Description("Required parameter of the subclass")] String Description;
124
+ [Write, Description("Additional non-required parameter")] Boolean Enabled;
125
+ };
126
+
127
+ [ClassVersion("1.0.0"), FriendlyName("ClassWithNoParent")]
128
+ class MSFT_ClassWithNoParent : OMI_BaseResource
129
+ {
130
+ [write, Description("dummy subclass variable"), EmbeddedInstance("MSFT_SubClass")]
131
+ string Subclass;
132
+ };
79
133
"@
80
134
81
135
# Act - run scriptanalyzer
0 commit comments