-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Put exercise generation under test #426
Conversation
This change alters `ExercismGenerator` just enough to allow side effect free tests. Having the class under test enables future refactoring. Three dependancies made this class difficult to test: - `PipeableOSProcess` executed commands outside of the Pharo VM - `ExTonelWriter` wrote files to the OS filesystem - `ExercismExercise` would access a variable number of exercises depending on how many were implemented To get this class under test the above dependancies have been placed in lazy assigned instance variables. This allows tests to assign mocks to the generator instance. There are two mock OS processes, one that always succeeds, and one that always fails. Neither executes any function outside the VM. A `ExTonelWriter` writes exercises to an in memory file system that lasts only for the test. A mock exercism exercise class returns only a single exercise. This speeds up the test and makes it more consistent as it won't change when more exercises are implemented.
One of my tests broke in CI. I'll take a look. |
The change is a test that passed on my personal computer (MacOS) but failed in CI (Ubuntu 16.04). I suspect that even though the tests use an in memory file system OS specific line-feed and carrage-return characters will be used causing enough of a difference between the expected result and the actual result of the test to fail. This change makes the line ending characters of the actual and expected results identical before asserting. The test design closely follows that of `TonelWriterTest` which also uses an in memory file system.
The failing test might be due to a difference in line ending characters for the OS running the test and the line endings in the expected test results. I've forced the expected results and the actual results to use the same line endings before assertions are made. This seems to have worked. CI is now green. |
@exercism/reviewers could I please have someone review this change? It's in Smalltalk so if you know a bit of Ruby you will at least know the OOP side of things. I'm happy to talk you through everything else. |
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 looks fine to me :3
I think you're right on the "line ending" issue when files are compared. Even accounting for OS line endings isn't good enough because .gitattributes
and git local and global config can override it. Normalizing line-endings is usually the way to go.
|
||
We have to do it this way as Exercism conventions differ from Tonel, and so we need to output them to a seperate directory suitable for the Exercism command line tool. | ||
I am responsible for generating kebab-cased Exercism V2 directories, each containing a seperate exercise for users. |
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.
(is it common in smalltalk that classes are personified?)
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.
When you make a class for the first time the default class comment template has an example that includes For example, "I represent a paragraph of text"
. I took a quick look through some of the class library. It seems to be a common, but not universal practice. I've stuck with the convention ever since I saw it although I don't use it in any other programming language.
Personified classes is very much a smalltalk trait - and it harks back to the original Logo work at Xerox where they studied this cognitively (Anthropomorphism <https://www.merriam-webster.com/dictionary/anthropomorphism>)
In a way, I think its a shame that this research has been lost and not made its way into the main stream - as its very powerful way of understanding your applications. In fact the whole live environment in Smalltalk is based on this idea.
On Mon, 19 Oct 2020, at 7:48 AM, Samuel wrote:
***@***.**** commented on this pull request.
In dev/src/ExercismDev/ExercismGenerator.class.st <#426 (comment)>:
>
-We have to do it this way as Exercism conventions differ from Tonel, and so we need to output them to a seperate directory suitable for the Exercism command line tool.
+I am responsible for generating kebab-cased Exercism V2 directories, each containing a seperate exercise for users.
…
When you make a class for the first time the default class comment template has an example that includes `For example, "I represent a paragraph of text"`. I took a quick look through some of the class library. It seems to be a common, but not universal practice. I've stuck with the convention ever since I saw it although I don't use it in any other programming language.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#426 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABKL3V3WM4HHQPV52NW3XH3SLPOLJANCNFSM4STA7M5A>.
|
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 honestly can't comment on the code (except for that it looks really well documented!), so I'll approve :)
Thanks for the interesting bit of info @macta. @SleeplessByte @ErikSchierboom thanks for the reviews. Merging now. |
This change puts the exercise generation for V2 under test. With this in place we can start work on a new generator for V3. My approach will be to create a duplicate of the V2 generator and alter it for V3 output. We can then start moving common behavior into a superclass. With the tests in place this becomes much easier to do while maintaining existing functionality.
Commit Message
This change alters
ExercismGenerator
just enough to allow side effect freetests. Having the class under test enables future refactoring. Three dependencies
made this class difficult to test:
PipeableOSProcess
executed commands outside of the Pharo VMExTonelWriter
wrote files to the OS filesystemExercismExercise
would access a variable number of exercises depending on how many were implementedTo get this class under test the above dependencies have been placed in lazy
assigned instance variables. This allows tests to assign mocks to the generator
instance.
There are two mock OS processes, one that always succeeds, and one that always fails.
Neither executes any function outside the VM.
A
ExTonelWriter
writes exercises to an in memory file system that lasts onlyfor the test.
A mock exercism exercise class returns only a single exercise. This speeds up the
test and makes it more consistent as it won't change when more exercises are implemented.