EzDevInfo.com

expresso

Clojure library for symbolic computation

How to make balancing group capturing?

Let's say I have this text input.

 tes{}tR{R{abc}aD{mnoR{xyz}}}

I want to extract the ff output:

 R{abc}
 R{xyz}
 D{mnoR{xyz}}
 R{R{abc}aD{mnoR{xyz}}}

Currently, I can only extract what's inside the {}groups using balanced group approach as found in msdn. Here's the pattern:

 ^[^{}]*(((?'Open'{)[^{}]*)+((?'Target-Open'})[^{}]*)+)*(?(Open)(?!))$

Does anyone know how to include the R{} and D{} in the output?


Source: (StackOverflow)

Android UI testing with Expresso: No activities in stage RESUMED

I am currently struggling implementing a functional test on an Android ListActivity that implements a LoaderManager.LoaderCallbacks. This Activity has a simple layout that has an EditText for the user to enter some string, and a ListView that is populated via a Custom CursorAdapter that fetch the data from a Custom Content Provider, and uses the LoadManager to automatically update the list view content when it changes.

The expected functionallity of this ListActivity is only for a User to enter some sting on to the EditText and to select one or more items from the ListView.

To achieve this functional test, I'm using Expresso, and here goes my implementation:

public class NewWordActivityFunctionalTest extends ActivityInstrumentationTestCase2<NewWordActivity>{

    public NewWordActivityFunctionalTest() {
        super(NewWordActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    public void testFillNewThemeFormAndSubmit() throws InterruptedException {
        onView(withId(R.id.submit_new_word_button))
        .perform(click());
    }
}

If I run it, the error stack trace I get is the following:

com.google.android.apps.common.testing.ui.espresso.NoActivityResumedException: No activities in stage RESUMED. Did you forget to launch the activity. (test.getActivity() or similar)?
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:579)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:69)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:40)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:159)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(ViewInteraction.java:90)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform(ViewInteraction.java:73)
at pt.consipere.hangman.ui.test.NewWordActivityFunctionalTest.testFillNewThemeFormAndSubmit(NewWordActivityFunctionalTest.java:36)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)

This test setup is the same I have used in other functional tests of my app that worked perfectly fine, which made me think that the problem may be with the test initialization since the only difference for the other tests is the fact that this activity is using a CursorAdapter and the LoadManager.

If anyone needs more contextualization please ask. Thank you :)


Source: (StackOverflow)

Advertisements

Expresso not installing on Windows 7

Having a problem install Expresso on my machine similar to this

windows 7 x64
node.js version: 0.8.0
npm version: 1.1.32

> npm install expresso
npm http GET https://registry.npmjs.org/expresso
npm http 304 https://registry.npmjs.org/expresso

> expresso@0.9.2 preinstall C:\node_modules\expresso
> make deps/jscoverage/node-jscoverage

make: Interrupt/Exception caught (code = 0xc0000005, addr = 0x0x770843f9)
npm ERR! expresso@0.9.2 preinstall: `make deps/jscoverage/node-jscoverage`
npm ERR! `cmd "/c" "make deps/jscoverage/node-jscoverage"` failed with 255
npm ERR!
npm ERR! Failed at the expresso@0.9.2 preinstall script.
npm ERR! This is most likely a problem with the expresso package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     make deps/jscoverage/node-jscoverage
npm ERR! You can get their info via:
npm ERR!     npm owner ls expresso
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\n
\\npm\\bin\\npm-cli.js" "install" "expresso"
npm ERR! cwd C:\
npm ERR! node -v v0.8.0
npm ERR! npm -v 1.1.32
npm ERR! code ELIFECYCLE
npm ERR! message expresso@0.9.2 preinstall: `make deps/jscoverage/node-jscoverage`
npm ERR! message `cmd "/c" "make deps/jscoverage/node-jscoverage"` failed with 255
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\npm-debug.log
npm ERR! not ok code 0

any help would be greatly appreciated.


Source: (StackOverflow)

How do I get mocha to run "exports"-style tests on Windows?

I have NodeJS and Mocha installed and working on Windows 7 x64 - so far, so good - but I can't get Mocha to recognise any tests defined using the exports interface (as described at http://visionmedia.github.com/mocha/)

If I create test/bdd.js containing the following code:

var should = require('should');

