Accessing locally created subprogram inside package in Ada - ada

Can anyone please let me know, how to get access to locally created subprogram inside package in order to test the locally created subprogram independently using GNATest (Aunit), instead of integrating locally created subprogram in called function/procedure.

If the subprogram you want to test is declared in the private part of the spec, you could create a special test-only child package to give access to it (or maybe to contain the tests?)

Related

How to build sqlite VFS into the library

I am trying to compile SQLite into a library which another application is then going to link against. I am not able to compile SQLite directly into that application for reasons which are beyond the scope of this question.
However, I need a VFS to be available which by default is not. In trying to figure out how to get this working I am trying to get the vfstrace shim to be made available to the application which is linking to SQLite. This will easily prove that it is working as I can log SQLite VFS activity from the shim and see that it is actually being used when the application calls SQLite.
How do I do this? All the examples I have found show the case of when you have a source file (such as shell.c) and you compile it, sqlite3.c and test_vfstrace.c to produce an executable. However, I do not have this luxury. I could compile sqlite.c and test_vfstrace.c and generate the libsqlite3.so library file, but there is no "main" function in which to call vfstrace_register so that the VFS is actually available. Is there some other hook for the library case where I can set this up? If no, how do I make a new VFS available?
SQLite is initialized via the sqlite3_initialize() function, which is called automatically when various functions such as sqlite3_open() are called by the user, although it is a no-op on subsequent invocations. This function in turn calls the OS specific initialization function sqlite3_os_init(). This is the function that initializes all the VFSes that are built into SQLite.
For the example VFS given, append test_vfstrace.c to the amalgamation and then put a call like this in sqlite3_os_init() right before the return statement:
vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1);
Then build the library with these modifications.
The last parameter's value of 1 will make this VFS be the default, so if you don't want trace messages printed for every SQLite operation performed via code linked the library you just created change this to 0 and explicitly specify this VFS when opening a database to trace the calls for. For instance, specify the SQLITE_USE_URI compile time option, and then pass a filename of the form: "file:database.db?vfs=unix" where "database.db" is the actual name of the file to open.

Use of gettext in a Shiny application

I noticed a strange behaviour of gettext in a Shiny application running on an Ubuntu 14.04 machine.
From ?gettext, we learn that:
If domain is NULL or "", and gettext or ngettext is called from a function in the namespace of package pkg the domain is set to "R-pkg".
But when I develop a package using gettext to perform the internationalization in an associated Shiny app, messages are not always translated.
I have developed a small reproducible example that you can find at Github :
devtools::install_github("tutuchan/gettext")
It is a very simple package with three functions:
hello() calls gettext("Hello, world!"), implicitly specifying the domain as R-gettext,
hello2() calls gettext("Hello, world!", domain = "R-gettext"), explicitly specifying the domain as R-gettext,
app() is a wrapper around shiny::runApp() to launch the app directly
The package includes the .po file for a French translation (which requires you to have a "fr_FR.UTF8" locale on your system to try it out).
If I call app(), both strings are translated:
But if I run the app directly, either by opening the file and clicking the Run App button in RStudio or by calling shiny::runApp("inst/app"), only the message with the domain called explicitly is translated:
I may have misunderstood the help from gettext but I'd be glad if anyone could shed some light on this.
Does gettext consider the top-level calling function when trying to match the domain ? Because in that case, it would make sense that when calling app(), all messages are translated while when calling shiny::runApp(), only those with explicit domains are translated (because for implicit domains, gettext would look for .po files in the namespace of the shiny package).
But I figured it would look for the domain of the function actually calling gettext.
It looks like gettext looks indeed in the namespace of the toplevel function for translation files when the domain is not specified.
I created another package that contains translation files and calls the app from my gettext package. When gettextpo::app() is called (which calls gettext::app() internally, the translation when the domain is implicit is found in the namespace of the gettextpo package, and not gettext.

What's a safe way to define Meteor server methods for use only in tests?

I want the methods to be available only for tests, and not in application code. For example, a method to delete any user. I don't want this capability in production code. But it's helpful in test code.
How would I add provide such a method in a test context while keeping it out of production code?
Here's one possible solution:
Let's assume you create a package called test-helpers. In it, you create a function called removeAllUsers in the TestHelpers namespace.
Now in another package that needs TestHelpers.removeAllUsers, you can just do this:
Package.onTest(function(api) {
api.use('TestHelpers', 'server');
});
Because we only included the package in onTest, it won't exist in your production code. Furthermore, we created a server-only function (not a method), so even if it did get exposed in production, it couldn't be called from a client.

Host TimeLineJS on Meteor app without smart package

I'd like to host the TimeLineJS library on my Meteor app locally and not use the smart package because I need to fine tune it. I've tried declaring the createStoryJS function in the Meteor space like this in create Timeline.js. However, there are other dependencies (storyjs-embed.js, storyjs-embed-generator.js, storyjs-embed.js, and everything under locale) which rely on the document object on the browser. How can I ensure that Timeline.js is loaded in a template with all of its dependencies locally managed, while successfully accessing the window.document object?
Put all the files in client/compatibility in your app, such that the dependencies load first via Meteor’s load order (e.g. put dependencies in client/compatibility/lib, for example). That’s all you have to do: no script tags, no declaring anything. Initialize TimeLineJS within a template’s onRendered callback.

Where do I properly put my constants in Meteor

I usually follow the unofficial Meteor FAQ on how to structure my codebase, but I can't figure out where I should put my global constants.
To give an example: I have some database entries with a constant GUID that I need to reference in many points of my app. So far I just attached the constants to the relevant collection, such that in collections/myCollectionWithGuids.coffee it would say:
#MyCollectionWithGuids = new Meteor.Collection "myCollectionWithGuids"
#MyCollectionWithGuids.CONSTANT_ID = "8e7c2fe3-6644-42ea-b114-df8c5211b842"
This approach worked fine, until I need to use it in the following snippet, located in client/views/myCollectionWithGuidsView.coffee, where it says:
Session.setDefault "selectedOption", MyCollectionWithGuids.CONSTANT_ID
...which is unavailable because the file is being loaded before the Collections are created.
So where should I put my constants then, such that they are always loaded first without hacking in a bunch of subdirectories?
You could rely on the fact that a directory names lib is always treated first when it comes to load order.
So I would probably advise you to organize your code as follow :
lib/collections/collection.js
client/views/view.js
In your particular use case this is going to be okay, but you might find cases when you have to use lib in your client directory as well and as the load order rules stack (subdirectories being loaded first), it will be loaded BEFORE the lib folder residing in your project root.
For the moment, the only way to have full control over the load order is to rely on the package API, so you would have to make your piece of code a local package of your app (living in the packages directory of your project root).
It makes sense because you seem to have a collection and a view somehow related, plus splicing your project into a bunch of collaborative local packages tends to be an elegant design pattern after all.
Creating a local package is really easy now that Meteor 0.9 provide documentation for the package.js API.
http://docs.meteor.com/#packagejs
I would put your collection definitions in a lib directory. File structure documentation explains that all files under the lib directory get loaded before any other files, which means your variable would be defined when you attempt to access it in your client-side code.
Generally speaking, you always want your collections to be defined before anything else in your application is loaded or executed, since your application will most likely heavily depend upon the use of the collection's cursor.

Resources