-
-
Notifications
You must be signed in to change notification settings - Fork 776
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
Add property based tests to assess load reverses dump #398
Conversation
I don't understand why this test is needed. Could you explain? |
The idea of this test is to cover (and maybe discover) edge-cases of the js-yaml package we have not think about in the already existing unit-tests. By definition, units cannot cover the range of all possible failures and might miss some complex corner cases. They are based on fixed inputs and expect fixed outputs. The suggested and complementary approach suggested here, is to add some properties (or contracts) we want to confirm on the package. For the moment the one I introduced check that for any valid object the yaml produced by js-yaml can be read by itself and return the original object. The strength of property based testing approach is that it does not limit itself to a pre-defined subset of possible entries but goes far beyond by building whatever entry we considered valid. In this example, I defined a valid entry as being all objects whose keys are strings and values are booleans, numbers, strings, nulls, arrays of values or sub-objects. If for any reasons, one of the objects built by the framework made the property failed, the framework will try to reduce it to the minimal object (less keys, smaller values...). |
IMHO, in existing context, this looks like adding code "just for fun" - no examples that such tests could help in the past and how those will help in future. I prefer to avoid unnecessary code when possible - more easy to maintain then. |
I found a bug in the code of js-yaml using this technic. Indeed js-yaml can produce illegal unicode files. It accepts incomplete surrogate pairs as input. |
For the above comment, you can try to build a YAML file from |
@puzrin Forget about the encoding issue I reported. I enhanced the scope of my property based tests in order to find real issues and found some quite interesting ones when playing on It appears that some yaml values generated by yaml.safeLoad(yaml.safeDump({"":[{"\u0000":""}]},{"condenseFlow":true,"flowLevel":1})); @puzrin Can you confirm that this is a real bug? More on this test at https://runkit.com/dubzzz/multiple-properties-for-js-yaml |
|
@puzrin const options = {styles:{'!!int':'binary'}};
yaml.safeLoad(yaml.safeDump({toto: 10}, options)); // produces: {toto: 10}
yaml.safeLoad(yaml.safeDump({toto: -10}, options)); // produces: {toto: "0b-1010"} When negative the integers values produced by js-yaml are read as strings (whereas they are read as integers for positive integers). |
The right negative binary for -10 should have been -0b1010 not 0b-1010 |
I agree, that's a real bug of int representer https://github.com/nodeca/js-yaml/blob/master/lib/js-yaml/type/int.js#L159-L164. Question is - do we need this code in core to maintain forever, or it's a one-time action. |
I would say that yes, we should keep some kind of test like this. They ensure non regression and can cover configurations yet uncovered by unit tests. Basically, no one can confirm that no other combination of settings or refactoring would break the code in the future. So yes, I believe it can still be useful to have it. I am currently trying to revamp the code of the pull request in order to provide a more maintainable code. |
Ок. Put it all into |
109f25c
to
a02e455
Compare
Just updated the pull request. Expected failure due to #399 You can see that in the logs of the job:
Please keep me updated if you want a change in the code. |
IMHO it's better to put everything into one file, as i said - more easy to maintain. No need to create complicated files structure in advance. |
Ok, I will update my change |
test/25-dumper-fuzzy.js
Outdated
suite('Properties', function () { | ||
var directory = path.resolve(__dirname, 'properties'); | ||
|
||
fs.readdirSync(directory).forEach(function (file) { |
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.
Could you put here content of ./properties/identity.js
instead of files load? You do too complicated load for single test that will never be extended (with high probability).
Update done, sorry for the delay |
Thanks! |
* master: (58 commits) Check for leading newlines when determining if block indentation indicator is needed (nodeca#404) Add property based tests to assess load reverses dump (nodeca#398) 3.11.0 released Browser files rebuild Dumper: fix negative integers in bin/octal/hex formats, close nodeca#399 support es6 arrow functions, fixes nodeca#389 (nodeca#393) Fix typo in README.md (nodeca#373) 3.10.0 released Browser files rebuild Add test for astrals dump Combine surrogate pairs into one escape sequence when encoding. (nodeca#369) Fix condenseFlow for objects (nodeca#371) correct spelling mistake (nodeca#367) More meaningful error for loader (nodeca#361) Fix typo and format code. (nodeca#365) 3.9.1 released Browser files rebuild Ensure stack is present for custom errors (fixes nodeca#351) (nodeca#360) 3.9.0 released Browser files rebuild ...
No description provided.