-
Notifications
You must be signed in to change notification settings - Fork 464
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
Correct handling of escaped interpolation \#{} #798
Conversation
smikes
commented
Jan 2, 2015
- partial merge of change to inspect.cpp
- initial set of catch unit tests
- add quote to Makefile.am
- remaining tests to cover quote
- escape backslash
- fix pin tests
- add more tests of current behavior
- factor out interpolant fns
- correct implementation of next_unescaped_interpolant
- unit tests for next_unescaped_interpolant
- ignore Emacs TAGS files
Here is a candidate PR for the first part of my work on quoting/interpolation in libsass. See sass/sass-spec#218 for the spec. Although the code in libsass that detects interpolations appears to ignore escaped ones:
my unit tests showed that this did not work. Worked around it in the stupidest way possible, that is, with an explicit guard. May be amenable to cleanup later, but for now, this is a step that increases correctness and coverage (+0.06%) |
} | ||
char q; | ||
if (*s.begin() == '"' && *s.rbegin() == '"') q = '"'; | ||
else if (*s.begin() == '\'' && *s.rbegin() == '\'') q = '\''; |
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.
q
is unused, isn't 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.
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.
Oh nice. I was just checking appveyor build: https://ci.appveyor.com/project/sass/libsass/build/1.0.6. Not sure why mingw made it a matter of fatality and terminated tests for such a trivial reason (it should just be a compiler warning). msvc is also choking with unresolved symbol.
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 running with an implicit 'warnings as errors' setting? Anyway, thanks for pointing it out. When 1.0.14
https://ci.appveyor.com/project/sass/libsass/build/1.0.14 finally runs we'll see if I got it.
Just wanted to give you some feedback on your work after a short review:
*1: I guess we want to keep the fragmentation at least down to a certain level. I agree that seperation is a good principle, but it also increases compile time. I think quote/unquote would fit very well into utils.cpp! *2: This is a bit more complicated and there have been already a lot of discussions about this. AFAIK we do not want to integrate another test framework without further considerations, so this seems IMHO not acceptable for this PR! Prefered solution in this case would be that you could re-create most of the test cases as spec-tests! We definately want to add more and better testing and are open for further PRs, but we need quite a bit to cover all cases:
Currently the core developers are mostly on bringing the code up to sass 3.4 parity! So the testing seems to get little attention. I use To do this properly we will need to have a test-runner in C that can test all the above scenarios. Once we have that, it could also include more basic tests like the once you have in this PR! |
Okay, I will move the quote/unquote functions into util. I will remove the unit tests from this PR. I appreciate that nobody wants to add a new dependency, especially a random untried C++ unit test framework. However, I argue that unit tests are critical to this project, and in particular, for quoting/unquoting and similar internal functions that are never exposed. In this case, I was only able to implement a correct Catch provides everything I want in a modern test framework for C++, including selecting tests by name or by tag, various output formats, separate compilation etc. Please check it out, and if there is no consensus about a unit test framework but a general consensus that there ought to be more testing, I would volunteer to support Catch unit tests. https://github.com/philsquared/Catch In any case, I will continue to maintain unit tests in my own branch and try to prevent them from leaking into my PRs. |
I agree that we are in desperate need of better testing. We do have a very good test-suite, which ensures pretty well that we do not break existing compiles. But when it comes down to tiny details, we are in lack of any testing! I also have my "own" tests in the perl-bindings to test stuff on the C-API which we do not currently test inside libsass itself. The same goes for the node-sass test-suite. But be aware that a sufficient test suite for libsass should include source-maps, exit-codes, error-msgs, warnings, importers and more! We would (AFAIK) love to replace the current ruby spec runner with a native C++ implementation. This would IMO be a great opportunity for somebody who would like to get to know the libsass internals 😉 Edit: Just a wild idea, but I think you could put your C unit tests into an own repository with a Makefile and links against libsass!? That way we might could adopt it as an alternative test runner someday!? |
Regarding tests, libsass relies on sassc executable, which also acts like a driver to run sass-spec test suite, which uses Ruby as an intermediary. But we only achieve functional testing by this approach (on relying on tertiary agent libsass->sassc->ruby..). Here is a related issue: sass/sassc#90. As @xzyfer mentioned, the Ruby entity in this test lifecycle is nothing but a convince at this point, and we can gradually move to C++ based testing framework, I think (and what @mgreter said) with that, we might be able to test more features such as options, source-maps and much more features, which are (not totally, but) unrelated to spec. Having said all that, it would still be functional testing, satelliting the API with sassc (which is more native than throwing in Ruby/Python to the mix), as opposed to Unit test, which shall be more focused the nitty-gritty of implementation itself. Here is my mind-map (not the graphical one 📈 ):
|
8487824
to
318e8fd
Compare
This should avoid inconsistent errors like the one that showed up in PR sass#798.
I agree with @mgreter . I like the intent here but adding a new dependency isn't viable at this point in time. There may very well be internal inconsistencies at times, but that doesn't matter as long as the output is correct for input supplied. All these use cases can and should be covered by sass spec. |
As it stands I think this PR's commits need a tidy up. Two or three well written commits should get the job done whilst preserving appropriate forensic git information. I can assist with this is you need. |
- move quote/unquote to util.cpp - partial merge of upstream changes to inspect.cpp - escape backslash - factor out interpolant fns - correct implementation of next_unescaped_interpolant - ignore Emacs TAGS files - reverse sense of "is unquoted" test
318e8fd
to
c07a7fe
Compare
Squashed down to one commit. I don't think there was anything important in the intervening commits, just add/revert of the new file quote.cpp and add/revert of the unit tests. |