Discussion:
[dart-misc] running tests with pub
Daniel Davidson
2016-01-01 20:53:05 UTC
Permalink
I've been using test package for a while and I run tests on drone by
invoking the scripts directly.
Some of my tests need to write files into the current directory and then
clean them up.

This line:

String root = dirname(dirname(absolute(Platform.script.toFilePath())));

gets the path of the root of the package. This fails when run via pub.
It seems the Platform.script.toFilePath() does not really resolve to a path
when run using pub test, but works fine when running test script with dart.

What is the workaourd?

Thanks
Dan
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Günter Zöchbauer
2016-01-01 22:14:10 UTC
Permalink
I think this is still work in progress and caused by Dart VM limitations.
I think http://stackoverflow.com/questions/30214563/get-current-script-path-or-current-project-path-using-new-test-runner should provide some more information (didn't check in detail).
I've been using test package for a while and I run tests on drone by invoking the scripts directly.
Some of my tests need to write files into the current directory and then clean them up.
  String root = dirname(dirname(absolute(Platform.script.toFilePath())));
gets the path of the root of the package. This fails when run via pub. 
It seems the Platform.script.toFilePath() does not really resolve to a path when run using pub test, but works fine when running test script with dart.
What is the workaourd?
Thanks
Dan
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
'Bob Nystrom' via Dart Misc
2016-01-04 17:11:26 UTC
Permalink
Ugh, yeah, this is way harder than it should be for a variety of reasons.
If this is just for tests, you can use mirrors, which is what I do to
address this in dart_style
<https://github.com/dart-lang/dart_style/blob/master/test/formatter_test.dart#L137-L142>
:

// Locate the "test" directory. Use mirrors so that this works with the
test
// package, which loads this suite into an isolate.
var testDir = p.dirname(currentMirrorSystem()
.findLibrary(#dart_style.test.formatter_test)
.uri
.path);

This works if you run the test suite directly in the VM or if you run it
through pub run test. I'm not sure about Drone.

Cheers!

– bob
Post by Günter Zöchbauer
I think this is still work in progress and caused by Dart VM limitations.
I think
http://stackoverflow.com/questions/30214563/get-current-script-path-or-current-project-path-using-new-test-runner
should provide some more information (didn't check in detail).
Post by Daniel Davidson
I've been using test package for a while and I run tests on drone by
invoking the scripts directly.
Post by Daniel Davidson
Some of my tests need to write files into the current directory and then
clean them up.
Post by Daniel Davidson
String root = dirname(dirname(absolute(Platform.script.toFilePath())));
gets the path of the root of the package. This fails when run via pub.
It seems the Platform.script.toFilePath() does not really resolve to a
path when run using pub test, but works fine when running test script with
dart.
Post by Daniel Davidson
What is the workaourd?
Thanks
Dan
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Daniel Davidson
2016-01-04 17:25:20 UTC
Permalink
Thanks. I'm ok, I mainly needed to get test working for CI. I was switching
from drone to travis since travis seems to be keeping up with sdk versions.
In the process I thought I'd try out the pub test approach used by kevmoo's
projects.
But, for this case it won't work, so I'll just go back to invoking dart
directly to test.
Post by 'Bob Nystrom' via Dart Misc
Ugh, yeah, this is way harder than it should be for a variety of reasons.
If this is just for tests, you can use mirrors, which is what I do to
address this in dart_style
<https://github.com/dart-lang/dart_style/blob/master/test/formatter_test.dart#L137-L142>
// Locate the "test" directory. Use mirrors so that this works with the
test
// package, which loads this suite into an isolate.
var testDir = p.dirname(currentMirrorSystem()
.findLibrary(#dart_style.test.formatter_test)
.uri
.path);
This works if you run the test suite directly in the VM or if you run it
through pub run test. I'm not sure about Drone.
Cheers!
– bob
Post by Günter Zöchbauer
I think this is still work in progress and caused by Dart VM limitations.
I think
http://stackoverflow.com/questions/30214563/get-current-script-path-or-current-project-path-using-new-test-runner
should provide some more information (didn't check in detail).
Post by Daniel Davidson
I've been using test package for a while and I run tests on drone by
invoking the scripts directly.
Post by Daniel Davidson
Some of my tests need to write files into the current directory and
then clean them up.
Post by Daniel Davidson
String root =
dirname(dirname(absolute(Platform.script.toFilePath())));
Post by Daniel Davidson
gets the path of the root of the package. This fails when run via pub.
It seems the Platform.script.toFilePath() does not really resolve to a
path when run using pub test, but works fine when running test script with
dart.
Post by Daniel Davidson
What is the workaourd?
Thanks
Dan
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Continue reading on narkive:
Loading...