Line numbers from HUnit-Plus / Distribution.TestSuite / stack test failures? - haskell

I'm using HUnit-Plus via stack test, which I believe makes use of Distribution.TestSuite.
When I get compilation errors, I get file paths and line numbers in the error. This is great because I can just click on the error in my editor and jump straight to the relevant code.
Other times there is no compilation error and instead I get output like this:
### Failure in testFoo: expected: 8
This isn't so great, because every time I have to navigate to the relevant test by hand. Also, it is sometimes ambiguous which assertion has failed, and I have to add a string to label the assertion, which becomes repetitious because the string merely repeats in some form the content of the assertion (or else is meaningless). With a line number that wouldn't be a problem.
Is there a way to get this setup to print line numbers and file paths for test failures?

Compilation errors are generated by GHC itself which gives you line numbers, to my knowledge no test suite has this feature, which would be a really nice thing to have though. What I found quite helpful is hspec-expectations-pretty-diff which is a nice diffing output but with no line numbers, I checked it also provides file path and line number!
Also I see some space for improvement for your test cases - usually a test case in my project has a string describing the test - therefore it is rarely ambiguous what test case failed. Also you can use the whole power of haskell to generate this String!

Related

RPLY - Unexpected token parsing source code with multiple lines of code

I'm experimenting with the RPLY library, which by the way looks awesome. However, my parser works fine if my source code has just one line in it. If I add another line of code the parser throws an exception. Anyone else seen this. My parser is pretty basic as the moment, and if I parse each line individually then I have no problem.
My source code looks like this:
MULTIPLY 10 BY 20 GIVING PRICE.
* This is a comment.
as I say, parsing each line separately is no problem.
Any help/pointers greatly received!!!

Antlr4 Testrig runs but I get no output

I am new to ANTLR4. I followed the installation instruction on github and ran the example successfully. So installation appears to be OK. Next I downloaded a grammer file I wish to use, ran antlr4 on it, and compiled the resultant files with javac. Then I tried an example like this:
C:> grun GrammerName tokens examplefile
This runs for a couple of seconds and returns, but there is no response. Ive tried using -tree and -ps but I get nothing with either. If I supply a bad filename, then I get a stream of file-not-found error messages, so it is doing something... but if I supply a random data file, I also get no response. Which suggests to me that my example file is not being seen as a valid example of the grammer in question. But why do I not get an error message?
In essence, my question is how do I get TestRig to supply some feedback about the example file I've supplied?
I've tried reading the manual pages on the antlr.org site but there's too much terminology I'm not familiar with yet.
If you supply tokens as the name of the start rule, that tells grun to not invoke the parser at all and only run the tokenizer. This is generally only useful in combination with the -tokens flag, which prints the tokens. Otherwise the only output you see would be possible tokenization errors.
The options -tree, -ps or -gui display the result of the parser. So if the parser isn't executed, they do nothing at all.
If you want to see the parse tree, you should replace tokens with the name of the rule that you want to use. If you want to see the list of generated tokens, you should add the -tokens flag.
Which suggests to me that my example file is not being seen as a valid example of the grammer in question.
It's the opposite actually. If grun detects errors, it will print them to the console. So if there is no output, grun did not detect any errors (however when using tokens, it will only look for lexical errors, not syntactical ones). When calling grun with valid input and without flags such as -tree or -tokens, the expected result would be that there's no output.

Python3 - "ValueError: not enough values to unpack (expected 3, got 1)"

