Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing (docs) preserve stack trace #1244

Merged

Conversation

stephenplusplus
Copy link
Contributor

@stephenplusplus stephenplusplus commented Apr 18, 2016

This preserves the original error from the "VM" that runs the examples from our docs.

It also tests each method individually as opposed to testing each file. Each file contains several methods, and if any one of them throws, to help track down the offending line, all of the example code from all of the methods was displayed. It now only displays the code from the example that threw. Additionally, it stops printing the lines from the example that threw after the offending line.

To test, I changed bigquery#createTable to always throw an error: "Must be 7".

Before

  10) documentation should run tests for docs/json/master/bigquery/dataset.json without errors:
     Error:
var gcloud = require('../');

var bigquery = gcloud.bigquery({
  keyFilename: '/path/to/keyfile.json',
  projectId: 'grape-spaceship-123'
});
var dataset = bigquery.dataset('institutions');
dataset.create(function(err, dataset, apiResponse) {
  if (!err) {
    // The dataset was created successfully.
  }
});
dataset.exists(function(err, exists) {});
dataset.get(function(err, dataset, apiResponse) {
  if (!err) {
    // `dataset.metadata` has been populated.
  }
});
dataset.getMetadata(function(err, metadata, apiResponse) {});
var metadata = {
  description: 'Info for every institution in the 2013 IPEDS universe'
};

dataset.setMetadata(metadata, function(err, apiResponse) {});
var tableId = 'institution_data';

var options = {
  // From the data.gov CSV dataset (http://goo.gl/kSE7z6):
  schema: 'UNITID,INSTNM,ADDR,CITY,STABBR,ZIP,FIPS,OBEREG,CHFNM,...'
};

dataset.createTable(tableId, options, function(err, table, apiResponse) {});
dataset.delete(function(err, apiResponse) {});
dataset.delete({ force: true }, function(err, apiResponse) {});
dataset.getTables(function(err, tables, nextQuery, apiResponse) {
  // If `nextQuery` is non-null, there are more results to fetch.
});
dataset.getTables()
  .on('error', console.error)
  .on('data', function(table) {})
  .on('end', function() {
    // All tables have been retrieved
  });
dataset.getTables()
  .on('data', function(table) {
    this.end();
  });

var institutions = dataset.table('institution_data');

must be 7
      at runCodeInSandbox (test/docs.js:37:11)
      at Function._throws (assert.js:306:5)
      at Function.assert.doesNotThrow (assert.js:337:11)
      at Context.<anonymous> (test/docs.js:112:14) 

After

  1) documentation should run tests for bigquery/dataset.js#createTable without errors:

var tableId = 'institution_data';
var options = {
  // From the data.gov CSV dataset (http://goo.gl/kSE7z6):
  schema: 'UNITID,INSTNM,ADDR,CITY,STABBR,ZIP,FIPS,OBEREG,CHFNM,...'
};
dataset.createTable(tableId, options, function(err, table, apiResponse) {});

must be 7
  Error: must be 7
      at Dataset.createTable (lib/bigquery/dataset.js:196:9)
      at assert-code.vm:8:9
      at ContextifyScript.Script.runInNewContext (vm.js:18:15)
      at Object.exports.runInNewContext (vm.js:49:17)
      at runCodeInSandbox (test/docs.js:32:8)
      at Function._throws (assert.js:306:5)
      at Function.assert.doesNotThrow (assert.js:337:11)
      at Context.<anonymous> (test/docs.js:125:16)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 18, 2016
@stephenplusplus
Copy link
Contributor Author

Going to try to add something else in here that might make it more helpful. Please hold!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 14cf805 on stephenplusplus:spp--doc-test-stacktrace into c6d6bc3 on GoogleCloudPlatform:master.

@stephenplusplus stephenplusplus force-pushed the spp--doc-test-stacktrace branch from 14cf805 to 32fd3f1 Compare April 18, 2016 20:48
@stephenplusplus stephenplusplus force-pushed the spp--doc-test-stacktrace branch 2 times, most recently from 21bbcc7 to 7e858c8 Compare April 19, 2016 12:01
@stephenplusplus stephenplusplus force-pushed the spp--doc-test-stacktrace branch from 7e858c8 to 7d386a1 Compare April 19, 2016 12:04
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 7d386a1 on stephenplusplus:spp--doc-test-stacktrace into ccc8dcf on GoogleCloudPlatform:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 7d386a1 on stephenplusplus:spp--doc-test-stacktrace into ccc8dcf on GoogleCloudPlatform:master.

@callmehiphop callmehiphop merged commit 55aeb1f into googleapis:master Apr 19, 2016
@callmehiphop
Copy link
Contributor

So goood!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants