Question.. I am trying to write a testbox testing ...
# testing
t
Question.. I am trying to write a testbox testing suite that will be based on CFLint results. Has anyone done this already? I hate to reinvent the wheel here.. I am not very familiar with testbox specs, but from what I understand I would need at least one per file that has issues raised by CFLint. I can build all this out be again really don't like doing this the hard way 🙂 Does anyone have some input on this idea?
a
Hang on. Back up a bit.
I am trying to write a testbox testing suite that will be based on CFLint results
Why? What problem are you trying to solve here?
t
lol 😄 I have inherated a large project of old code. the new project is to convert the majority of the code base to fw/1. Did I mention it is very very old code? Anyway our team is working hard to move forward, but I need a way to report if 1) the old code needs to be rewritten and 2) to make sure the new code is written with best practices
a
Fine. And how does testing the results of a cflint run contribute to this?
t
it will help us to understand just how much code still needs attention for one
or is there a better way?
I would love to see 100% test coverage as well but that is another story
a
The only code that needs attn is code you need to change. if the old-style code is working ATM... just leave it be. If there is some feature you need to implement... write tests for it. If there is some feature you need to port from the old codebase to the new one... same... write tests for the new code. I don't see how CFLint figures in any of this as it just checks some code quality rules. It does not speak to whether or not code works, or needs to be migrated or anything like that.
t
true. but our team is just copy/pasting files into the new codebase without doing any testing just to use a single method within the cfc. So I am trying to be politically correct but at the same time trying to enforce some standards
its not that CFLint or CFFormat does any quality checks/ tests for works or not, but does help to make sure code is hopefully in the same standard
a
I still don't get what you're trying to do. But let's say you achieve it. What is one of these tests going to do?
t
and I am the only one writting tests 😞
we use Jenkins, and ideally this would pass off some yes/no to Jenkins and disallow the job if the standards tests fail
the basic idea is to force some standards
a
But... CFLint already - by itself - emits something to the effect of a pass or a fail, doesn't it?
t
well not that general but does give you a count of failures.
cfformat as well
a
The usual approach to enforcing code quality rules is: 2) run the code quality tool as part of the build / deploy process (so: Jenkins runs CFlint) 3) If CFLint exits with a "nope"... fail the build process. Unit test runs play no part in that.
Oh, and 1) get buy in from the team first.
t
gotcha okay that makes since
a
a count of failures
A count of >0 is a failure.
t
CFLint gives you errors, warnings and info counts
depending on the lint rules configured
a
And it runs in a browser yeah? It itself is a CFML "app"?
t
CFLint is a java jar
a
(I had a look at it ages ago... didn't do a very good job of what it set out to do so moved on)
t
theres also a vs code plugin
a
OK, so it runs like
java -jar cflint.jar
or some such.
Which means it will have an exit code. Does it not exit with a non-zero if there are any lint failures?
t
yes, no it uses sdtout. and i built a poc that calls it during a restart and writes out the report files
anyway was hoping someone had done something like this to stop a CI/CD if there is a failure
not stuck on CFLint, just figured that was the most popular
Thanks for the help!!
a
to stop a CI/CD if there is a failure
Yeah this is what I'm working towards with you
👍 1
t
I also have no clue on the Jenkins side, so I was working on this as a POC to hand off to our OPS team
a
You ought to be able to get Jenkins to run something like this:
Copy code
[run cflint] | grep "Total errors: 0" || false
(where
"Total errors: 0"
is a string from the output of the cfflint run that indicates success). That will exit with
0
if it's good, or
1
if it's not. Jenkins will know what to do with that
Naive example:
Copy code
$ echo "Errors: 0" | grep "Errors: 0" || false
Errors: 0
adam@DESKTOP:~ $ echo $?
0
adam@DESKTOP:~ $ echo "Errors: 1" | grep "Errors: 0" || false
adam@DESKTOP:~ $ echo $?
1
t
ahh, very nice.. thank you sir!!
a
(where the
echo
statement is emulating cfflint here)
t
ill just need to help the OPS team get CFLint.jar installed
a
We do the same with our TestBox run, as it only emits text and doesn't do exit codes 😕
This is a pretty common thing to do in a build process
👍 1
(commandbox has a TestBox runner that emits 0 or non-0, but we don't run commandbox)
t
I am locally