Two independent specs seem to interfere. Can someone tell me why? - unit-testing

I have two specs below:
spec/domain/cve/id_spec.cr
spec/domain/cwe/id_spec.cr
Only 'cve' and 'cwe' differ; the others are the same.
When I ran them one by one below,
crystal spec spec/domain/cve/id_spec.cr
crystal spec spec/domain/cwe/id_spec.cr
all examples passed.
However, when I did at a time below,
crystal spec spec/domain/cve/id_spec.cr spec/domain/cwe/id_spec.cr
examples in the 'cve' spec failed.
I've found crystal spec is doubtful, so posted an issue to the GitHub repository.
A set of reproducible minimum codes is in another repository.
The description below is obsolete.
Both Domain::CVE::ID and Domain::CWE::ID have the same methods, which are parse(string) and ==(other).
Did the crystal spec runner misread 'V' and 'W' as humans do? Really?
Now I've replaced the name ID with the fully qualified Domain::CVE::ID, and commented out include Domain::CVE, then I get all the examples passed.
Does someone tell me how to use include and not qualified constants?
The version I've used is:
Crystal 1.6.1 (2022-10-21)
LLVM: 14.0.6
Default target: aarch64-apple-darwin21.6.0
Thank you.

Related

How to enable documentation comments for C++/Qt in VS Code?

Following these instructions, I have already managed to fix the IntelliSense suggestions for my C++ hello world program using Qt headers. So for instance, when I type QString::, the class methods append, arg, etc. are suggested correctly. However, when I choose any of them, I would expect to read a short documentation comment describing what the selected method does do. Unfortunately, this information is not available.
I have also followed this tip and installed qt5-doc on my Ubuntu system, but I have no idea how I can use the .qch documentation files in VS Code. Do you have any pointer for me?

ctwill - mini indexes for cweb (again)

