diff --git a/CHANGELOG.md b/CHANGELOG.md index 542c663f..c8783e52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +What's changed since v0.7.0: + +- Engine features: + - Added support for custom configuration key values. [#121](https://github.com/BernieWhite/PSDocs/issues/121) + - See `about_PSDocs_Configuration` for more details. + ## v0.7.0 What's changed since v0.6.3: diff --git a/README.md b/README.md index a97adf82..641d86ca 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,9 @@ The following commands exist in the `PSDocs.Dsc` module: The following conceptual topics exist in the `PSDocs` module: +- [Configuration](docs/concepts/PSDocs/en-US/about_PSDocs_Configuration.md) - [Options](docs/concepts/PSDocs/en-US/about_PSDocs_Options.md) + - [Configuration](docs/concepts/PSDocs/en-US/about_PSDocs_Options.md#configuration) - [Execution.LanguageMode](docs/concepts/PSDocs/en-US/about_PSDocs_Options.md#executionlanguagemode) - [Markdown.ColumnPadding](docs/concepts/PSDocs/en-US/about_PSDocs_Options.md#markdowncolumnpadding) - [Markdown.Encoding](docs/concepts/PSDocs/en-US/about_PSDocs_Options.md#markdownencoding) diff --git a/docs/concepts/PSDocs/en-US/about_PSDocs_Configuration.md b/docs/concepts/PSDocs/en-US/about_PSDocs_Configuration.md new file mode 100644 index 00000000..b05f98cd --- /dev/null +++ b/docs/concepts/PSDocs/en-US/about_PSDocs_Configuration.md @@ -0,0 +1,97 @@ +# PSDocs_Configuration + +## about_PSDocs_Configuration + +## SHORT DESCRIPTION + +Describes custom configuration that can be used within PSDocs document definitions. + +## LONG DESCRIPTION + +PSDocs lets you generate dynamic markdown documents using PowerShell blocks known as document definitions. +Document definitions can read custom configuration set at runtime or within options to change rendering. +Within a document definition, PSDocs exposes custom configuration through the `$PSDocs` automatic variable. + +### Setting configuration + +To specify custom configuration, set a property of the `configuration` object. +Configuration can be set at runtime or as YAML by configuring `ps-docs.yaml`. + +For example: + +```yaml +# Example: ps-docs.yaml + +# YAML: Using the configuration YAML property to set custom configuration 'MODULE1_KEY1' +configuration: + MODULE1_KEY1: Value1 +``` + +To ensure each custom key is unique use a prefix followed by an underscore that represent your module. +Key names are not case sensitive, however we recommend you use uppercase for consistency. + +### Reading configuration + +The `$PSDocs` automatic variable can be used within a Document definition to read configuration. +Each custom configuration key is available under the `.Configuration` property. +Additionally, several helper methods are available for advanced usage. + +Syntax: + +```powershell +$PSDocs.Configuration. +``` + +For example: + +```powershell +# Get the value of the custom configuration 'MODULE1_KEY1' +$PSDocs.Configuration.MODULE1_KEY1 +``` + +The following helper methods are available: + +- `GetStringValues(string configurationKey)` - The configuration value as an array of strings. +This helper will always returns an array of strings. +The array will be empty if the configuration key is not defined or empty. +- `GetValueOrDefault(string configurationKey, object defaultValue)` - Returns the configuration value. +When the configuration key is not defined the default value will be used instead. +- `GetBoolOrDefault(string configurationKey, bool defaultValue)` - The configuration value as a boolean. +When the configuration key is not defined the default value will be used instead. + +Syntax: + +```powershell +$PSDocs.Configuration.helper() +``` + +For example: + +```powershell +# Example using GetStringValues +$values = $PSDocs.Configuration.GetStringValues('SAMPLE_AUTHORS'); + +# Example using GetValueOrDefault +$value = $PSDocs.Configuration.GetValueOrDefault('SAMPLE_CONTENT_OWNER', 'defaultUser'); + +# Example using GetBoolOrDefault +if ($PSDocs.Configuration.GetBoolOrDefault('SAMPLE_USE_PARAMETERS_SNIPPET', $True)) { + # Execute code +} +``` + +## NOTE + +An online version of this document is available at https://github.com/BernieWhite/PSDocs/blob/main/docs/concepts/PSDocs/en-US/about_PSDocs_Configuration.md. + +## SEE ALSO + +- [Invoke-PSDocument](https://github.com/BernieWhite/PSDocs/blob/main/docs/commands/PSDocs/en-US/Invoke-PSDocument.md) + +## KEYWORDS + +- Configuration +- PSDocs +- GetStringValues +- GetValueOrDefault +- GetBoolOrDefault diff --git a/docs/concepts/PSDocs/en-US/about_PSDocs_Options.md b/docs/concepts/PSDocs/en-US/about_PSDocs_Options.md index 52a74e11..7ce0618c 100644 --- a/docs/concepts/PSDocs/en-US/about_PSDocs_Options.md +++ b/docs/concepts/PSDocs/en-US/about_PSDocs_Options.md @@ -13,6 +13,7 @@ This topic describes what options are available, when to and how to use them. The following workspace options are available for use: +- [Configuration](#configuration) - [Execution.LanguageMode](#executionlanguagemode) - [Markdown.ColumnPadding](#markdowncolumnpadding) - [Markdown.Encoding](#markdownencoding) @@ -62,6 +63,28 @@ For example: Invoke-PSDocument -Path . -Option '.\myconfig.yml'. ``` +### Configuration + +Sets custom configuration for document generation. +Document definitions may allow custom configuration to be specified. +To specify custom configuration, set a property of the configuration object. + +To ensure each custom key is unique use a prefix followed by an underscore that represent your module. +Key names are not case sensitive, however we recommend you use uppercase for consistency. + +This option can be specified using: + +```powershell +# PowerShell: Using the Configuration hashtable key to set custom configuration 'MODULE1_KEY1' +$option = New-PSDocumentOption -Option @{ 'Configuration.MODULE1_KEY1' = 'Value1' } +``` + +```yaml +# YAML: Using the configuration YAML property to set custom configuration 'MODULE2_KEY1' +configuration: + MODULE2_KEY1: Value1 +``` + ### Execution.LanguageMode Unless PowerShell has been constrained, full language features of PowerShell are available to use within document definitions. @@ -143,7 +166,8 @@ markdown: ### Markdown.Encoding -Sets the text encoding used for markdown output files. One of the following values can be used: +Sets the text encoding used for markdown output files. +One of the following values can be used: - Default - UTF8 @@ -315,14 +339,19 @@ output: ### Example ps-docs.yaml ```yaml -# Set markdown options +configuration: + SAMPLE_USE_PARAMETERS_SNIPPET: true + execution: languageMode: ConstrainedLanguage + +# Set markdown options markdown: # Use UTF-8 with BOM encoding: UTF8 skipEmptySections: false wrapSeparator: '\' + output: culture: - 'en-US' @@ -334,14 +363,18 @@ output: ```yaml # These are the default options. # Only properties that differ from the default values need to be specified. +configuration: { } + execution: languageMode: FullLanguage + markdown: encoding: Default skipEmptySections: true wrapSeparator: ' ' columnPadding: MatchHeader useEdgePipes: WhenRequired + output: culture: [ ] path: null @@ -358,6 +391,9 @@ An online version of this document is available at https://github.com/BernieWhit ## KEYWORDS +- Configuration - Options - Markdown - PSDocument +- Output +- Execution diff --git a/docs/concepts/PSDocs/en-US/about_PSDocs_Variables.md b/docs/concepts/PSDocs/en-US/about_PSDocs_Variables.md index 7010873b..873ed30b 100644 --- a/docs/concepts/PSDocs/en-US/about_PSDocs_Variables.md +++ b/docs/concepts/PSDocs/en-US/about_PSDocs_Variables.md @@ -11,7 +11,7 @@ Describes the automatic variables that can be used within PSDocs document defini PSDocs lets you generate dynamic markdown documents using PowerShell blocks. To generate markdown, a document is defined inline or within script files by using the `document` keyword. -Within a document definition, PSDocs exposes a number of automatic variables that can be read to assist with dynamic document generation. +Within a document definition, PSDocs exposes several automatic variables that can be read to assist with dynamic document generation. Overwriting these variables or variable properties is not supported. The following variables are available for use: @@ -20,6 +20,7 @@ The following variables are available for use: - [$Document](#document) - [$InstanceName](#instancename) - [$LocalizedData](#localizeddata) +- [$PSDocs](#psdocs) - [$TargetObject](#targetobject) - [$Section](#section) @@ -134,6 +135,42 @@ This document returns content similar to: Localized string for en-ZZ. Format=TestType. ``` +### PSDocs + +An object representing the current context of PSDocs. + +In addition, `$PSDocs` provides several helper properties and functions. + +The following properties are available for public read access: + +- `Configuration` - An object with custom configuration properties. +Each configuration key specified in `ps-docs.yaml` is assessable as a property. +Additionally helper methods can be used. +See `about_PSDocs_Configuration` for more information. +- `Culture` - The name of the culture currently being processed. +- `TargetObject` - The value of the pipeline object currently being processed. + +Syntax: + +```powershell +$PSDocs +``` + +```powershell +# Get the value of the custom configuration 'Key1' +$PSDocs.Configuration.Key1 +``` + +```powershell +# Return the currently processed culture. e.g. 'en-US' +$PSDocs.Culture +``` + +```powershell +# Return the current pipeline object. +$PSDocs.TargetObject +``` + ### TargetObject The value of the pipeline object currently being processed. @@ -196,5 +233,6 @@ An online version of this document is available at https://github.com/BernieWhit - Culture - Document - InstanceName -- InputObject +- PSDocs +- TargetObject - Section diff --git a/src/PSDocs/Common/DictionaryExtensions.cs b/src/PSDocs/Common/DictionaryExtensions.cs index 90a0ded8..0520cf6f 100644 --- a/src/PSDocs/Common/DictionaryExtensions.cs +++ b/src/PSDocs/Common/DictionaryExtensions.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Management.Automation; namespace PSDocs { @@ -77,9 +76,14 @@ public static bool TryGetBool(this IDictionary dictionary, strin [DebuggerStepThrough] public static void AddUnique(this IDictionary dictionary, IEnumerable> values) { + if (values == null) + return; + foreach (var kv in values) + { if (!dictionary.ContainsKey(kv.Key)) dictionary.Add(kv.Key, kv.Value); + } } } } diff --git a/src/PSDocs/Configuration/ConfigurationOption.cs b/src/PSDocs/Configuration/ConfigurationOption.cs new file mode 100644 index 00000000..d7fc6188 --- /dev/null +++ b/src/PSDocs/Configuration/ConfigurationOption.cs @@ -0,0 +1,40 @@ + +using System.Collections; +using System.Collections.Generic; + +namespace PSDocs.Configuration +{ + /// + /// A set of custom configuration values that are exposed at runtime. + /// + public sealed class ConfigurationOption : KeyMapDictionary + { + private const string KEYMAP_PREFIX = "Configuration."; + + public ConfigurationOption() + : base() { } + + public ConfigurationOption(ConfigurationOption option) + : base(option) { } + + private ConfigurationOption(Hashtable hashtable) + : base(hashtable) { } + + public static implicit operator ConfigurationOption(Hashtable hashtable) + { + return new ConfigurationOption(hashtable); + } + + internal static ConfigurationOption Combine(ConfigurationOption o1, ConfigurationOption o2) + { + var result = new ConfigurationOption(o1); + result.AddUnique(o2); + return result; + } + + internal void Load(IDictionary dictionary) + { + Load(KEYMAP_PREFIX, dictionary); + } + } +} diff --git a/src/PSDocs/Configuration/KeyMapDictionary.cs b/src/PSDocs/Configuration/KeyMapDictionary.cs new file mode 100644 index 00000000..f43ea1b2 --- /dev/null +++ b/src/PSDocs/Configuration/KeyMapDictionary.cs @@ -0,0 +1,158 @@ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; + +namespace PSDocs.Configuration +{ + public abstract class KeyMapDictionary : DynamicObject, IDictionary + { + private readonly Dictionary _Map; + + protected KeyMapDictionary() + { + _Map = new Dictionary(StringComparer.OrdinalIgnoreCase); + } + + protected KeyMapDictionary(KeyMapDictionary map) + { + if (map == null) + throw new ArgumentNullException(nameof(map)); + + _Map = new Dictionary(map._Map, StringComparer.OrdinalIgnoreCase); + } + + protected KeyMapDictionary(IDictionary dictionary) + { + _Map = dictionary == null ? + new Dictionary(StringComparer.OrdinalIgnoreCase) : + new Dictionary(dictionary, StringComparer.OrdinalIgnoreCase); + } + + protected KeyMapDictionary(Hashtable hashtable) + : this() + { + Load(hashtable); + } + + public TValue this[string key] + { + get => _Map[key]; + set => _Map[key] = value; + } + + public ICollection Keys => _Map.Keys; + + public ICollection Values => _Map.Values; + + public int Count => _Map.Count; + + public bool IsReadOnly => false; + + public void Add(string key, TValue value) + { + _Map.Add(key, value); + } + + public void Add(KeyValuePair item) + { + Add(item.Key, item.Value); + } + + public void Clear() + { + _Map.Clear(); + } + + public bool Contains(KeyValuePair item) + { + return ((IDictionary)_Map).Contains(item); + } + + public bool ContainsKey(string key) + { + return _Map.ContainsKey(key); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + ((IDictionary)_Map).CopyTo(array, arrayIndex); + } + + public IEnumerator> GetEnumerator() + { + return _Map.GetEnumerator(); + } + + public bool Remove(string key) + { + return _Map.Remove(key); + } + + public bool Remove(KeyValuePair item) + { + return ((IDictionary)_Map).Remove(item); + } + + public bool TryGetValue(string key, out TValue value) + { + return _Map.TryGetValue(key, out value); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + protected void Load(Hashtable hashtable) + { + if (hashtable == null) + throw new ArgumentNullException(nameof(hashtable)); + + foreach (DictionaryEntry entry in hashtable) + _Map.Add(entry.Key.ToString(), (TValue)entry.Value); + } + + protected void Load(string prefix, IDictionary dictionary) + { + if (dictionary == null) + throw new ArgumentNullException(nameof(dictionary)); + + if (dictionary.Count == 0) + return; + + var keys = dictionary.Keys.ToArray(); + for (var i = 0; i < keys.Length; i++) + { + if (TryKeyPrefix(keys[i], prefix, out string suffix) && dictionary.TryPopValue(keys[i], out object value)) + _Map[suffix] = (TValue)value; + } + } + + private static bool TryKeyPrefix(string key, string prefix, out string suffix) + { + suffix = key; + if (prefix == null || prefix.Length == 0) + return true; + + if (key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) + { + suffix = key.Substring(prefix.Length); + return true; + } + return false; + } + + public sealed override bool TryGetMember(GetMemberBinder binder, out object result) + { + if (binder == null) + throw new ArgumentNullException(nameof(binder)); + + var found = _Map.TryGetValue(binder.Name, out TValue value); + result = value; + return found; + } + } +} diff --git a/src/PSDocs/Configuration/PSDocumentOption.cs b/src/PSDocs/Configuration/PSDocumentOption.cs index 6b0f0db5..3da7c411 100644 --- a/src/PSDocs/Configuration/PSDocumentOption.cs +++ b/src/PSDocs/Configuration/PSDocumentOption.cs @@ -34,6 +34,7 @@ public sealed class PSDocumentOption public PSDocumentOption() { // Set defaults + Configuration = new ConfigurationOption(); Document = new DocumentOption(); Execution = new ExecutionOption(); Markdown = new MarkdownOption(); @@ -45,6 +46,7 @@ private PSDocumentOption(string sourcePath, PSDocumentOption option) SourcePath = sourcePath; // Set from existing option instance + Configuration = new ConfigurationOption(option?.Configuration); Document = new DocumentOption(option?.Document); Execution = new ExecutionOption(option?.Execution); Markdown = new MarkdownOption(option?.Markdown); @@ -66,6 +68,8 @@ private PSDocumentOption(string sourcePath, PSDocumentOption option) /// public string Generator { get; set; } + public ConfigurationOption Configuration { get; set; } + public DocumentOption Document { get; set; } /// @@ -97,6 +101,7 @@ public PSDocumentOption Clone() private static PSDocumentOption Combine(PSDocumentOption o1, PSDocumentOption o2) { var result = new PSDocumentOption(o1?.SourcePath ?? o2?.SourcePath, o1); + result.Configuration = ConfigurationOption.Combine(result.Configuration, o2?.Configuration); result.Document = DocumentOption.Combine(result.Document, o2?.Document); result.Execution = ExecutionOption.Combine(result.Execution, o2?.Execution); result.Markdown = MarkdownOption.Combine(result.Markdown, o2?.Markdown); @@ -246,6 +251,7 @@ public override bool Equals(object obj) public bool Equals(PSDocumentOption other) { return other != null && + Configuration == other.Configuration && Document == other.Document && Execution == other.Execution && Markdown == other.Markdown && @@ -257,6 +263,7 @@ public override int GetHashCode() unchecked // Overflow is fine { int hash = 17; + hash = hash * 23 + (Configuration != null ? Configuration.GetHashCode() : 0); hash = hash * 23 + (Document != null ? Document.GetHashCode() : 0); hash = hash * 23 + (Execution != null ? Execution.GetHashCode() : 0); hash = hash * 23 + (Markdown != null ? Markdown.GetHashCode() : 0); @@ -303,6 +310,8 @@ public static implicit operator PSDocumentOption(Hashtable hashtable) if(index.TryPopString("output.path", out svalue)) option.Output.Path = svalue; + // Process configuration values + option.Configuration.Load(index); return option; } diff --git a/src/PSDocs/Pipeline/PipelineBuilder.cs b/src/PSDocs/Pipeline/PipelineBuilder.cs index 55e2c7aa..fcf6ed9e 100644 --- a/src/PSDocs/Pipeline/PipelineBuilder.cs +++ b/src/PSDocs/Pipeline/PipelineBuilder.cs @@ -87,6 +87,7 @@ internal PipelineBuilderBase(Source[] source, HostContext hostContext) public virtual IPipelineBuilder Configure(PSDocumentOption option) { + Option.Configuration = new ConfigurationOption(option.Configuration); Option.Document = DocumentOption.Combine(option.Document, DocumentOption.Default); Option.Execution = ExecutionOption.Combine(option.Execution, ExecutionOption.Default); Option.Markdown = MarkdownOption.Combine(option.Markdown, MarkdownOption.Default); diff --git a/src/PSDocs/Runtime/Configuration.cs b/src/PSDocs/Runtime/Configuration.cs new file mode 100644 index 00000000..71e53a21 --- /dev/null +++ b/src/PSDocs/Runtime/Configuration.cs @@ -0,0 +1,77 @@ + +using System.Collections; +using System.Collections.Generic; +using System.Dynamic; + +namespace PSDocs.Runtime +{ + /// + /// A set of custom configuration values that are exposed at runtime. + /// + public sealed class Configuration : DynamicObject + { + private readonly RunspaceContext _Context; + + internal Configuration(RunspaceContext context) + { + _Context = context; + } + + public override bool TryGetMember(GetMemberBinder binder, out object result) + { + result = null; + if (_Context == null || binder == null || string.IsNullOrEmpty(binder.Name)) + return false; + + // Get from configuration + return TryGetValue(binder.Name, out result); + } + + public string[] GetStringValues(string configurationKey) + { + if (!TryGetValue(configurationKey, out object value) || value == null) + return System.Array.Empty(); + + if (value is string valueT) + return new string[] { valueT }; + + if (value is string[] result) + return result; + + if (value is IEnumerable c) + { + var cList = new List(); + foreach (var v in c) + cList.Add(v.ToString()); + + return cList.ToArray(); + } + return new string[] { value.ToString() }; + } + + public object GetValueOrDefault(string configurationKey, object defaultValue) + { + if (!TryGetValue(configurationKey, out object value) || value == null) + return defaultValue; + + return value; + } + + public bool GetBoolOrDefault(string configurationKey, bool defaultValue) + { + if (!TryGetValue(configurationKey, out object value) || !(value is bool bvalue)) + return defaultValue; + + return bvalue; + } + + private bool TryGetValue(string name, out object value) + { + value = null; + if (_Context == null) + return false; + + return _Context.Pipeline.Option.Configuration.TryGetValue(name, out value); + } + } +} diff --git a/src/PSDocs/Runtime/PSDocs.cs b/src/PSDocs/Runtime/PSDocs.cs index 3e526b9f..27aeb533 100644 --- a/src/PSDocs/Runtime/PSDocs.cs +++ b/src/PSDocs/Runtime/PSDocs.cs @@ -1,4 +1,5 @@ -using System.Management.Automation; + +using System.Management.Automation; using System.Threading; namespace PSDocs.Runtime @@ -10,6 +11,8 @@ public sealed class PSDocs { private readonly RunspaceContext _Context; + private Configuration _Configuration; + public PSDocs() { } internal PSDocs(RunspaceContext context) @@ -48,6 +51,13 @@ public string Culture // } //} + /// + /// Custom configuration values. + /// + public Configuration Configuration + { + get { return GetConfiguration(); } + } /// /// Format a string with arguments. /// @@ -70,5 +80,13 @@ private RunspaceContext GetContext() return _Context; } + + private Configuration GetConfiguration() + { + if (_Configuration == null) + _Configuration = new Configuration(GetContext()); + + return _Configuration; + } } } diff --git a/tests/PSDocs.Tests/FromFile.Variables.Doc.ps1 b/tests/PSDocs.Tests/FromFile.Variables.Doc.ps1 index df622779..2cb1246b 100644 --- a/tests/PSDocs.Tests/FromFile.Variables.Doc.ps1 +++ b/tests/PSDocs.Tests/FromFile.Variables.Doc.ps1 @@ -8,7 +8,13 @@ Document 'PSAutomaticVariables' { # Synopsis: Test $PSDocs variable Document 'PSDocsVariable' { + Metadata @{ + author = $PSDocs.Configuration.author.name + } $PSDocs.Format("TargetObject.Name={0};", $PSDocs.TargetObject.Name); + if ($PSDocs.Configuration.GetBoolOrDefault('NotConfig', $True)) { + "Document.Metadata=$($Document.Metadata['author']);" + } } # Synopsis: Test $Document variable diff --git a/tests/PSDocs.Tests/PSDocs.Options.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Options.Tests.ps1 index 6cc3ed38..0feff4a3 100644 --- a/tests/PSDocs.Tests/PSDocs.Options.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Options.Tests.ps1 @@ -31,6 +31,24 @@ Describe 'New-PSDocumentOption' -Tag 'Option' { } } + Context 'Read Configuration' { + It 'from default' { + $option = New-PSDocumentOption -Default; + $option.Configuration.Count | Should -Be 0; + } + + It 'from Hashtable' { + $option = New-PSDocumentOption -Option @{ 'Configuration.Key1' = 'Value1' }; + $option.Configuration.Key1 | Should -Be 'Value1'; + } + + It 'from YAML' { + $option = New-PSDocumentOption -Option (Join-Path -Path $here -ChildPath 'PSDocs.Tests.yml'); + $option.Configuration.Key1 | Should -Be 'Value2'; + $option.Configuration.'UnitTests.String.1' | Should -Be 'Config string 1' + } + } + Context 'Read Execution.LanguageMode' { It 'from default' { $option = New-PSDocumentOption -Default; diff --git a/tests/PSDocs.Tests/PSDocs.Tests.yml b/tests/PSDocs.Tests/PSDocs.Tests.yml index bbb0e3fd..0c9794d7 100644 --- a/tests/PSDocs.Tests/PSDocs.Tests.yml +++ b/tests/PSDocs.Tests/PSDocs.Tests.yml @@ -1,4 +1,9 @@ # These are test options + +configuration: + Key1: Value2 + UnitTests.String.1: Config string 1 + markdown: encoding: UTF8 wrapSeparator: 'ZZZ' diff --git a/tests/PSDocs.Tests/PSDocs.Variables.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Variables.Tests.ps1 index c7489685..1e933116 100644 --- a/tests/PSDocs.Tests/PSDocs.Variables.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Variables.Tests.ps1 @@ -39,10 +39,14 @@ Describe 'PSDocs variables' -Tag 'Variables' { Path = $docFilePath InputObject = $testObject PassThru = $True + Option = @{ + 'Configuration.author' = @{ name = 'unit-tester' } + } } It '$PSDocs' { $result = (Invoke-PSDocument @invokeParams -Name 'PSDocsVariable' | Out-String).Split([System.Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries); $result | Where-Object -FilterScript { $_ -like "TargetObject.Name=*" } | Should -Be 'TargetObject.Name=TestObject;'; + $result | Where-Object -FilterScript { $_ -like "Document.Metadata=*" } | Should -Be 'Document.Metadata=unit-tester;'; } It '$Document' { $result = (Invoke-PSDocument @invokeParams -Name 'PSDocsDocumentVariable' | Out-String).Split([System.Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries);