Skip to content
Merged
16 changes: 11 additions & 5 deletions ConsumePlugin/ArgParserConflictTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ open WoofWare.Myriad.Plugins
// This file contains test cases for conflict detection in the ArgParser generator.
// These are expected to FAIL at build time with appropriate error messages.
// Uncomment each section one at a time to test the specific conflict detection.
//
// These cases (and case-insensitive variants of them) are asserted automatically in
// WoofWare.Myriad.Plugins/Test/TestArgParserRejection.fs, which drives the generator over
// in-memory source; the copies here are kept for manual end-to-end confirmation that a real
// build fails.

// ============================================================================
// Test 1: Field named NoFooBar conflicts with FooBar's --no- variant
// ============================================================================
// Expected error: Argument name conflict: '--no-foo-bar' collides with the --no- variant
// of field 'FooBar' (which has [<ArgumentNegateWithPrefix>])
// Expected error: The argument name '--no-foo-bar' is claimed by: the --no- variant of field
// 'FooBar' (which has [<ArgumentNegateWithPrefix>]); '--no-foo-bar' (field 'NoFooBar')

(*
[<ArgParser>]
Expand All @@ -25,8 +30,8 @@ type ConflictingFieldNames =
// ============================================================================
// Test 2: ArgumentLongForm "no-foo" conflicts with Foo's --no- variant
// ============================================================================
// Expected error: Argument name conflict: '--no-foo' collides with the --no- variant
// of field 'Foo' (which has [<ArgumentNegateWithPrefix>])
// Expected error: The argument name '--no-foo' is claimed by: the --no- variant of field
// 'Foo' (which has [<ArgumentNegateWithPrefix>]); '--no-foo' (field 'Bar')

(*
[<ArgParser>]
Expand All @@ -42,7 +47,8 @@ type ConflictingLongForm =
// ============================================================================
// Test 3: Multiple ArgumentLongForm, one conflicts
// ============================================================================
// Expected error: Argument name conflict: '--no-verbose' collides with...
// Expected error: The argument name '--no-verbose' is claimed by: the --no- variant of field
// 'VerboseMode' (which has [<ArgumentNegateWithPrefix>]); '--no-verbose' (field 'Quiet')

(*
[<ArgParser>]
Expand Down
36 changes: 36 additions & 0 deletions ConsumePlugin/Args.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ type ParentRecord =
AndAnother : bool
}

type ChildRecordWithDefault =
{
[<ArgumentDefaultFunction>]
FromFunction : Choice<int, int>
}

/// The default-function convention resolves against the record which declares the field,
/// not against the [<ArgParser>]-tagged root.
static member DefaultFromFunction () = 97

[<ArgParser true>]
type ParentRecordChildDefault =
{
Child : ChildRecordWithDefault
AndAnother : bool
}

type ChildRecordWithPositional =
{
Thing1 : int
Expand Down Expand Up @@ -191,6 +208,17 @@ type ManyLongForms =
SomeFlag : bool
}

[<ArgParser true>]
type AliasedPositionals =
{
Count : int

[<PositionalArgs>]
[<ArgumentLongForm "rest">]
[<ArgumentLongForm "remainder">]
Others : string list
}

[<RequireQualifiedAccess>]
type private IrrelevantDu =
| Foo
Expand Down Expand Up @@ -259,3 +287,11 @@ type WithMultilineTypeHelp =
OutputDir : string
Force : bool
}

/// Regression test: the pre-rewrite generator produced uncompilable code for a non-positional
/// list of booleans (its accumulator was a ResizeArray but the flag machinery assumed an option).
[<ArgParser>]
type NonPositionalBoolList =
{
Flags : bool list
}
8 changes: 7 additions & 1 deletion ConsumePlugin/ConsumePlugin.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,17 @@
<Compile Include="GeneratedArgParserNegationTests.fs">
<MyriadFile>ArgParserNegationTests.fs</MyriadFile>
</Compile>
<Compile Include="Nested/Args.fs" />
<Compile Include="Nested/GeneratedArgs.fs">
<MyriadFile>Nested/Args.fs</MyriadFile>
</Compile>
<Compile Include="OpensLeakRegression.fs" />
<Compile Include="GeneratedOpensLeakRegression.fs">
<MyriadFile>OpensLeakRegression.fs</MyriadFile>
</Compile>
<!-- Not compiled, because by design they *don't* compile. That makes them very hard to test in an automated way! -->
<!-- Not compiled, because by design they *don't* compile. The automated equivalents live in
WoofWare.Myriad.Plugins/Test/TestArgParserRejection.fs, which drives the generator over
in-memory source; this copy is kept for manual end-to-end confirmation. -->
<None Include="ArgParserConflictTests.fs" />
<!-- To run the conflict tests:
<Compile Include="GeneratedArgParserConflictTests.fs">
Expand Down
Loading
Loading