unix.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // only run this test on windows
  2. // pretending to be another platform is too hacky, since it breaks
  3. // how the underlying system looks up module paths and runs
  4. // child processes, and all that stuff is cached.
  5. if (process.platform === 'win32') {
  6. console.log('TAP Version 13\n' +
  7. '1..0\n' +
  8. '# Skip unix tests, this is not unix\n')
  9. return
  10. }
  11. var tap = require('tap')
  12. // like unix, but funny
  13. process.env.USER = 'sirUser'
  14. process.env.HOME = '/home/sirUser'
  15. process.env.HOSTNAME = 'my-machine'
  16. process.env.TMPDIR = '/tmpdir'
  17. process.env.TMP = '/tmp'
  18. process.env.TEMP = '/temp'
  19. process.env.PATH = '/opt/local/bin:/usr/local/bin:/usr/bin/:bin'
  20. process.env.PS1 = '(o_o) $ '
  21. process.env.EDITOR = 'edit'
  22. process.env.VISUAL = 'visualedit'
  23. process.env.SHELL = 'zsh'
  24. tap.test('basic unix sanity test', function (t) {
  25. var osenv = require('../osenv.js')
  26. t.equal(osenv.user(), process.env.USER)
  27. t.equal(osenv.home(), process.env.HOME)
  28. t.equal(osenv.hostname(), process.env.HOSTNAME)
  29. t.same(osenv.path(), process.env.PATH.split(':'))
  30. t.equal(osenv.prompt(), process.env.PS1)
  31. t.equal(osenv.tmpdir(), process.env.TMPDIR)
  32. // mildly evil, but it's for a test.
  33. process.env.TMPDIR = ''
  34. delete require.cache[require.resolve('../osenv.js')]
  35. var osenv = require('../osenv.js')
  36. t.equal(osenv.tmpdir(), process.env.TMP)
  37. process.env.TMP = ''
  38. delete require.cache[require.resolve('../osenv.js')]
  39. var osenv = require('../osenv.js')
  40. t.equal(osenv.tmpdir(), process.env.TEMP)
  41. process.env.TEMP = ''
  42. delete require.cache[require.resolve('../osenv.js')]
  43. var osenv = require('../osenv.js')
  44. t.equal(osenv.tmpdir(), '/home/sirUser/tmp')
  45. delete require.cache[require.resolve('../osenv.js')]
  46. var osenv = require('../osenv.js')
  47. osenv.home = function () { return null }
  48. t.equal(osenv.tmpdir(), '/tmp')
  49. t.equal(osenv.editor(), 'edit')
  50. process.env.EDITOR = ''
  51. delete require.cache[require.resolve('../osenv.js')]
  52. var osenv = require('../osenv.js')
  53. t.equal(osenv.editor(), 'visualedit')
  54. process.env.VISUAL = ''
  55. delete require.cache[require.resolve('../osenv.js')]
  56. var osenv = require('../osenv.js')
  57. t.equal(osenv.editor(), 'vi')
  58. t.equal(osenv.shell(), 'zsh')
  59. process.env.SHELL = ''
  60. delete require.cache[require.resolve('../osenv.js')]
  61. var osenv = require('../osenv.js')
  62. t.equal(osenv.shell(), 'bash')
  63. t.end()
  64. })