Skip to content

Commit

Permalink
Test without Tape
Browse files Browse the repository at this point in the history
Current Tape does not support some of the very old versions we do.
  • Loading branch information
kemitchell committed Sep 21, 2023
1 parent ec6ee14 commit 4aa7f81
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"dependencies": {
"spdx-compare": "^1.0.0",
"spdx-expression-parse": "^3.0.0",
"spdx-ranges": "^2.0.0",
"tape": "^5.6.6"
"spdx-ranges": "^2.0.0"
},
"devDependencies": {
"defence-cli": "^2.0.1",
Expand Down
51 changes: 36 additions & 15 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
var assert = require('assert')
var examples = require('./examples.json')
var satisfies = require('./')
var tape = require('tape')

function label(expression, approved) {
return JSON.stringify(expression) + ', ' + JSON.stringify(approved)
var failed = false

function write (string) { process.stdout.write(string) }

function label (expression, approved) {
write('satisfies(' + JSON.stringify(expression) + ', ' + JSON.stringify(approved) + ')')
}

for (const [expression, approved] of examples.returnTrue) {
tape.test(label(expression, approved), t => {
t.assert(satisfies(expression, approved), 'returns true')
t.end()
})
label(expression, approved)
try {
assert(satisfies(expression, approved) === true)
} catch (error) {
failed = true
write(' did not return true\n')
continue
}
write(' returned true\n')
}

// False Examples
for (const [expression, approved] of examples.returnFalse) {
tape.test(label(expression, approved), t => {
t.assert(!satisfies(expression, approved))
t.end()
})
label(expression, approved)
try {
assert(satisfies(expression, approved) === false)
} catch (error) {
failed = true
write(' did not return false\n')
continue
}
write(' returned false\n')
}

// Invalid License Arrays
for (const [expression, approved] of examples.throwErrors) {
tape.test(label(expression, approved), t => {
t.throws(() => satisfies(expression, approved))
t.end()
})
label(expression, approved)
try {
satisfies(expression, approved)
} catch (error) {
write(' threw an exception\n')
continue
}
failed = true
write(' did not throw an exception\n')
}

process.exit(failed ? 1 : 0)

0 comments on commit 4aa7f81

Please sign in to comment.