-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
WIP: Convert to Lib tests #373
base: main
Are you sure you want to change the base?
Conversation
As I said over in #366 I wont force push to this, so feel free to clone and we can all work together on it. I think local work on any given exercise should be rebased before pushing back up here to make cherry picking easier. @kotp @glennj @IsaacG Let me know if you guys would prefer having this branch belong to our exercism repo outright. It might be nice if we could all just have our own version of this branch through our personal clones. Anyway, just let me know ;) |
EDIT:I remember now that I just needed to rerun the travis tests, because sometimes stuff fails for no reason 😟 |
echo "false" | ||
fi | ||
|
||
[[ $1 -eq 0 ]] && echo 'true' || echo 'false' |
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.
(( $1 == 0 )) && ...
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 are very right about that.
At least I upgraded it from []
😂
# Test returns true if the triangle is equilateral | ||
|
||
@test "all sides are equal, equilateral" { | ||
#[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh equilateral 2 2 2 | ||
run equilateral 2 2 2 |
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'm a fan of exporting a single main
or triangle
function that takes a triangle-type as a first arg.
Thoughts?
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.
Given that it is a library I think main here is not right, but I could be convinced that a managing function has its place for namespacing.
This also depends on how our other endeavors into namespacing fare.
If you have some ideas for this exercise please feel free to make a PR to this branch on my fork.
If you would prefer I am interested in making a new branch on the base repo for getting through this ordeal.
I want to know other contributor opinions first though.
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.
Or you can make your own PR for triangle.
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 think this comment thread is getting to the heart of how we want to manage name-spacing in our bash libs.
- do we want any? i.e. let
source
just dump library functionality into the "global" scope - use a top-level function with library functions accessed as sub-commands, as suggested here
- use a function prefix, like I did in the forth example
Does anyone know of any common idioms or best practice guidelines?
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 think the world of bash library modules is all cowboys. We should see if Gnu org has any specification.
I learned that functions may have .
in their names too.
The only problem I have is that my syntax highlighters get confused.
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.
So, I did some more tests.
Double colon (::
) looks nice, but I have also read that it is not guaranteed to work with older versions of bash. I am of the opinion that there is absolutely no reason to be using bash older than v4.x, but historically we have not wanted to make Mac
users upgrade bash against their will.
I am not against setting v4.2 as a requirement for the track. Hell, I am on v5.0.7, but I would not make this requirement all on my own.
If we decide against enforcing a minimum Bash version, then I see no other way to namespace the functions than by using an module access function.
In order for this not to confuse students it should be present in the stub. We would need to decide if we write the whole thing, so they don't have to worry about it or not.
Then we are left with the decision about how to name the parts it calls. Good naming convention would then make the former API functions internal and they should be preceded by a _
. I think this will get ugly very quickly, and it is not really exposing students to a common pattern in the shell world. Furthermore, it doesn't do much to help with possible collisions in the world.
While I think that ::
is ideal (even if a bit non-standard) I am feeling less comfortable with the interface function pattern. I honestly think that normally lib sourcing is the way to go here.
If it makes us feel any better. Golang's tests are in the same packagespace as the code, so all of the functions are called without namespacing.
Also, our namespacing ideas were never going to solve issue of set options colliisions with bats
' internal requirements. To do that we would need to execute the run commands in a sub-shell. This might work, but it needs to be tested.
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.
@issacg I guess we were typing at the same time 🤣
It seems we both came to the same conclusion (although I am very verbose as usual).
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.
Looking around at other languages like Python and Ruby it is very evident tha no one else is worrying about this (but in their languages those functions will be namespaced once they are imported somewhere). That just isn't the way of life here 😄
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.
Note bash 3 (or, at least 3.2.57) supports space::func just fine. While we may not want to enforce bash 4+, I think it's fair to expect bash 3 or newer.
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.
Thanks for checking.
Additionally, if these are bash libraries (they are not posix compliant) then they should have |
The invalid and wontfix labels are added just to remind not to merge. |
Thank @kotp those labels are a good reminder. Do you have an opinion on whether or not this project should be switched to an architecture wherein it is a direct branch of |
I think it is fine where it is, until it isn't. We can clone it down and work with it locally, as it is. |
FYI I have not noticed any problems with function names containing |
So, is it possible to get new count of our positions regarding namespaces? Still my vote would be for no namespaces, since students are unlikely to encounter that so much in wild (although it does exist). |
Tally for namespacing:
|
Since this is a bash-specific track and bash is not POSIX compatible, IMO don't care.
This is like @guygastineau what's "with Function" mean? Is that capitalizing the library function names? |
I'll vote for yes namespace. |
@IsaacG I assume you mean with |
@glennj I meant using a function that takes subcommands to act as the entry point for the library. |
Yes, I'm in favor of using the |
ref #376 |
I feel like this is the Bash track, and so by definition not It may be interesting to have a
This seems to happen on Debian (and at least some derivatives). OpenBSD seems to use something a little more Korn-y. So the practice of "portability" using Instead, as this is the Bash track, we should use Just some thoughts as it regards my "vote" in Tally for Namespacing. |
How is that going to affect the CI scripts? I guess we'll have to throw a little extra logic into |
No direct answer to this, but no (long term) logic. All should be |
Really good discussion here 🔥 another thing worth noting, by changing @test "a name given" {
[[ $BATS_RUN_SKIPPED == true ]] || skip
run two_fer Alice
[[ $status -eq 0 ]]
[[ $output == "One for Alice, one for me." ]]
} printDiff(){
echo output;
echo "$output";
echo ;
echo expected;
echo "$expected;
}
@test "a name given" {
[[ $BATS_RUN_SKIPPED == true ]] || skip
run two_fer Alice
expected=$(cat <<-END
One for Alice, one for me.
END
)
printDiff
[[ $status -eq 0 ]]
[[ "$output" == "$expected" ]]
} |
And as a side note: the test runner should also be updated. It might even be necessary to support both formats to not break old exercises. Did we decide how to handle such a situation @iHiD ? |
This PR has seen no activity in 6 months. Is it still being used or should it be closed out? |
Leave it be. It is draft and still has a place. |
This is not intended for merging at all, but rather it is intended to share ideas about how to convert our tests to library testing. That being said, if commits only ever involve 1 exercise, then we can easily cherry pick conversions where we agree, so they can be merged in their own PR.
For now, I just did
two-fer
initial PoC andtriangle
since it is a bit more relevant.@glennj I played with the
::
you used for name spacing inforth
, but I could not get it to work fortriangle
. It kept returning an error status. Anyway, I will keep investigating that, but any investigation you feel like doing would be appreciated.I noticed that
nounset
absolutely may not be used in the implementation files for lib testing.source
ing the file into bats, then pollutes the bats environment. Since bats relies on variables being unset sometimes it will not work. We can probably use something likebash -c "source triangle; equilateral 2 2 2"
to keep from polluting the bats environment. We should make sure we discuss this ;)closes #366
Reviewer Resources:
Track Policies