Exclude unit test files from build

So, should I file this as a bug and/or create a feature request?

I’d say make it a feature request.  http://feedback.coronalabs.com

Thanks

Done: http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/13064880-exclude-lua-files-e-g-unit-tests-from-build

The perfect Corona Forums question would include which platform are you building for and what version of CoronaSDK are you using :slight_smile:

excludeFiles operates after all the .lua files in the project have been compiled.  It isn’t practical to determine whether any given file is referenced from main.lua.

If you really want to keep them in your project, I would recommend changing the .lua extension on your “spec” files and excluding those filenames (if you’re running them with the lua command line tool you can use any extension you want, e.g. .luaspec ).  

The scope for confusion that allowing the exclusion of .lua files from a build would provide is immense and I doubt we’ll ever offer that feature.

If you are using the spec files in a “test mode” of the Corona project (rather than running them on the command line), you can change their extensions (to, say, .luaspec ) and in the code that requires them to something like this which adjusts the filetypes the require directive looks for:

local resourceDir = system.pathForFile(nil, system.ResourceDirectory) package.path = resourceDir .. "/" .. "?.luaspec;" .. package.path local file1spec = require("spec.file1\_spec")

package.path is documented in the Lua 5.1 Manual and note that “/” in **require()**s has to be specified as “.”

Thanks, Perry. Yeah I can totally hack around it. I could also delete the specs/ folder before requesting a Corona build. I was just wondering whether Corona already provides functionality for such a use case and/or plans to add it. Traditionally, game developers do not care so much for unit testing (which they should imo), maybe it would encourage aspiring developers if Corona would support them in that endeavor.

I’m not 100% sure I’m clear on what you’re getting at but if I understand you correctly …

I don’t think making it possible to inject doubt as to which .lua files in the project will be included in the app is a good idea.  

I think we’ve provided a couple of suggestions for those who are keen to include Lua code that is not part of the app in the project directory and I’m sure there are other ways to do it.

Sorry to resurrect an old thread, but I just ran into this issue myself.

I tried to exclude an entire folder, saw that the code was still being included in my app, and spent the next 2 hours debugging and trying to figure out why. I thought maybe something was wrong with the patterns I was trying to match. If I choose to exclude an entire directory then it makes sense to expect the lua files within that directory to be excluded as well, right?

The fact that exclusion ignores lua files should be added to the documentation and probably this tutorial too. It might save a few headaches down the road. But to be honest, I don’t see why exclusion can’t work on lua files. The documentation already warns that it might be too agressive and to check your bundle carefully (and presumably you should be testing your build anyway before submitting to the store).

The suggestion to rename file extensions is not ideal because it breaks the syntax highlighting features in my IDE (ZeroBrane). For now, the workaround that I have to use is renaming the folder that I want to exclude by prefixing it with a “.”. As far as I know, this is not documented either and I had to find the answer in a 3 year old forum thread. Using the dot prefix also might not be ideal for Windows users.

Hi Vince_,

glad I am not the only one! :slight_smile:

Please vote for this feature request, if you haven’t already:

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/13064880-exclude-lua-files-e-g-unit-tests-from-build

This is how I am solving it currently:

I copy all files that are relevant to Corona (excluding unit tests, build scripts etc.) into a build folder and then start the Corona build process from there.

Hope that helps!

Voted :slight_smile:

> The suggestion to rename file extensions is not ideal because it breaks the syntax highlighting features in my IDE (ZeroBrane).

@Vince_, you should still be able to use Lua syntax with files with arbitrary extensions. Try adding something like this to the config file (Edit | Preferences | Settings: User):

local luaspec = ide.specs.lua
luaspec.exts[#luaspec.exts+1] = “luaz”
 

Now you should be able to use files with “luaz” extension the same way you use Lua files. See this link for example. Paul.

 

@Paul, this is awesome. I love how configurable ZeroBrane is. Thanks for the tip!

Sorry to resurrect an old thread, but I just ran into this issue myself.

I tried to exclude an entire folder, saw that the code was still being included in my app, and spent the next 2 hours debugging and trying to figure out why. I thought maybe something was wrong with the patterns I was trying to match. If I choose to exclude an entire directory then it makes sense to expect the lua files within that directory to be excluded as well, right?

The fact that exclusion ignores lua files should be added to the documentation and probably this tutorial too. It might save a few headaches down the road. But to be honest, I don’t see why exclusion can’t work on lua files. The documentation already warns that it might be too agressive and to check your bundle carefully (and presumably you should be testing your build anyway before submitting to the store).

The suggestion to rename file extensions is not ideal because it breaks the syntax highlighting features in my IDE (ZeroBrane). For now, the workaround that I have to use is renaming the folder that I want to exclude by prefixing it with a “.”. As far as I know, this is not documented either and I had to find the answer in a 3 year old forum thread. Using the dot prefix also might not be ideal for Windows users.

Hi Vince_,

glad I am not the only one! :slight_smile:

Please vote for this feature request, if you haven’t already:

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/13064880-exclude-lua-files-e-g-unit-tests-from-build

This is how I am solving it currently:

I copy all files that are relevant to Corona (excluding unit tests, build scripts etc.) into a build folder and then start the Corona build process from there.

Hope that helps!

Voted :slight_smile:

> The suggestion to rename file extensions is not ideal because it breaks the syntax highlighting features in my IDE (ZeroBrane).

@Vince_, you should still be able to use Lua syntax with files with arbitrary extensions. Try adding something like this to the config file (Edit | Preferences | Settings: User):

local luaspec = ide.specs.lua
luaspec.exts[#luaspec.exts+1] = “luaz”
 

Now you should be able to use files with “luaz” extension the same way you use Lua files. See this link for example. Paul.

 

@Paul, this is awesome. I love how configurable ZeroBrane is. Thanks for the tip!