aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-doc
diff options
context:
space:
mode:
authorF. Eugene Aumson <gene@aumson.org>2018-09-14 01:05:01 +0800
committerF. Eugene Aumson <gene@aumson.org>2018-09-18 05:49:03 +0800
commitd5f964b58e755ccf1e63a61a97da1c161cf22b22 (patch)
treecd8b738e702eb7fae7686c5873d032a998541926 /packages/sol-doc
parentcbb5a425dfb45d1dfda3579548d6b3f70dfca166 (diff)
downloaddexon-sol-tools-d5f964b58e755ccf1e63a61a97da1c161cf22b22.tar
dexon-sol-tools-d5f964b58e755ccf1e63a61a97da1c161cf22b22.tar.gz
dexon-sol-tools-d5f964b58e755ccf1e63a61a97da1c161cf22b22.tar.bz2
dexon-sol-tools-d5f964b58e755ccf1e63a61a97da1c161cf22b22.tar.lz
dexon-sol-tools-d5f964b58e755ccf1e63a61a97da1c161cf22b22.tar.xz
dexon-sol-tools-d5f964b58e755ccf1e63a61a97da1c161cf22b22.tar.zst
dexon-sol-tools-d5f964b58e755ccf1e63a61a97da1c161cf22b22.zip
test w/&w/out passing in `contractsToCompile`
Diffstat (limited to 'packages/sol-doc')
-rw-r--r--packages/sol-doc/src/solidity_doc_generator.ts8
-rw-r--r--packages/sol-doc/test/solidity_doc_generator_test.ts127
2 files changed, 76 insertions, 59 deletions
diff --git a/packages/sol-doc/src/solidity_doc_generator.ts b/packages/sol-doc/src/solidity_doc_generator.ts
index a1ef32e79..513468803 100644
--- a/packages/sol-doc/src/solidity_doc_generator.ts
+++ b/packages/sol-doc/src/solidity_doc_generator.ts
@@ -30,12 +30,12 @@ import {
* @return doc object for use with documentation generation tools.
*/
export async function generateSolDocAsync(
- contractsToCompile: string[],
contractsDir: string,
+ contractsToCompile?: string[],
): Promise<DocAgnosticFormat> {
const doc: DocAgnosticFormat = {};
- const compilerOptions = _makeCompilerOptions(contractsToCompile, contractsDir);
+ const compilerOptions = _makeCompilerOptions(contractsDir, contractsToCompile);
const compiler = new Compiler(compilerOptions);
const compilerOutputs = await compiler.getCompilerOutputsAsync();
for (const compilerOutput of compilerOutputs) {
@@ -57,7 +57,7 @@ export async function generateSolDocAsync(
return doc;
}
-function _makeCompilerOptions(contractsToCompile: string[], contractsDir: string): CompilerOptions {
+function _makeCompilerOptions(contractsDir: string, contractsToCompile?: string[]): CompilerOptions {
const compilerOptions: CompilerOptions = {
contractsDir,
contracts: '*',
@@ -70,7 +70,7 @@ function _makeCompilerOptions(contractsToCompile: string[], contractsDir: string
},
};
- const shouldOverrideCatchAllContractsConfig = !_.isUndefined(contractsToCompile);
+ const shouldOverrideCatchAllContractsConfig = !_.isUndefined(contractsToCompile) && contractsToCompile.length > 0;
if (shouldOverrideCatchAllContractsConfig) {
compilerOptions.contracts = contractsToCompile;
}
diff --git a/packages/sol-doc/test/solidity_doc_generator_test.ts b/packages/sol-doc/test/solidity_doc_generator_test.ts
index 7f11fcdfd..b71cce6e7 100644
--- a/packages/sol-doc/test/solidity_doc_generator_test.ts
+++ b/packages/sol-doc/test/solidity_doc_generator_test.ts
@@ -3,7 +3,7 @@ import * as _ from 'lodash';
import * as chai from 'chai';
import 'mocha';
-import { SolidityMethod } from '@0xproject/types';
+import { DocAgnosticFormat, SolidityMethod } from '@0xproject/types';
import { generateSolDocAsync } from '../src/solidity_doc_generator';
@@ -12,65 +12,82 @@ import { chaiSetup } from './util/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
-describe('#SolidityDocGenerator', () => {
- it('should generate a doc object that matches the TokenTransferProxy fixture', async () => {
- const doc = await generateSolDocAsync(['TokenTransferProxy'], `${__dirname}/../../test/fixtures/contracts`);
+describe('#SolidityDocGenerator', async () => {
+ const docPromises: Array<Promise<DocAgnosticFormat>> = [
+ generateSolDocAsync(`${__dirname}/../../test/fixtures/contracts`),
+ generateSolDocAsync(`${__dirname}/../../test/fixtures/contracts`, []),
+ generateSolDocAsync(`${__dirname}/../../test/fixtures/contracts`, ['TokenTransferProxy']),
+ ];
+ docPromises.forEach(docPromise => {
+ it('should generate a doc object that matches the TokenTransferProxy fixture', async () => {
+ const doc = await docPromise;
+ expect(doc).to.not.be.undefined();
- expect(doc).to.not.be.undefined();
-
- const tokenTransferProxyConstructorCount = 0;
- const tokenTransferProxyMethodCount = 8;
- const tokenTransferProxyEventCount = 3;
- expect(doc.TokenTransferProxy.constructors.length).to.equal(tokenTransferProxyConstructorCount);
- expect(doc.TokenTransferProxy.methods.length).to.equal(tokenTransferProxyMethodCount);
- if (_.isUndefined(doc.TokenTransferProxy.events)) {
- throw new Error('events should never be undefined');
- }
- expect(doc.TokenTransferProxy.events.length).to.equal(tokenTransferProxyEventCount);
+ expect(doc.TokenTransferProxy).to.not.be.undefined();
+ expect(doc.TokenTransferProxy.constructors).to.not.be.undefined();
+ const tokenTransferProxyConstructorCount = 0;
+ const tokenTransferProxyMethodCount = 8;
+ const tokenTransferProxyEventCount = 3;
+ expect(doc.TokenTransferProxy.constructors.length).to.equal(tokenTransferProxyConstructorCount);
+ expect(doc.TokenTransferProxy.methods.length).to.equal(tokenTransferProxyMethodCount);
+ if (_.isUndefined(doc.TokenTransferProxy.events)) {
+ throw new Error('events should never be undefined');
+ }
+ expect(doc.TokenTransferProxy.events.length).to.equal(tokenTransferProxyEventCount);
- const ownableConstructorCount = 1;
- const ownableMethodCount = 2;
- const ownableEventCount = 1;
- expect(doc.Ownable.constructors.length).to.equal(ownableConstructorCount);
- expect(doc.Ownable.methods.length).to.equal(ownableMethodCount);
- if (_.isUndefined(doc.Ownable.events)) {
- throw new Error('events should never be undefined');
- }
- expect(doc.Ownable.events.length).to.equal(ownableEventCount);
+ expect(doc.Ownable).to.not.be.undefined();
+ expect(doc.Ownable.constructors).to.not.be.undefined();
+ expect(doc.Ownable.methods).to.not.be.undefined();
+ const ownableConstructorCount = 1;
+ const ownableMethodCount = 2;
+ const ownableEventCount = 1;
+ expect(doc.Ownable.constructors.length).to.equal(ownableConstructorCount);
+ expect(doc.Ownable.methods.length).to.equal(ownableMethodCount);
+ if (_.isUndefined(doc.Ownable.events)) {
+ throw new Error('events should never be undefined');
+ }
+ expect(doc.Ownable.events.length).to.equal(ownableEventCount);
- const erc20ConstructorCount = 0;
- const erc20MethodCount = 6;
- const erc20EventCount = 2;
- expect(doc.ERC20.constructors.length).to.equal(erc20ConstructorCount);
- expect(doc.ERC20.methods.length).to.equal(erc20MethodCount);
- if (_.isUndefined(doc.ERC20.events)) {
- throw new Error('events should never be undefined');
- }
- expect(doc.ERC20.events.length).to.equal(erc20EventCount);
+ expect(doc.ERC20).to.not.be.undefined();
+ expect(doc.ERC20.constructors).to.not.be.undefined();
+ expect(doc.ERC20.methods).to.not.be.undefined();
+ const erc20ConstructorCount = 0;
+ const erc20MethodCount = 6;
+ const erc20EventCount = 2;
+ expect(doc.ERC20.constructors.length).to.equal(erc20ConstructorCount);
+ expect(doc.ERC20.methods.length).to.equal(erc20MethodCount);
+ if (_.isUndefined(doc.ERC20.events)) {
+ throw new Error('events should never be undefined');
+ }
+ expect(doc.ERC20.events.length).to.equal(erc20EventCount);
- const erc20BasicConstructorCount = 0;
- const erc20BasicMethodCount = 3;
- const erc20BasicEventCount = 1;
- expect(doc.ERC20Basic.constructors.length).to.equal(erc20BasicConstructorCount);
- expect(doc.ERC20Basic.methods.length).to.equal(erc20BasicMethodCount);
- if (_.isUndefined(doc.ERC20Basic.events)) {
- throw new Error('events should never be undefined');
- }
- expect(doc.ERC20Basic.events.length).to.equal(erc20BasicEventCount);
+ expect(doc.ERC20Basic).to.not.be.undefined();
+ expect(doc.ERC20Basic.constructors).to.not.be.undefined();
+ expect(doc.ERC20Basic.methods).to.not.be.undefined();
+ const erc20BasicConstructorCount = 0;
+ const erc20BasicMethodCount = 3;
+ const erc20BasicEventCount = 1;
+ expect(doc.ERC20Basic.constructors.length).to.equal(erc20BasicConstructorCount);
+ expect(doc.ERC20Basic.methods.length).to.equal(erc20BasicMethodCount);
+ if (_.isUndefined(doc.ERC20Basic.events)) {
+ throw new Error('events should never be undefined');
+ }
+ expect(doc.ERC20Basic.events.length).to.equal(erc20BasicEventCount);
- let addAuthorizedAddressMethod: SolidityMethod | undefined;
- for (const method of doc.TokenTransferProxy.methods) {
- if (method.name === 'addAuthorizedAddress') {
- addAuthorizedAddressMethod = method;
+ let addAuthorizedAddressMethod: SolidityMethod | undefined;
+ for (const method of doc.TokenTransferProxy.methods) {
+ if (method.name === 'addAuthorizedAddress') {
+ addAuthorizedAddressMethod = method;
+ }
}
- }
- expect(
- addAuthorizedAddressMethod,
- `method addAuthorizedAddress not found in ${JSON.stringify(doc.TokenTransferProxy.methods)}`,
- ).to.not.be.undefined();
- const tokenTransferProxyAddAuthorizedAddressComment = 'Authorizes an address.';
- expect((addAuthorizedAddressMethod as SolidityMethod).comment).to.equal(
- tokenTransferProxyAddAuthorizedAddressComment,
- );
+ expect(
+ addAuthorizedAddressMethod,
+ `method addAuthorizedAddress not found in ${JSON.stringify(doc.TokenTransferProxy.methods)}`,
+ ).to.not.be.undefined();
+ const tokenTransferProxyAddAuthorizedAddressComment = 'Authorizes an address.';
+ expect((addAuthorizedAddressMethod as SolidityMethod).comment).to.equal(
+ tokenTransferProxyAddAuthorizedAddressComment,
+ );
+ });
});
});