describe('TestDemo - BDD interface', function(){
  describe('#foo', function(){
    it('1 should equal 1', function(){ (1).should.equal(1);  });
  });
});

I can run mocha and get the expected output:

D:\Projects\NodeDemo>mocha -R spec

  TestDemo - BDD interface
    #foo
      ✓ 1 should equal 1

  ✔ 1 tests complete (7ms)

D:\Projects\NodeDemo>

BUT if I create test/exports.js containing this code (based on the 'exports' interface example provided on the Mocha site)

var should = require('should');

module.exports = {
  'TestDemo - exports interface': {
    '#foo': {
      '1 should equal 1': function(){ (1).should.equal(1); }
    }
  }
};

when I run Mocha it doesn't find any tests:

D:\Projects\NodeDemo>mocha -R spec

✔ 0 tests complete (1ms)

D:\Projects\NodeDemo>

I suspect I've either missed a switch or something for specifying which interface mocha should be using for test definitions, or I've found something that isn't supported on Windows (yet). Any ideas?


Source: (StackOverflow)

What's the regex for restricted number of numeric characters?

Having trouble figuring out a regex issue.

We are looking for 2 numbers then hyphen or space then 6 numbers. Must be only 6 numbers, so either an alpha character or some punctuation or space must follow the 6 numbers or the 6 numbers must be at the end of the string.

Other numbers are allowed elsewhere in the string, as long as they are separate.

So, these should match:

foo 12-123456 bar  
12-123456 bar  
foo 12-123456  
foo12-123456bar  
12-123456bar  
foo12-123456  
12-123456bar 99
foo12-123456 99 

These should not match:

123-12345 bar  
foo 12-1234567  
123-12345bar  
foo12-1234567  

Here's what we were using:

\D\d{2}[-|/\ ]\d{6}\D

and in Expresso this was fine.

But running for real in our .net application this pattern was failing to match on examples where the 6 numbers were at the end of the string.

Tried this:

\D\d{2}[-|/\ ]\d{6}[\D|$]

and it still doesn't match

foo 12-123456

Source: (StackOverflow)

Expresso does not find test cases: 'Empty test suite' on Android Studio

I started using JakeWharton's DoubleExpresso library and I was able to set it up as per instructions but unfortunately it's not able to find test cases.

My gradle config looks like this:

androidTestCompile('com.jakewharton.espresso:espresso:1.1-r2') {
    exclude group:'com.google.guava', module:'guava'
}
androidTestCompile('com.jakewharton.espresso:espresso-support-v4:1.1-r2') {
    exclude group:'com.android.support', module:'support-v4'
    exclude group:'com.google.guava', module:'guava'
}

And my test case looks like this (src/androidTest/NavigationTest.java)

public class NavigationTest extends ActivityInstrumentationTestCase2<MainActivity> {

    public NavigationTest() {
        super(MainActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    @SmallTest
    public void testAddition() {
        assertEquals(1 + 1, 2);
    }
}

Any ideas why this test case is not being caught by Expresso?

Update: It works perfectly if I run it on command line, seems like this happens only on Android Studio.


Source: (StackOverflow)

How do I get the code coverage output to display using expresso?

I'm working on getting Expresso set up and some tests running. I followed along with a tutorial on node tuts and have 4 tests running, and passing. Now I'm trying to get a code coverage output to show up when I run the tests, like the docs show. However, I'm sort of lost.

My super basic learning example tests are in a file called test.js in a folder called test:

var Account = require('../lib/account');

require('should');

module.exports = {
    "initial balance should be 0" : function(){
        var account = Account.create();
        account.should.have.property('balance');
        account.balance.should.be.eql(0);
    },

    "crediting account should increase the balance" : function(){
        var account = Account.create();
        account.credit(10);
        account.balance.should.be.eql(10);
    },

    "debiting account should decrease the balance" : function(){
        var account = Account.create();
        account.debit(5);
        account.balance.should.be.eql(-5);
    },

    "transferring from account a to b b should decrease from a and increase b": function(){
        var accountA = Account.create();
        var accountB = Account.create();
        accountA.credit(100);
        accountA.transfer(accountB, 25);
        accountA.balance.should.be.eql(75);
        accountB.balance.should.be.eql(25);
    }
}

And the code itself is in lib/account.js:

var Account = function(){
    this.balance = 0;
}

module.exports.create = function(){
    return new Account();
}

Account.prototype.credit = function(amt){
    this.balance += amt;
}

Account.prototype.debit = function(amt){
    this.balance -= amt;
}

Account.prototype.transfer = function(acct, amt){
    this.debit(amt);
    acct.credit(amt);
}

Account.prototype.empty = function(acct){
    this.debit(this.balance);
}

When I run expresso from the command line, I get:

$ expresso

    100% 4 tests

Likewise, if I run expresso with a -c flag or a variety of other options, I get the same output. I'd like to get the code coverage output shown in the docs. I've also run the command $ node-jscoverage lib lib-cov, and the lib-cov folder has things in it now..

What am I missing?


Source: (StackOverflow)

Rethinkdb with nodejs and expresso

I am trying to use rethinkdb and test it via expresso. I have function

module.exports.setup = function() {
  var deferred = Q.defer();
  r.connect({host: dbConfig.host, port: dbConfig.port }, function (err, connection) {
     if (err) return deferred.reject(err);
     else deferred.resolve();
  });
 return deferred.promise;
});

I am testing it like this

