Skip to content

Conversation

@mansimarkaur
Copy link
Contributor

@mansimarkaur mansimarkaur commented Jul 26, 2017

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew tests with your changes locally?

Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't use instance variables to describe a test, since this doesn't really explain what it is supposed to do.

@MikeMcQuaid
Copy link
Member

Some test failures:

Failures:
  1) Utils#self.svn_remote_exists returns true when svn is not available
     Failure/Error: expect(described_class.svn_remote_exists(url)).to be_truthy
       expected: truthy value
            got: false
     # ./test/utils/svn_spec.rb:26:in `block (3 levels) in <top (required)>'
     # ./test/spec_helper.rb:91:in `block (2 levels) in <top (required)>'
     # ./vendor/bundle/ruby/2.0.0/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in `block (2 levels) in <top (required)>'
  2) Utils#self.svn_available? returns false if svn --version command does not succeed
     Failure/Error: expect(described_class.svn_available?).to be_falsey
       expected: falsey value
            got: true
     # ./test/utils/svn_spec.rb:12:in `block (3 levels) in <top (required)>'
     # ./test/spec_helper.rb:91:in `block (2 levels) in <top (required)>'
     # ./vendor/bundle/ruby/2.0.0/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in `block (2 levels) in <top (required)>'
Finished in 7 minutes 2 seconds (files took 4.75 seconds to load)
985 examples, 2 failures
Failed examples:
rspec ./test/utils/svn_spec.rb:24 # Utils#self.svn_remote_exists returns true when svn is not available
rspec ./test/utils/svn_spec.rb:10 # Utils#self.svn_available? returns false if svn --version command does not succeed

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this test performing network access?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is performing network access. Do you think I should add a local repo instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed on Slack - preferably, it'd be good to use a local repo here. If something has to use the network and we don't have another option, it'll need the :needs_network tag so that it only gets run with brew tests --online.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests are behaving weirdly on my system. In the first run, only 1 test case fails, in the second 3 tests cases fail. I can kind of see this pattern here. Could you please try running the tests on your system and let me know what happens, @mistydemeo ?

@apjanke apjanke closed this Jul 28, 2017
@apjanke apjanke reopened this Jul 28, 2017
@mansimarkaur
Copy link
Contributor Author

@apjanke Why was this PR closed?

@apjanke
Copy link
Contributor

apjanke commented Jul 29, 2017

I have no idea! I think I accidentally hit the wrong button on GitHub. Please ignore.

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't need mktmpdir here; this is already in a temporary directory.

Copy link
Member

Choose a reason for hiding this comment

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

This won't be run if the expectation fails.

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've added a begin ... ensure block to take care of this now.

Copy link
Member

Choose a reason for hiding this comment

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

This will not reset the variable after the test, can you find a way to test the functionality that actually sets this to true? Otherwise, the only thing this is testing is whether svn_available? uses this variable.

Copy link
Member

Choose a reason for hiding this comment

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

Or alternatively: call a method that calls this so it's covered but not by a unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This variable will be set only if svn_available? has been called successfully atleast once. So, there is no method which can ensure @svn will already exist if svn is not available on the system.
I'm removing @svn before each test now. I don't think svn_version already set can work without setting @svn because on a system without svn, this test won't work the way it should.

Copy link
Member

Choose a reason for hiding this comment

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

I think it may be worth allowing the svn shim to be called. What fails if it is?

Copy link
Member

Choose a reason for hiding this comment

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

I think it may be worth allowing the svn shim to be called. What fails if it is?

Copy link
Contributor Author

@mansimarkaur mansimarkaur Aug 12, 2017

Choose a reason for hiding this comment

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

On some systems it might be successful and on some it might not be. So, I can just check that quiet_system will return either true, nil or false if svn shim is called.

Copy link
Member

Choose a reason for hiding this comment

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

On any macOS system there will always be a working svn and git so let's assume that during the tests, too, thanks.

@mansimarkaur mansimarkaur force-pushed the svn branch 2 times, most recently from 5fb5025 to f659a03 Compare August 15, 2017 11:20
Copy link
Contributor

@mistydemeo mistydemeo left a comment

Choose a reason for hiding this comment

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

Left one comment, but otherwise looks good to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this test just doing the same thing as the previous one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. I guess I should remove it. I've removed such similar tests in git tests as well. Thanks :)

Copy link
Member

Choose a reason for hiding this comment

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

Need to try and figure out a way to not set/get instance variables here. If need be: delete the relevant tests that need them set given we're almost at the end of GSoC. Ideally: just call other methods that end up calling these ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, I'm trying to remove the instance variable if already set because once svn_available? is called, it will set the @svn instance variable. To make these tests independent of each other, I need to ensure that the instance variable is not set beforehand. What do you suggest in this case?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps adding a new method clear_svn_location_cache or similar and call that in the before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! :)

Copy link
Member

Choose a reason for hiding this comment

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

Why does this need to use mktmpdir and not write to an already existing location that's deleted after tests: for example:

FileUtils.rm_rf [
TEST_DIRECTORIES.map(&:children),
HOMEBREW_LINKED_KEGS,
HOMEBREW_PINNED_KEGS,
HOMEBREW_PREFIX/".git",
HOMEBREW_PREFIX/"bin",
HOMEBREW_PREFIX/"share",
HOMEBREW_PREFIX/"opt",
HOMEBREW_PREFIX/"Caskroom",
HOMEBREW_LIBRARY/"Taps/caskroom",
HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bar",
HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bundle",
HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo",
HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-services",
HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-shallow",
HOMEBREW_REPOSITORY/".git",
CoreTap.instance.path/".git",
CoreTap.instance.alias_dir,
CoreTap.instance.path/"formula_renames.json",
]

Copy link
Member

Choose a reason for hiding this comment

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

It's also really confusing to have a directory named url. Instead just use HOMEBREW_CACHE and no let.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. It's better to use a location that is already deleted after tests. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Consider using https://github.com/Homebrew/install as it's really small and we control it (you can clone GitHub repositories as Subversion repositories).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the above url, I'm getting the following:

Error validating server certificate for 'https://github.com:443':
 - The certificate is not issued by a trusted authority. Use the
   fingerprint to validate the certificate manually!
Certificate information:
 - Hostname: github.com
 - Valid: from Mar 10 00:00:00 2016 GMT until May 17 12:00:00 2018 GMT
 - Issuer: DigiCert SHA2 Extended Validation Server CA, www.digicert.com, DigiCert Inc, US
 - Fingerprint: D7:9F:07:61:10:B3:92:93:E3:49:AC:89:84:5B:03:80:C1:9E:2F:8B
(R)eject, accept (t)emporarily or accept (p)ermanently?

In the tests, how do I ensure that I don't need to manually answer the above posed question of accepting the host?

Copy link
Member

Choose a reason for hiding this comment

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

HOMEBREW_CACHE.cd { system ... }

Copy link
Member

Choose a reason for hiding this comment

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

This is never needed, except in tests, so this shouldn‘t exist in the actual code.

Copy link
Member

Choose a reason for hiding this comment

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

@reitermarkus I'm not sure how this gets resolved without adding a method here. What would you propose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about adding a method in one of the support modules for tests to clear any instance variable? As in a method whose argument is the instance variable to be cleared. @MikeMcQuaid @reitermarkus @mistydemeo

Copy link
Member

Choose a reason for hiding this comment

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

@mansimarkaur If by support modules you mean in the spec_helper or something then: yeh, that could work. @reitermarkus?

Copy link
Member

Choose a reason for hiding this comment

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

Also, there's probably some times this method should be called anyway such as e.g. after a new installation of svn (and same thing for git)

Copy link
Contributor Author

@mansimarkaur mansimarkaur Aug 25, 2017

Choose a reason for hiding this comment

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

@MikeMcQuaid Yes, I meant adding a method in the spec_helper but if we want to call this cache clear method after a new installation, then we don't need to add it in the spec_helper. Which is a better alternative? Also, utils/git.rb already has a Utils.clear_git_available_cache to remove @git, @git_path and @git_version: https://github.com/Homebrew/brew/blob/master/Library/Homebrew/utils/git.rb#L66

Copy link
Member

Choose a reason for hiding this comment

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

@mansimarkaur I think this is fine as-is, then, thanks.

@mansimarkaur
Copy link
Contributor Author

There is something wrong with codecov. The base coverage is missing. Could you please help?

Copy link
Contributor

@mistydemeo mistydemeo left a comment

Choose a reason for hiding this comment

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

This looks good to me. Could you get the commit history ready for merging?

@mansimarkaur mansimarkaur force-pushed the svn branch 2 times, most recently from 97565f3 to dfe7338 Compare August 26, 2017 20:07
@mistydemeo mistydemeo dismissed MikeMcQuaid’s stale review August 27, 2017 01:08

Requested changes have been made

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

One tweak required otherwise 👍

Copy link
Member

Choose a reason for hiding this comment

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

Actually: this shouldn't be a problem because it's not an issue with the formula that's being audited. Instead I'd just do next unless Utils.svn_available?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! Made the change. Thanks :)

@mistydemeo mistydemeo merged commit 156bca7 into Homebrew:master Aug 29, 2017
@mistydemeo
Copy link
Contributor

Thanks!

@MikeMcQuaid
Copy link
Member

Thanks for this @mansimarkaur, nice work!

@Homebrew Homebrew locked and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants