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
improve test scripts #44
Conversation
zimbatm
commented
Dec 25, 2017
- validated with shellcheck
- allow to evaluate just one for convenience
- reduce verbosity and improve debugging output
* validated with shellcheck * allow to evaluate just one for convenience * reduce verbosity and improve debugging output
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.
@zimbatm, I really appreciate that you made Travis CI to work, and I do appreciate the time you've spent on doing this, but...
This turns a 15-line shell script into 45 lines without much return.
It hides useful information (list of derivations that will be built might be useful, e.g. it might help debug stuck builds). CI logs should be as verbose as possible. When my local checks stutter with download-from-binary-cache.pl
, I also want to know that.
It introduces a checker that has to be babysitted by adding magical comments and makes the script much harder to change without causing subsequent checks to fail (see NixOS/nixpkgs#32857).
It also includes redundant formatting that mostly duplicates what is currently being emitted by the script or by nix-build
command.
I think this is over-engineered out of proportion and what we currently have (roughly, your second rebase of #40) is close to being ideal, other than missing --show-trace
.
@@ -0,0 +1,35 @@ | |||
#!/bin/sh |
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.
Evaluating just one is not a proper test, because profiles can be inherited (even model profiles, because there might be revisions, e.g. later revisions of X220 do not support tp_smapi
).
It can be done via nixos-rebuild -I nixos-config=tests/eval-test.nix nixos-hardware-config=path/to/default.nix dry-build
. I think it's a bad idea to allow to eval just one profile via a script.
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.
Travis will evaluate all of them in the end, or not?
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.
Travis evaluates every profile on each push or pull request.
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.
The idea here is that I can test my profile without having to wait on all the others to evaluate. Travis is testing all the profiles anyways.
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.
You shouldn't assume that your profile isn't inherited by any other profiles. Profile might be inherited by someone from another directory, e.g. in case of brand renaming (e.g. IBM ThinkPad -> Lenovo ThinkPad), including a model profile.
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.
How is this relevant? Travis will catch this eventually.
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.
It's relevant in that it's not a test and thus should not be exposed. It's possible to see someone with merge rights using eval-one
test for convenience and then pushing to master
.
Actually, doing that is the only use case I can come up with in regards to this script.
tests/eval-test.sh
Outdated
@@ -1,15 +1,11 @@ | |||
#!/bin/sh | |||
set -efu | |||
cd "$(dirname "$0")/.." || exit 1 |
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.
This can't really fail.
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.
|| exit 1
should not be necessary, since set -e
is used.
ret=$? | ||
|
||
if [ "$ret" -gt 0 ]; then | ||
echo ERROR |
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.
nix-build
already prints "error", we don't need to print that twice.
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.
Look at the Travis CI output logs and you will understand.
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 don't understand: https://travis-ci.org/NixOS/nixos-hardware/builds/321451543#L5488
-I "nixos-config=$here/eval-test.nix" \ | ||
-I "nixos-hardware-profile=$profile" \ | ||
--dry-run \ | ||
--no-out-link \ |
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.
--no-out-link
doesn't do anything when --dry-run
is present.
nix-build \ | ||
'<nixpkgs/nixos>' \ | ||
-I "nixos-config=$here/eval-test.nix" \ | ||
-I "nixos-hardware-profile=$profile" \ |
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.
We shouldn't allow profiles that have spaces in names.
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.
It doesn't hurt to escape the argument in either case
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.
It does. We should enforce that there are no spaces in names.
--dry-run \ | ||
--no-out-link \ | ||
--show-trace \ | ||
-A system > "$logfile" 2>&1 |
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 don't see the point of having a log file instead of stderr, and I think it hides a lot of potentially useful information. Also, the idea of stderr is exactly to have an error log.
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.
The test will only produce output when the test fail and will output both stdout and stderr. This sounds good to me.
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.
It doesn't matter, I think nix-build
only ever writes to stderr. What matters is that sometimes CI builds may stutter, and with this approach, we'll never know why.
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.
Also 2>&1
is a bashism.
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.
@yegortimoshenko With this approach it's easy to find the failing profile and get to the point instead of going through pages of repeating out links. They might be interesting but not very useful in practice.
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.
Right, you only need logs if something goes wrong. Your way of doing things makes certain errors opaque and non-debuggable.
tests/eval-test.sh
Outdated
set -e | ||
|
||
cd "$(dirname "$0")/.." | ||
echo "### Evaluating all profiles ###" |
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.
This is redundant.
profile=$1 | ||
logfile=$(mktemp) | ||
|
||
# shellcheck disable=SC2039 |
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.
What's the point of using a tool when it requires magic comments to do its job? I think shellcheck
is very overreaching, and we shouldn't use it.
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.
It catches a lot of common mistakes and educates the users about shell corner-cases.
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.
We don't need that for fifteen lines of shell script. And teaching people to use something doesn't make magical comments OK.
-I "nixos-hardware-profile=$profile" \ | ||
--dry-run \ | ||
--no-out-link \ | ||
--show-trace \ |
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.
--show-trace
might be useful and should make it into master
.
tests/eval-test.sh
Outdated
|
||
# shellcheck disable=SC2044 |
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.
Not sure why you ignore this check: https://github.com/koalaman/shellcheck/wiki/SC2044
In this case, it could be rewritten as find . -name default.nix -exec tests/eval-one.sh {}
. But again, I think we shouldn't accept files with weird names into this repo, and current shell script makes sure that we won't.
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.
There is no solution that doesn't depend on word splitting, without depending on bash 4. find -exec
doesn't early-return nor propagate the exit status. I don't think that profiles should contain special characters in any case.
tests/eval-test.sh
Outdated
@@ -1,15 +1,11 @@ | |||
#!/bin/sh | |||
set -efu |
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.
set -o pipefail
also comes handy.
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.
It is a bashism.
Resolved in #66 with a fundamentally different approach. |
@zimbatm I shouldn't have behaved so aggressively over this. I'm sorry. |