I'm very new to Python and programming overall, so if I seem to struggle to understand you, please bear with me.
I'm reading "Learn Python 3 the Hard Way", and I'm having trouble with exercise 23.
I copied the code to my text editor and ended up with this:
import sys
script, input_encoding, error = sys.argv
def main(language_file, encoding, errors):
line = language_file.readline()
if line:
print_line(line, encoding, errors)
return main(language_file, encoding, errors)
def print_line(line, encoding, errors):
next_lang = line.strip()
raw_bytes = next_lang.encode(encoding, errors=errors)
cooked_string = raw_bytes.decode(encoding, errors=errors)
print(raw_bytes, "<====>", cooked_string)
languages = open("languages.txt", encoding = "utf-8")
main(languages, input_encoding, error)
When I tried to run it I got the following error message:
Traceback (most recent call last):
File "pag78.py", line 3, in <module>
script, input_encoding, error = sys.argv
ValueError: not enough values to unpack (expected 3, got 1)
which I am having difficulties understanding in this context.
I googled the exercise, to compare it something other than the book page and, if I'm not missing something, I copied it correctly. For example, see this code here for the same exercise.
Obviously something is wrong with this code, and I'm not capable to identify what it is.
Any help would be greatly appreciated.
When you run the program, you have to enter your arguments into the command line. So run the program like this:
python ex23.py utf-8 strict
Copy and paste all of that into your terminal to run the code. This exercise uses argv like others do. It says this in the chapter, just a little bit later. I think you jumped the gun on running the code before you got to the explanation.
Let's record this in an answer for sake of posterity. In short, the immediate problem described lies not as much in the script itself, but rather in how it's being called. No positional argument was given, but two were expected to be assigned to input_encoding and error.
This line:
script, input_encoding, error = sys.argv
Takes (list) of arguments passed to the script. (sys.argv) and unpacks it, that is asigns its items' values to the variables on the left. This assumes number of variables to unpack to corresponds to items count in the list on the right.
sys.argv contains name of the script called and additional arguments passed to it one item each.
This construct is actually very simple way to ensure correct number of expected arguments is provided, even though as such the resulting error is perhaps not the most obvious.
Later on, you certainly should check out argparse for handling of passed arguments. It is comfortable and quite powerful.
I started reading LPTHW a couple of weeks ago. I got the same error as 'micaldras'. The error arises because you have probably clicked the file-link and opened an IEExplorer window. From there, (I guess), you have copied the text into a notepad file and saved. it.
I did that as well and got the same errors. I then downloaded the file directly from the indicated link (right click on the file and choose Save Target As). The saves the file literally as Zed intended and the program now runs.

Excel-VBA: is there a VBA command that reads it's own line number

My Excel 2016 VBA code has rare occasions of fatal errors (e.g. loss of variable or reference values).
It sends mail/text then.
I'm looking for a way to state in which module and code line the problem occurred.
Is there a VBA command that can read the module name and the line number?
...without hard-coding the module and function/sub name.
You can use Erl as long as you have added line numbers to the code.
My idea of best case scenario for emailing fatal errors:
Save all the user's input in a class variable. In case of error, mail the information to yourself plus the type of the error.
This should be enough to replicate and fix.
Concerning a way to get the module name without hardcoding - there is no such way. But using a hardcoded variable for the name is not that difficult - http://www.cpearson.com/excel/InsertProcedureNames.aspx

Handle a bunch of arbitrary literals using Groovy AST Transformation

I read a lot about AST Transformation these days and now I want to handle some arbitrary literals not known by groovy. The specific idea is to enable groovy handling plain sql.
If you write select a from tab where b = 'x' in GroovyConsole, the AST looks like this at some point
MethodCall - this.select(a).from(tab).where((b = x))
With some effort, it should be possible to turn this into a sql-statement.
So everything is fine as long as I don't use an asterisk.
If I write select * from tab no AST can be built (no matter what phase) and an error occures:
Unable to produce AST for this phase due to earlier compilation error:
startup failed:
script123.groovy: 1: expecting EOF, found 'tab' # line1, column 15.
So here's the question:
How can I turn the asterisk into something processable?
I tried to get the CST after parsing was done. But it's always null and I couldn't find out why.
But I found another approach:
http://java.dzone.com/articles/run-your-antlr-dsl-groovy

Resources