Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary error for buffers containing a main function #4

Closed
nordlow opened this issue Feb 3, 2014 · 4 comments
Closed

Unnecessary error for buffers containing a main function #4

nordlow opened this issue Feb 3, 2014 · 4 comments

Comments

@nordlow
Copy link

nordlow commented Feb 3, 2014

Flags sent to dmd should not contain -main flag if the current buffer contains a D main function.

This will inhibit the unneccessary error message:

3539     error    only one main allowed, -main switch added another main() (d-dmd-unittest)

This is preferrably solved by searching for a regexp matching a D main function definition such as

void main(string args[])

int the current buffer.

Here's a somewhat relaxed Emacs-Lisp regexp that works for me

(defcustom d-main-function-regexp "^\\(?:void\\|int\\)?[[:space:]]*main[[:space:]]*([[:space:]]*string[[:space:]]+"
  "Regexp matching C-style main function.")
@tom-tan
Copy link
Collaborator

tom-tan commented Feb 4, 2014

I think it is not good idea to use original main function for unittest.
The main function may read a string from the standard input.
In that case, the unittest will wait for the user input and it never stops if we use original main.

Instead of that, it is better to enclose main function in version(!unittest) block as described in the document.

import std.stdio;

version(unittest) {}
else
void main()
{
    writeln("Hello!");
}

unittest
{
    assert(1+2 == 3);
}

@tom-tan
Copy link
Collaborator

tom-tan commented Feb 19, 2014

I close this issue because using version(!unittest) is enough to avoid this issue.

@tom-tan tom-tan closed this as completed Feb 19, 2014
@nordlow
Copy link
Author

nordlow commented May 1, 2014

I would still like to have logic that only adds -main flag if d-main-function-regexp does not match contents of current buffer. Where can I most easily inject this without modifying flycheck.el itself?

@tom-tan
Copy link
Collaborator

tom-tan commented May 2, 2014

You can directly modify the arguments by using put function.
Here is the example to remove -main from the arguments of d-dmd-unittest checker.

(let ((checker 'd-dmd-unittest))
  (put checker :flycheck-command
       (remove "-main" (flycheck-checker-arguments checker))))

"Defining new syntax checkers" section in Flycheck website will help you to modify the arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants