Exclude unit test files from build

I make heavy use of unit testing in my project. My code is organized as follows:

project |-- lib | |-- file1.lua | |-- file2.lua | |-- file3.lua +-- spec | |-- file1\_spec.lua | |-- file2\_spec.lua | |-- file3\_spec.lua |-- main.lua

Is there any way I can exclude the spec files from the build? Or rather are they already being excluded when the lua files get converted to byte code cause they are not reachable from the main.lua?

I just want to make sure that I am not having test code in my artifacts.

There is the ability to exclude files by specifing a list in your build.settings file. See:

https://docs.coronalabs.com/guide/distribution/buildSettings/index.html#excluding-files

Rob

@tyrondis,

Rob already answered, but I wanted to say, “Super Awesome Formatting” for a first post.  I wish all users spent the time to write such well formatted, clear, and concise questions.

Thank you, Rob. I already tried that. Problem is, during the build process all lua files are being processed and invisible in the final artifact. Hence I was not able to validate whether they are actually being excluded or have been converted to byte code.

Ha! Thank you for the kind words. I am in the unfortunate position of being a perfectionist, I make everything nice and pretty, otherwise I can’t sleep :wink:

Hmmmm good point. The build process is going to compile the lua files into bytecode and include it in the code bundle. They shouldn’t add much in the way of package weight though. They will end up being pretty small.

You can build a package with the spec folder included, but do not exclude them in the build process and see what size the resulting .app, .ipa or .apk is. Then take the folder out completely and rebuild. That will give you a base line on how expensive they are (included) and if the build.settings exclude is working (removed). Then build again excluding *spec/*" and see if there is a difference.

Rob

Thanks, Rob. I just tested this with an iOS build:

My original .app size was 5,187,341 bytes.

I then added 3,510,000 bytes of spec files.

This resulted in a new app size of 12,139,349 bytes (which seems to be quite significant)

After adding the spec/ folder to the exclude directive, the .app is still 12,139,349 bytes huge (no change)

I confirmed in the Console output that the exclude has been recognized:

Mar 16 10:43:48.821 Excluding spec/spec.1.lua

Mar 16 10:43:48.865 Excluding spec/spec.2.lua

Mar 16 10:43:48.907 Excluding spec/spec.3.lua

It’s weird  that the size went up that much.

Rob

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.

There is the ability to exclude files by specifing a list in your build.settings file. See:

https://docs.coronalabs.com/guide/distribution/buildSettings/index.html#excluding-files

Rob

@tyrondis,

Rob already answered, but I wanted to say, “Super Awesome Formatting” for a first post.  I wish all users spent the time to write such well formatted, clear, and concise questions.

Thank you, Rob. I already tried that. Problem is, during the build process all lua files are being processed and invisible in the final artifact. Hence I was not able to validate whether they are actually being excluded or have been converted to byte code.

Ha! Thank you for the kind words. I am in the unfortunate position of being a perfectionist, I make everything nice and pretty, otherwise I can’t sleep :wink:

Hmmmm good point. The build process is going to compile the lua files into bytecode and include it in the code bundle. They shouldn’t add much in the way of package weight though. They will end up being pretty small.

You can build a package with the spec folder included, but do not exclude them in the build process and see what size the resulting .app, .ipa or .apk is. Then take the folder out completely and rebuild. That will give you a base line on how expensive they are (included) and if the build.settings exclude is working (removed). Then build again excluding *spec/*" and see if there is a difference.

Rob

Thanks, Rob. I just tested this with an iOS build:

My original .app size was 5,187,341 bytes.

I then added 3,510,000 bytes of spec files.

This resulted in a new app size of 12,139,349 bytes (which seems to be quite significant)

After adding the spec/ folder to the exclude directive, the .app is still 12,139,349 bytes huge (no change)

I confirmed in the Console output that the exclude has been recognized:

Mar 16 10:43:48.821 Excluding spec/spec.1.lua

Mar 16 10:43:48.865 Excluding spec/spec.2.lua

Mar 16 10:43:48.907 Excluding spec/spec.3.lua

It’s weird  that the size went up that much.

Rob