Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FakeVar enhancements #1978

Merged
merged 26 commits into from
Jun 5, 2018
Merged

Conversation

BlythMeister
Copy link
Contributor

Added:

  • Get with type
  • Get or default
  • Get or fail

Also added tests to the above

forceFakeContext()
|> getFakeContext name
|> Option.map (fun o -> o :?> 'a)

let getFakeVarOrFail<'a> name =
match getFakeVar<'a> name with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this to be in a new module and try to keep the api surface (and changes) of the context module as minimal as possible. This is the only module where you have to update the runner in order to get the changes. Therefore your suggestion will break on old runners

Adding the generic parameter is (I believe) harmless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh really :s

i wonder if it's possible to remove all the variable stuff?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if it's possible to remove all the variable stuff?

We maybe could move it somewhere else but have to leave an obsolete attribute for now (we can do the breaking change sometime after the release)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly what I've started working on 😂
All internal usage I'll migrate away from obsolete.

This makes it harder for newbies to understand since the core readme on expecto states "All expect-functions have the signature actual -> expected -> string -> unit, leaving out expected when obvious from the function."

When flip is needed (for pipelines) it's explicitly mentioned
@BlythMeister
Copy link
Contributor Author

Have also updated use of Expecto.Flip as this is quite confusing and subtle when used as a file level "open" statement

@matthid
Copy link
Member

matthid commented Jun 4, 2018

Looking at this, we probably should have basic integration-tests to test if we are still compatible with the old runner

@BlythMeister
Copy link
Contributor Author

Agreed...not sure how to implement...

@matthid
Copy link
Member

matthid commented Jun 4, 2018

not sure how to implement...

The tests? Basically like the current integration tests, but using the "installed" version if fake and not the built one (for example we could use dotnet fake)

Also remove the obsolete i added on AssemblyInfoFile - if someone wants to directly call, they should be able to...
@BlythMeister
Copy link
Contributor Author

@matthid done the refactoring and also fixed a few other things which were build warnings to make it easier to see the wood for the trees when building locally

|> Option.map (fun o -> try
o :?> 'a
with e ->
failwithf "Variable '%s' - %s" name e.Message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use raise <| exn(sprintf "", e) instead (at the very least)

@@ -21,29 +25,35 @@ let getOrDefault<'a> name defaultValue =
let remove name =
forceFakeContext()
|> removeFakeContext name
|> Option.map (fun o -> o :?> 'a)
|> ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes you might want to know which value has been removed? Anyway I'm not sure if it is worth the potential breaking change ;) (On the other hand this one isn't too bad - I don't think anyone uses this directly at the moment.

Copy link
Contributor Author

@BlythMeister BlythMeister Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was working on this being brand new, so not breaking change.
Nobody is using this function at the moment 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I'm probably a bit over cautious on this thing :)
Problem is this is the "connection" between runtime and script and breaking stuff there is a huge pain to cleanup :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree, I was unaware of the link originally

@@ -213,7 +213,6 @@ module AssemblyInfoFile =

/// Creates a C# AssemblyInfo file with the given attributes and configuration.
/// The generated AssemblyInfo file contains an AssemblyVersionInformation class which can be used to retrieve the current version no. from inside of an assembly.
[<System.Obsolete "Please use 'create' instead">]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't like create anymore or what is the rationale?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I was a big agressive on the obsolete. What if someone wanted to control themselves?
Since we don't plan to delete, only make private i see no harm in leaving without obsolete

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't plan to delete

;)

@matthid
Copy link
Member

matthid commented Jun 4, 2018

Generally I really like the direction of this. Good idea to make this a thing and simplify the context module.

Have also updated use of Expecto.Flip as this is quite confusing and subtle when used as a file level "open" statement

I always thought that's how to use it :/. I personally don't really like the default signature, but whatever

@@ -0,0 +1,59 @@
/// This module contains helpers for managing build time variables
module Fake.Core.Variables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add [<RequireQualifiedAccess>]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

@BlythMeister
Copy link
Contributor Author

BlythMeister commented Jun 4, 2018

Re expecto I agree it seems wrong, but personnally spent an hour confused as the code didn't match the docs 😂

@matthid
Copy link
Member

matthid commented Jun 4, 2018

Seems like AppVeyor died :/

@BlythMeister
Copy link
Contributor Author

I noticed it vanished... I didn't do it. 😂
Last commits made from phone as I'm away from laptop until the morning... I hope they compile!

@@ -0,0 +1,60 @@
/// This module contains helpers for managing build time variables
[<RequireQualifiedAccess>]
module Fake.Core.Variables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just fixed the compilation error and I'm not sure about the plural form. But Variable.set doesn't really sound better. Maybe explicitly call it FakeVar or FakeContext for example? Any idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like FakeVar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though that means there is a function called fakeVar so would be FakeVar.fakeVar

How about ContextVariable ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but FakeVar.fakeVar ;)
maybe FakeVar.create instead of that and
FakeContext.set for the raw stuff (or we make that internal)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooo FakeVar.create love it!

@BlythMeister
Copy link
Contributor Author

@matthid made the updates to Fake.Core.FakeVar and really quite like it.
Went with "define" rather than "create" though :)

Copy link
Member

@matthid matthid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it reads really nice now!

@BlythMeister
Copy link
Contributor Author

Shame it has build error.
Will pick it up tomorrow 🤦🏼‍♂️

@BlythMeister
Copy link
Contributor Author

image

<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj">
<FromP2P>true</FromP2P>
</ProjectReference>
<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj" FromP2P="true" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does P2P mean here? I hope this has no effect on dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already here, i just made the projects nicer.
From what i can tell, it enables the transitive project dependencies to be pulled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think all of the references should have it...based on this: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-add-reference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2P = project-to-project

@@ -19,6 +19,7 @@
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" />
<ProjectReference Include="..\Fake.Core.String\Fake.Core.String.fsproj" />
<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably could remove Fake.Core.Context now (but I guess it doesn't hurt)

@matthid
Copy link
Member

matthid commented Jun 5, 2018

Thanks a lot for going all the way with this :) Let's see how it works on staging

@matthid matthid merged commit c6ba91c into fsprojects:release/rc Jun 5, 2018
@BlythMeister BlythMeister deleted the fakeVarType branch May 11, 2021 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants