-
Notifications
You must be signed in to change notification settings - Fork 533
Simplify test execution #615
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
Conversation
9e24e01
to
82fe41c
Compare
In fact, I got a bit carried away and did a more extensive bit of tidying among the tests. The extra work is over here; there are a bunch of commits because I was working in small low-risk changes, but the summary is:
My hope is that once that last point is completed it should be much easier to then work out which fixture repo usage can be eliminated. I haven't pushed all that to this PR yet because I'm conscious it's a lot to review and spare time is precious, but if any of that sounds of use, I'll be glad to include it. |
9535343
to
65bcce8
Compare
Not that I know of. If there is, they are unknown to me. These changes look like a step in the right direction to me. I haven't had the chance to look at your extra work yet. |
@urbanautomaton I did want to get your feedback on an alternate idea to run individual tests. Is it a good idea or too hacky? What if you could simply run a single test right from the rake command line: $ rake test tests/units/test_archive.rb
Loaded suite /Users/james/.asdf/installs/ruby/3.2.0/bin/rake
Started
.
Finished in 0.273002 seconds.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 tests, 15 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
3.66 tests/s, 54.94 assertions/s
$ or multiple tests: $ rake test tests/units/test_archive.rb tests/units/test_worktree.rb
Loaded suite /Users/james/.asdf/installs/ruby/3.2.0/bin/rake
Started
.....
Finished in 0.860063 seconds.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
5 tests, 28 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
5.81 tests/s, 32.56 assertions/s
$ or all tests (like normal): $ rake test
Loaded suite /Users/james/.asdf/installs/ruby/3.2.0/bin/rake
Started
...................................................................................................................................................................
....................
Finished in 27.827281 seconds.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
183 tests, 668 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
6.58 tests/s, 24.01 assertions/s
$ Here is the rake code that enables it: desc 'Run Unit Tests'
task :test do
sh 'git config --global user.email "git@example.com"' if `git config user.email`.empty?
sh 'git config --global user.name "GitExample"' if `git config user.name`.empty?
$LOAD_PATH << 'tests'
test_files = []
if (test_index = ARGV.index('test'))
(test_index + 1 .. ARGV.size - 1).each do |i|
break unless ARGV[i] =~ /^tests\//
test_files << ARGV[i][6..-1]
end
end
test_files << 'all_tests' if test_files.empty?
test_files.each { |test_file| require test_file }
end |
f0f3358
to
97df54e
Compare
Thanks for the feedback! On the rake modification: I know what you mean, it'd be nice to have a single entry point for running tests, and I did consider trying to pass the file args via rake. The thing that makes me wary of using If we did want a single entry point capable of running all tests, one test or a subset of tests, I might be tempted to introduce a very simple |
03f866b
to
840d9e1
Compare
The way I have implemented it allows other tasks to be passed on the command line like:
It does work against rake's built in method for passing args, but I find that method to be a bit cumbersome since the square brackets need escaping in zsh. Does that help? |
Also, I reviewed the extra work you did and would love it if those commits were added to this PR. I will squash them all into one commit when I merge to master. Nice work. This is an area of this gem that has needed cleaning up. |
Okay cool, I've pulled in those extra commits. 👍🏻
Ah yes, I'd missed that you're scanning forwards for the first TBH my instinct is that we'd still be working around rake's official way of doing things though, which is likely to be a bit fragile and maybe cause developer confusion. So my leaning would remain towards having a separate test runner executable; I've sketched out what that might look like here, see what you think! |
Looks like you broke a test on Windows. Can you take a stab at fixing it? I am guessing since you didn't notice these broken tests, you aren't running windows. Neither do I... so I'd have to guess a solution and then commit the changes to see if the CI tests pass.
Yes, you convinced me. Please add your changes to this PR. If documentation for how tests are run needs to be updated, please do that too. Maybe we should add a bullet in this section of CONTRIBUTING.md that says something about how to run one or more specific test files. |
21ca063
to
189c6b4
Compare
This commit aims to make working with the test suite easier in two ways: 1. make individual tests easier to run 2. clarify use of fixture repo clones To do this it takes the following steps: * Eliminate complexity due to regular changes of working directory * Make individual test files runnable from the command line using the new bin/test executable * Extract constants to refer to fixture locations * Reduce unnecessary cloning of certain fixture repos * Begin using helper methods to clarify which tests are using which fixture repo Signed-off-by: Simon Coffey <simon.coffey@futurelearn.com>
c95647e
to
22ba027
Compare
Okay cool - I fixed the windows jobs by backing out one of the smaller changes I made, because those failures were isolated to a single test case I modified (I switched from using a bare repo clone to the 'working' fixture). I'm not sure of the exact cause but there's definitely something suspect going on in the tests that use multiple interlinked fixture repos, and I think that's best left to be investigated later. Otherwise I've added the test runner executable and documented it in I'm definitely stopping there for the moment though; from my end it's ready to go. 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed all changes. These are welcome changes. Nice job!
This PR:
On the whole, this PR removed a lot of tech debt and made this gem easier to change. Great job Simon (@urbanautomaton )! This is a great contribution! |
Your checklist for this pull request
🚨Please review the guidelines for contributing to this repository.
Description
Loading files for tests currently involves a lot of manually-constructed relative requires, as well as a
Dir.chdir
in thetests/all_tests.rb
file which adjusts where requires need to be relative from.Apart from some boilerplate, the main effect of this is that it's hard to run a single test file from the command line, as you need to edit the
all_tests.rb
file.This makes things a bit simpler by:
tests
directory to the load path for therake test
taskchdir
fromall_tests.rb
to avboid a bunch of path complexityYou can now run a single test file from the root directory of the project in a fairly standard way:
Feedback
These changes seem simpler to me, but I haven't made a huge effort to investigate why the loading was the way it was. Are there any ways of running or writing tests that my changes would obstruct?