Dart library: export a file from the test folder - testing

My library's structure is:
mylib
lib
mylib.dart
src
example.dart
test
utilities.dart
I'd like to export some helper functions I've written in this library so they can be used in the test files of other libraries.
In mylib.dart, which contains exports for the other classes in the library (e.g. export 'src/example.dart';, the following line causes an error:
export '../test/utilities.dart';
The error is:
Target of URI doesn't exist: '../test/utilities.dart'.
It seems I can only export files under the lib folder. I imagine this is a security thing, so I don't go exporting files from just anywhere on my computer.
Is it possible to export a file that contains utility functions for tests, if that file lives under the test folder? Or should I put those utility functions in a file under the lib folder, even though they only pertain to testing, and should only be used in other libraries' tests?

If you have test code that you want to share in tests for other packages, you should put your code in the lib/ directory (or in its own package) and expect that non-testing code would just not bother importing it.
If you have test code that you want to share in tests in the same package, you can leave it in your test/ directory (or in a subdirectory), and test files in test/ can import it via the relative path.

Related

Meson: how to copy subproject file to build directory?

I'm using Meson build system to build a simple executable app.
Problem is: the executable needs to have access to file file.txt which is located in the separate utils repository. The executable app reads this file at runtime and can't work without accessing it.
I have pulled in the utils repository as a Meson subproject, but I am not sure how would I copy the subprojects/utils/file.txt to a builddirdirectory where the executable is built. Currently the app is built without problems, but when I run it, it fails to find file.txt.
How do I copy the subprojects/utils/file.txt to builddir?

How can I precompile multiple vue files in a single library and keep them easily importable?

I have a program with multiple .vue files in src/components. These use typescript and sass. The program uses webpack for compilation and bundling. I would like to add all these components to a single npm package to be used as a library with the following restrictions:
It should be compiled down to javascript and css so whoever imports my library doesn't need my compile dependencies and webpack configuration
The components depend on typescript files. These should also be compiled, but not bundled. They are valid entry points for the library.
The import for the users of the library should be as painless as possible. It would be optimal if the generated js and css could be loaded in a single import, just like importing a .vue file
Is this possible to do? And if so, how? If not, how could I best approximate this or what are my alternatives?
I have tried to use vue-cli-service build --target lib but it seems that can only handle one component, bundles the ts files, and I'm not sure if it behaves like I expect when you import a file.

Why are `__init__.py` and `BUILD` needed inside TensorFlow's `models/tutorials/rnn/translate`?

Inside the tensorflow/models/tutorials/rnn/translate folder, we have a few files including __init__.py and BUILD.
Without __init__.py and BUILD files, the translate script can still manage to run.
What is the purpose of __init__.py and BUILD here? Are we supposed to install or build it using these two files?
The BUILD file supports using Bazel for hermetic building and testing of the model code. In particular a BUILD file is present in that directory to define the integration test translate_test.py and its dependencies, so that we can run it on continuous integration system (e.g. Jenkins).
The __init__.py file causes Python to treat that directory as a package. See this question for a discussion of why __init__.py is often present in a Python source directory. While this file is not strictly necessary to invoke translate.py directly from that directory, it is necessary if we want to import the code from translate.py into a different module.
(Note that when you run a Python binary through Bazel, the build system will automatically generate __init__.py files if they are missing. However, TensorFlow's repositories often have explicit __init__.py files in Python source directories so that you can run the code without invoking Bazel.)

Using Eclipse Palantir TypeScript Plug-in with JSPM

I am using the Palantir Eclipse TypeScript Plug-in (v1.8.0.v20160223-1645), it works fine as long as my d.ts files are in the same source folder /src but due to JSPM they are in another folder and it cannot find and import the modules anymore:
/src <-- My .ts files are here (no js here)
/dist <-- This is where the transpiled js ends up
/jspm_packages/npm <-- External d.ts files are here
In the project TypeScript properties (Eclipse UI), I have:
Source folder(s): src
Exported folders(s): src;jspm_packages/npm
Output folder: dist
Output file name: (nothing here)
So in com.palantir.typescript.prefs there is:
...
build.path.exportedFolder=src; jspm_packages/npm
build.path.sourceFolder=src
compiler.outputDirOption=dist
...
(author of Eclipse TypeScript here) I think you'll want to add jspm_packages/npm to the source folders. You probably don't need the exported folders - those are for exporting things out of a project and only get used in multi-project workspaces where projects depend upon one another.

Something strange with Project Paths in IntelliJ 14.1.4

So, something has started to act weird in my intelliJ project. I even tried removing the iml and .idea data, to no avail.
I go to Project Structure. There, I have a content root. Withing, I have three folders - one for my jar (and jni lib), one for Samples and one for Tools (just tools written to use the jar). The jar, Samples and Tools are marked blue (sources).
In the jar folder, I have my source tree (com\company\projectname\XXX), a lib folder, a folder for my JNI lib and a folder I created call 'junit', which is the focus of this question. It is marked in Project Structure in green (Tests).
Within, I have a folder structure eerily similar to my code: com\company\projectname\junit.
When I open a file in junit\com\company\xxx\junit, I have a big red underline under my package com.company.xxx.junit; line which tells me: "Package name 'com.company.xxx.junit' does not correspond to the file path 'junit.com.company.xxx.junit'.
I was under the impression that marking a folder as 'Tests' would instruct the IDE to use that as a "parent" folder, if you will, eliminating the need to prepend another folder name.
How can I separate the code from unit tests and in fact, create two junit test suites (one is for internal use, the other is a 'skeleton' for distribution), park them under one "umbrella" folder and NOT have to prepend the package names with that folder name?
Update: Project structure:
Based on your screen shot, the issue is that the junit directory is a subdirectory of another source directory, namely MyProvider. A source directory (whether a "production" source or a unit test source directory) cannot be a subdirectory of another source directory.
You need to either:
move the junit directory out of MyProvider so it is a sibling directory, or
unmark MyProvider as a source directory, create a main (or some such directory) in MyProvider, mark it as a source directory, and then move the com directory/package into main.
Option 2 would be the preferred way to deal with this as it follows a very common directory structure standard.
UPDATE (Following comment from OP)
Here's a couple of screenshot showing the configuration you desire:
I removed the .IdeaIC15 folder and started over. Working for now. Something must have gotten confused in the config, either as part of the update, or in the course of operation. I have taken a backup copy as it is now, so if this happens again, I will have something to check.