Maybe a bug compiling with warn_missing_spec option

Hey all.

I have a question about the warn_missing_spec compiler option.
Compiling this module

-module(maybe_a_bug).
-compile(warn_missing_spec).

-ifdef(TEST).

-include_lib("eunit/include/eunit.hrl").

maybe_a_bug_test() ->
    ok.

-endif.

this is the output

erlc maybe_a_bug.erl 
maybe_a_bug.erl:0: Warning: missing specification for function test/0
maybe_a_bug.erl:8:1: Warning: missing specification for function maybe_a_bug_test/0
%    8| maybe_a_bug_test() ->
%     | ^

Why the TEST macro is ignored? Shouldn’t it be no warning in this case?
The same for warn_missing_spec_all.

1 Like

I get no warnings (as expected) when I compile this module with either OTP 25 or OTP 26.

Have you set the environment variable ERL_COMPILER_OPTIONS? If I set it like this:

export ERL_COMPILER_OPTIONS="[{d,'TEST'}]"

I get the same warnings as you did.

1 Like

I have no ERL_COMPILER_OPTIONS defined.

# rebar3 / erlang
export PATH=~/.cache/rebar3/bin:$PATH

# erlang
export ERL_LIBS="/home/williamthome/.asdf/installs/erlang/25.3.2/lib"
export ERL_AFLAGS="-kernel shell_history enabled"
erl
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Eshell V13.2.2  (abort with ^G)
1> os:getenv("ERL_COMPILER_OPTIONS").
false

My OS:

cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS"

I enabled this option on this repo: GitHub - williamthome/changeset: An OTP library to validate data based on Ecto changeset library (Elixir).
and the job is falling: chore: set warn_missing_spec compiler option · williamthome/changeset@18056f5 · GitHub

Run rebar3 do eunit, ct
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling changeset
===> Compiling src/validators/changeset_is_boolean_validator.erl failed
src/validators/changeset_is_boolean_validator.erl:0: missing specification for function test/0
src/validators/changeset_is_boolean_validator.erl:33:1: missing specification for function validate_change_test/0

Error: Process completed with exit code 1.

Am I making some mistakes here?

1 Like

using rebar3 as eunit… defines TEST. See the documentation:

4 Likes

Ohh, how I missed that, this makes total sense.
So, I cannot use this option using eunit?
I will try moving all tests to a test folder. Maybe these warnings will go away.

1 Like

But wait, this makes sense in the repo that I mention, but does not make sense in my example that I simply compile using erlc and receive the same result:

1 Like

that’s strange. I don’t get any warning compiling with erlc maybe_a_bug.erl. What does compile:env_compiler_options(). return?

1> compile:env_compiler_options().
[]
1 Like

Strange, is the same

1> compile:env_compiler_options().
[]
1 Like

My appologies, I see my error, I was compiling it with the include outside the ifdef attribute:

-module(maybe_a_bug).
-compile(warn_missing_spec).

-include_lib("eunit/include/eunit.hrl").

-ifdef(TEST).

maybe_a_bug_test() ->
    ok.

-endif.

I’m sorry for this mistake.

2 Likes