From the man page for getopt_long
The last element of the longopts array has to be filled with zeroes.
So what you need is another line
struct option long_options[] = {
{ "test", required_argument, 0, 't' },
{ 0 } // this line is new
};
I suspected this was the case because I looked at your code and asked, "how does getopt_long know how many elements is in the array". man page confirmed.