Skip to content

Commit

Permalink
Add tests for $0 (2 passing, 4 failing)
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen authored and Benjamin Coe committed Apr 14, 2015
1 parent 0e7a7fb commit 22382ee
Showing 1 changed file with 60 additions and 3 deletions.
63 changes: 60 additions & 3 deletions test/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,9 @@ describe('usage tests', function () {
}

return yargs('--foo 10 --bar 20'.split(' '))
.usage('Usage: $0 [options]', opts)
.strict()
.argv
.usage('Usage: $0 [options]', opts)
.strict()
.argv
})

r.should.have.property('result')
Expand Down Expand Up @@ -1107,4 +1107,61 @@ describe('usage tests', function () {
])
})
})

describe('$0', function() {
function mockProcessArgv (argv, cb) {
var argvOld = process.argv
process.argv = argv
// cb must be sync for now
try {
cb()
process.argv = argvOld
} catch (err) {
process.argv = argvOld
throw err
}
}

it('is detected correctly for a basic script', function () {
mockProcessArgv(['script.js'], function () {
yargs([]).$0.should.equal('script.js')
})
})

it('is detected correctly when argv contains "node"', function () {
mockProcessArgv(['node', 'script.js'], function () {
yargs([]).$0.should.equal('script.js')
})
})

it('is detected correctly when dirname contains "node"', function () {
mockProcessArgv(['/code/node/script.js'], function () {
yargs([]).$0.should.equal('/code/node/script.js')
})
})

it('is detected correctly when dirname and argv contain "node"', function () {
mockProcessArgv(['node', '/code/node/script.js'], function () {
yargs([]).$0.should.equal('/code/node/script.js')
})
})

it('is detected correctly when argv contains "iojs"', function () {
mockProcessArgv(['iojs', 'script.js'], function () {
yargs([]).$0.should.equal('script.js')
})
})

it('is detected correctly when dirname contains "iojs"', function () {
mockProcessArgv(['/code/iojs/script.js'], function () {
yargs([]).$0.should.equal('/code/iojs/script.js')
})
})

it('is detected correctly when dirname and argv contain "iojs"', function () {
mockProcessArgv(['iojs', '/code/iojs/script.js'], function () {
yargs([]).$0.should.equal('/code/iojs/script.js')
})
})
})
})

0 comments on commit 22382ee

Please sign in to comment.