I am looking for ctwill's (literate) source code.
I did not find it in CTAN or through Knuth's page.
The links in this previous question (ftp://ftp.cs.stanford.edu/pub/ctwill/ and ftp://labrea.stanford.edu/pub/ctwill/) don't seem to work. (And the same links appear in this cweb repository, so no luck there either.)
Any help is deeply appreciated!
Actually, the repository for cweb binaries contains the source for ctwill.
The reason why this is not immediately apparent is because of how ctwill is generated. Indeed, it is a modified version of cweave, which is generated from the very source files of cweave using the changefile mechanism devised by Knuth.

How to exclude test paths from cppcheck analysis?

I try to run a cppcheck analysis over my code, which has the following file structure:
/code/module_1/src/a.cpp
/code/module_1/src/b.cpp
/code/module_1/test/c.cpp
/code/module_2/src/d.cpp
/code/module_2/src/e.cpp
/code/module_3/test/f.cpp
I'd like to run an analysis excluding all test code. Is this possible with a command like "cppcheck -itest"? It doesn't work for me, although I think it should, according to the docs:
...Directory name is matched to all parts of the path.
I'm using version 1.69. I know I could mention all test directories separately (which does work, I checked), but the number of modules is too high to do this for many analyses reasonably.
Is this possible?
I installed Cppcheck to do some tests and it seems the -i implementation is a bit bonkers. However, I managed to achieve what you want.
Solution: use -itest\ instead of -itest (this was in Windows; maybe Linux needs -itest/)
Rationale: in my tests, -itest worked only if there was a .\test\ directory, in which case even .\a\test\a.cpp was excluded. With -itest\, however, such exclusion took place regardless of the presence of .\test\ directory.
This seems like a bug which the developers ought to weed out, but, in the meantime, you can succeed using the above workaround.
This is a late response to an old question, but perhaps this will help other latecomers like myself.
Disclaimer: This answer is for Windows.
It seems as if v1.79 has remedied the OP's issue. The following command line syntax has worked for me:
cppcheck -itest code
In this example, "-itest" weeds out any occurrence of the "test" directory, as originally (and correctly) assumed by the OP. In addition, the code folder is found next to the cppcheck.exe. This will be the root of the recursive source-code scan.
I'd use something like:
cppcheck /code/module_1/src /code/module_2/src /code/module_3/src

What does this mean in a Constructor?

I am looking through the PhantomJS source code and I've encountered this line:
Q_PROPERTY(QString frameName READ frameName)
I don't understand how this is correct syntax, it's even missing a semi-colon.
Here is the fine in question on the Github repo, in case you need to sift through it https://github.com/ariya/phantomjs/blob/master/src/webpage.h
It's a macro that the Qt Library defines to have its own Property System. It uses its own macros mainly because of being platform independent (its aim is not to rely on specific compilers/os). I don't think I can add anything not in their reference docs.

Saxon, custom extension element, XTDE:unknown extension instruction

When I tried to use a custom extension element with Saxon, I got an error saying XTDE:unknown extension instruction in my XSL file. I asked this on Saxon mailing list, but haven't yet received a response, so I decided to ask here. In order to be helpful, here is the whole content from the mailing list:
from: sky
I just start using Saxon. After go through some documentations, I still found it hard to write my own custom extension instruction. I have read "writing XSLT extension instructions", and the example provided in the package net.sf.saxon.option.sql. But I'm still a little confusing: the document says,
A subclass of SimpleExpression should implement the methods getImplementationMethod() and getExpressionType(), and depending on the value returned by getImplementationMethod(), should implement one of the methods evaluateItem(), iterate(), or process().
However, there is only call() method implemented in the sql example. I'm new to XML/XSLT, hence find it hard to understand how to write my own extension elements.
Is there a tutorial of some kind which explains writing extension elements in more detail?(I have Google but found no luck, the best I can find is with older Saxon version that has different implementation). Or maybe I should go through some other XML/XSLT intermediate first?
Thanks in advance
from Michael Kay
You're right, implementing extension instructions is not easy. That's partly because the APIs are quite complex, partly because the documentation is poor, and partly because the code that would help you understand it is not open source. The underlying reason for this is that not many people have attempted to do this, so there has been little feedback that would lead to improvement over the years.
I would encourage you to ask yourself seriously whether this is something you really want to do badly enough to cope with the difficulties.
The documentation extract you cite appears to be out of date. The "Callable" interface was a relatively recent addition, and the documentation has not caught up. Implementing the call() method is enough.
Michael Kay
Saxonica
from sky
Thanks for reply.
I'm replacing Xalan with Saxon, so there are extension instructions written for Xalan that need to be rewritten. I think it would be better if I rewrite Xalan extension elements into Saxon extension functions, however, I want to give extension element a try before making the choice. Right now I have a problem with extension element. I tried to write a simple extension element, but it failed to run with "XTDE 1450: Unknown extension instruction". Here is what my code looks like:
//Config.java
ProfessionalConfiguration config = new ProfessionalConfiguration();
config.setExtensionElementNamespace("degx", "DegElementFactory");
//DegElementFactory.java
if(localname.equals("value-of")) return DegxValueOf.class;
//version.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:degx="http://DegElementFactory" extension-element-prefixes="degx">
...
<degx:value-of select="alpha 1"/>
...
</xsl:stylesheet>
I run Config.class first, and then running sf.net.saxon.Transform, I got the error above. My guess is I configured extension element namespace the wrong way. I have Saxon PE with evaluate license install correctly, because I got message about expired days after running Transform.
In summary, I have Config.class, DegElementFactory.class, DegxValueOf.class, all in my working directory, and I have add it to class path through -cp argument. Please help :)
Because I'm using net.sf.saxon.Transform from command line, the configuration class object cease to exist after the execution of Config.class. At first I thought config.setExtensionElementNamespace() would write to a configuration file somewhere. But it turns out wrong. So there are two ways to set extension element namespace:
from command line, supply -config:file argument. e.g.
net.sf.saxon.Transform -config:config.xml -s:source.xml -xsl:transform.xsl -o:result.out
invoking XSLT from application, instance a configuration class and execute setExtensionElementNamespace() method.
#Martin Honnen also pointed out another problem in comment, thanks!