1

We often have comments in our code review that tells people to remove their @tag from tests they had tagged to have a tighter iteration loop. However, I think that is a waste to have depend on humans to make those comments.

Is there some option for mix test, credo or some other tool that exists to detect @tag in tests?

CallMeNorm
  • 2,299
  • 1
  • 16
  • 23
  • I would start this exploration by first identifying with objective evidence (i.e. a profiler) that the tags are really causing performance problems. I suspect they have no impact at all. – Robert Harvey Mar 20 '19 at 20:40
  • It's not performance that I care about, it's the noise. Having the tests littered with tags is like having your code littered with one line useless comments. That's obviously subjective, but it's definitely how I feel. – CallMeNorm Mar 20 '19 at 20:41
  • You have to decide which cost is greater: the noise introduced by the @tags or the labor involved in removing them. – Robert Harvey Mar 20 '19 at 20:42

1 Answers1

2

You can try this bash spell:

! grep -R --include="*.exs" "@tag" test

It basically greps for all instances of the pattern @tag in the directory test (because of the -R). The ! negates the exit code, so it succeeds when grep finds nothing and fails if it finds something. Most CIs should fail when any command in the script fails, so this might suit your bill.

Paweł Obrok
  • 22,568
  • 8
  • 74
  • 70
  • That's dope. I ended up doing something very similar. ` function check_for_tags { tags=\`rg "@tag" -g apps/**/*.exs | wc | awk '{print $1}'\` if [ $tags -ne "0" ]; then echo "Your tests contain tags" return 1; fi return 0; } ` – CallMeNorm Mar 21 '19 at 07:46
  • 3
    @CallMeNorm then please mark this answer as solving the issue. – Aleksei Matiushkin Mar 21 '19 at 08:39