  module.exports = {
    'setup()': function() {
        console.log("in setup rethink");

        db.setup().then(function(){
            console.log(clc.green("Sucsessfully connected to db!"));
        }).catch(function(err){
            console.log('error');
            assert.isNotNull(err, "error");
        });

    }
  };

And I am runing code like this

expresso db.test.js 

But expresso shows error 100% 1 tests even in case of error. I tried to put throw err; in catch, but nothing changes.

But if I put assert.eql(1, 2, "error"); in the begining of setup() it fails as expected;

Is there something, that caches errors? How can I make it fail as it should be? For squalize I found

Sequelize.Promise.onPossiblyUnhandledRejection(function(e, promise) {
    throw e;
});

Is there something like this for rethink db?


Source: (StackOverflow)

How to redirect user to custom form when using Expression Engine with Exp-resso store

Okay so I need a little help here. I have a store running on expression engine with exp-resso store and I need my users to be directed to a custom form based on what product and what modifiers they have selected. once they go through the custom form they will then be placed in the checkout to review their cart.

Is this possible? Can anyone help me please and thank you!

(p.s this site is similar to www.bizfilings.com)


Source: (StackOverflow)

Tests fail in Espresso with devices under Lollipop (failed: Instrumentation run failed due to 'java.lang.IllegalAccessError')

I'm trying to run expresso tests with Spoon in a multidex project. Tests are running without problem in devices/VM with Lollipop or Marshmallow, but they are not working under Lollipop devices.

There are some other questions about this problem in stackoverflow and all solutions talk about avoid duplicates of libraries in the dependencies configuration of Gradle, but I couldn't find them nor the any other problem.

This is the result of make a ./gradlew -q :project:dependencies

_debugAndroidTestApk - ## Internal use, do not manually configure ##
+--- com.android.support.test:runner:0.4.1
|    +--- com.android.support.test:exposed-instrumentation-api-publish:0.4.1
|    \--- junit:junit:4.12
|         \--- org.hamcrest:hamcrest-core:1.3
+--- com.android.support.test:rules:0.4.1
|    \--- com.android.support.test:runner:0.4.1 (*)
+--- com.android.support.test.espresso:espresso-contrib:2.2.1
|    +--- com.android.support.test.espresso:espresso-core:2.2.1
|    |    +--- com.squareup:javawriter:2.1.1
|    |    +--- com.android.support.test:runner:0.4.1 (*)
|    |    +--- com.android.support.test:rules:0.4.1 (*)
|    |    +--- org.hamcrest:hamcrest-library:1.3
|    |    |    \--- org.hamcrest:hamcrest-core:1.3
|    |    +--- org.hamcrest:hamcrest-integration:1.3
|    |    |    \--- org.hamcrest:hamcrest-library:1.3 (*)
|    |    +--- com.google.code.findbugs:jsr305:2.0.1
|    |    +--- javax.annotation:javax.annotation-api:1.2
|    |    +--- com.android.support.test.espresso:espresso-idling-resource:2.2.1
|    |    \--- javax.inject:javax.inject:1
|    \--- com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:2.0
|         \--- org.hamcrest:hamcrest-core:1.3
+--- com.android.support.test.espresso:espresso-core:2.2.1 (*)
+--- com.android.support.test.espresso:espresso-intents:2.2.1
|    \--- com.android.support.test.espresso:espresso-core:2.2.1 (*)
+--- com.android.support:multidex-instrumentation:1.0.1
+--- com.squareup.spoon:spoon-client:1.2.0
\--- project :multidextest
 +--- com.android.support:multidex:1.0.1
 \--- com.android.support.test:runner:0.4.1 (*)

Those are our dependencies:

dependencies {
    compile project(':MemorizingTrustManager')
    compile project(':widgets')
    compile fileTree(dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
    compile "org.igniterealtime.smack:smack-android-extensions:4.1.3"
    compile "org.igniterealtime.smack:smack-experimental:4.1.3"
    compile "org.igniterealtime.smack:smack-tcp:4.1.3"
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.squareup:otto:1.3.7'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'
    compile 'com.google.dagger:dagger:2.0.1'
    apt 'com.google.dagger:dagger-compiler:2.0.1'
    provided 'org.glassfish:javax.annotation:10.0-b28'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.github.pedrovgs:renderers:2.0.3'
    compile 'com.getbase:floatingactionbutton:1.10.0'
    compile 'fr.avianey.com.viewpagerindicator:library:2.4.1@aar'
    compile 'com.google.android.gms:play-services-analytics:8.1.0'
    compile 'com.google.android.gms:play-services-gcm:8.1.0'
    compile "com.mixpanel.android:mixpanel-android:4.6.4"
    compile 'org.apmem.tools:layouts:1.8@aar'
    compile('com.crashlytics.sdk.android:crashlytics:2.3.2@aar') {
        transitive = true;
    }
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-all:1.10.19'
    testCompile 'org.hamcrest:hamcrest-all:1.3'
    androidTestCompile ('com.android.support.test:runner:0.4.1') {
        exclude module: 'support-annotations'
    }
    androidTestCompile ('com.android.support.test:rules:0.4.1') {
        exclude module: 'support-annotations'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1') {
        exclude module: 'support-annotations'
        exclude module: 'support-v4'
        exclude module: 'support-v13'
        exclude module: 'recyclerview-v7'
        exclude group: 'javax.inject'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.1') {
        exclude module: 'support-annotations'
        exclude group: 'javax.inject'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-intents:2.2.1') {
        exclude module: 'support-annotations'
    }
    androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') {
        exclude group: 'com.android.support', module: 'multidex'
    }
    androidTestCompile "com.squareup.spoon:spoon-client:1.2.0"
    androidTestCompile project(':multidextest')
}

And finally the stacktrace with the problem:

11:18:24 D/Device: Uploading file onto device 'emulator-5554'
2015-11-17 11:18:49 [SDR.run] About to actually run tests for [emulator-5554]
11:18:49 I/RemoteAndroidTest: Running am instrument -w -r  -e class com.redbooth.newredbooth.presentation.tests.collaboration.dashboard.DashboardActivityTest com.project.debug.test/com.project.multidextest.MultidexAndroidJUnitRunner on Nexus_One_API_15 [emulator-5554]
11:18:49 I/InstrumentationResultParser: test run failed: 'Instrumentation run failed due to 'java.lang.IllegalAccessError''
2015-11-17 11:18:49 [STRL.testRunStarted] testCount=0 runName=com.project.debug.test
2015-11-17 11:18:49 [STRL.testRunFailed] errorMessage=Instrumentation run failed due to 'java.lang.IllegalAccessError'
2015-11-17 11:18:49 [STRL.testRunEnded] elapsedTime=0
11:18:49 I/XmlResultReporter: XML test result file generated at /Users/disaster/Repositorios/Project/android/project/build/custom-report-dir/debug/junit-reports/emulator-5554.xml. Total tests 0, 
2015-11-17 11:18:50 [SDR.run] About to grab screenshots and prepare output for [emulator-5554]
2015-11-17 11:18:50 [SDR.pullScreenshotsFromDevice] Internal path is /data/data/com.project.debug/app_spoon-screenshots
2015-11-17 11:18:50 [SDR.pullScreenshotsFromDevice] External path is /mnt/sdcard/app_spoon-screenshots
2015-11-17 11:18:50 [SDR.pullScreenshotsFromDevice] Pulling screenshots from external dir on [emulator-5554]
2015-11-17 11:18:50 [SDR.pullScreenshotsFromDevice] Pulling screenshots from internal dir on [emulator-5554]
2015-11-17 11:18:50 [SDR.pullScreenshotsFromDevice] Done pulling screenshots from [emulator-5554]
2015-11-17 11:18:50 [SDR.run] Moving screenshots to the image folder on [emulator-5554]
2015-11-17 11:18:50 [SDR.run] Generating animated gifs for [emulator-5554]
2015-11-17 11:18:50 [SDR.run] Done running for [emulator-5554]
2015-11-17 11:18:50 [SR.runTests] [emulator-5554] Execution done.
:project:spoonDebugAndroidTest FAILED

I invoke the Council of Elrond =_=. Thank you very much for your help.

SOLUTION: I found the solution! http://stackoverflow.com/a/33759357/1147572


Source: (StackOverflow)

Regular Expression for multiple specific-domain email addresses (separated)

Good day,

I'm looking for a regular expression that would validate the following email addresses:

a@domain.com, b@domain.com

So far, I have this:

^([\w+-.%]+@domain\.com,?\s*)+$

It should not return anything in case of:

a@domain.comb@domain.com     or

a@domain.com b@domain.com
  1. It should also return a result if a ; is entered.
  2. Also, is there a way to ensure a result will be returned only when there is a single @ in an address?

Any help would be appreciated.


Source: (StackOverflow)

Having problems with a specific regex statement

I'm trying to write a script for Woofy (tl;dr a program that downloads webcomics), but apparently my regex expression to find the link to the previous page isn't working, according to Expresso. I'm trying to find something along the lines of:

<a rel='nofollow' href="http://70-seas.com/?p=1253" title="Prologue 01" class="previous-comic-link"><span>&lsaquo; Previous</span></a>

that varies with each page, with the URL and title changing to link to whatever the previous page was, with:

<a\srel='nofollow' href="http://70-seas.com/?p=[0-9]{4}"\stitle="[.]*\s[.]*\s([.]*)?"\sclass="previous-comic-link"><span>&lsaquo;\sPrevious</span></a>

(Sometimes the titles have three words, sometimes they have two. They always have numbers as the last word, though.)

Given that I have no prior experience or formal training whatsoever with regex, I have no idea what I'm doing wrong. Any help would be appreciated.


Source: (StackOverflow)

Regular expressions, capture group

This would be the sample text:

<option value="USD">American Samoa, United States Dollar (USD)</option>
<option value="EUR">Andorra, Euro (EUR)</option>
<option value="AOA">Angola, Kwanza (AOA)</option>
<option value="XCD">Anguilla, East Caribbean Dollar (XCD)</option>
<option value="XCD">Antigua and Barbuda, East Caribbean Dollar (XCD)</option>
<option value="ARS">Argentina, Peso (ARS)</option>

This is my try:

<option selected="selected" value="[A-Z]{3}">(?<Test>).+</option>.

The problem is, it only matches the first occurrence it finds. While I want it to get them all. What am I missing in my try?


Source: (StackOverflow)

Node.js test with expresso

I tried to use expresso to test my project. I have installed it with command

sudo npm install --save expresso

and it worked for me. Than I decided to test it in created test.js file with code

var assert = require('assert');
assert.equal(6, 'foobar'.length);

I run it with command expresso ./test.js as was written in example But I have got result

No command 'expresso' found, did you mean:
Command 'extresso' from package 'icoutils' (universe)
Command 'express' from package 'node-express' (universe)
expresso: command not found

Can anyone help me, please? Thank you in advance!


Source: (StackOverflow)

Expresso Test unable to import AndroidJUnit4 and Expresso Test

I have followed the tutorial given in

https://developer.android.com/tools/testing-support-library/index.html#setup

my code is

/* JUnit4 & Espresso */
androidTestCompile 'com.android.support.test:runner:0.3'

// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.3'

// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'

androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'

But I still cant import AndroidJUnit4 class and Expresso Test.

import static android.support.test.espresso.Espresso.onView;

But after until android.support.test.

the expresso library is in red colors

and also the AndroidJUnit4 unable to run.

Anyone know what issue?Thanks a lot


Source: (StackOverflow)