unix.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. var tap = require('tap')
  6. if (process.platform === 'win32') {
  7. tap.plan(0, 'Skip unix tests, this is not unix')
  8. process.exit(0)
  9. }
  10. // like unix, but funny
  11. process.env.USER = 'sirUser'
  12. process.env.HOME = '/home/sirUser'
  13. process.env.HOSTNAME = 'my-machine'
  14. process.env.TMPDIR = '/tmpdir'
  15. process.env.TMP = '/tmp'
  16. process.env.TEMP = '/temp'
  17. process.env.PATH = '/opt/local/bin:/usr/local/bin:/usr/bin/:bin'
  18. process.env.PS1 = '(o_o) $ '
  19. process.env.EDITOR = 'edit'
  20. process.env.VISUAL = 'visualedit'
  21. process.env.SHELL = 'zsh'
  22. tap.test('basic unix sanity test', function (t) {
  23. var osenv = require('../osenv.js')
  24. t.equal(osenv.user(), process.env.USER)
  25. t.equal(osenv.home(), process.env.HOME)
  26. t.equal(osenv.hostname(), process.env.HOSTNAME)
  27. t.same(osenv.path(), process.env.PATH.split(':'))
  28. t.equal(osenv.prompt(), process.env.PS1)
  29. t.equal(osenv.tmpdir(), process.env.TMPDIR)
  30. // mildly evil, but it's for a test.
  31. process.env.TMPDIR = ''
  32. delete require.cache[require.resolve('../osenv.js')]
  33. var osenv = require('../osenv.js')
  34. t.equal(osenv.tmpdir(), process.env.TMP)
  35. process.env.TMP = ''
  36. delete require.cache[require.resolve('../osenv.js')]
  37. var osenv = require('../osenv.js')
  38. t.equal(osenv.tmpdir(), process.env.TEMP)
  39. process.env.TEMP = ''
  40. delete require.cache[require.resolve('../osenv.js')]
  41. var osenv = require('../osenv.js')
  42. osenv.home = function () { return null }
  43. t.equal(osenv.tmpdir(), '/tmp')
  44. t.equal(osenv.editor(), 'edit')
  45. process.env.EDITOR = ''
  46. delete require.cache[require.resolve('../osenv.js')]
  47. var osenv = require('../osenv.js')
  48. t.equal(osenv.editor(), 'visualedit')
  49. process.env.VISUAL = ''
  50. delete require.cache[require.resolve('../osenv.js')]
  51. var osenv = require('../osenv.js')
  52. t.equal(osenv.editor(), 'vi')
  53. t.equal(osenv.shell(), 'zsh')
  54. process.env.SHELL = ''
  55. delete require.cache[require.resolve('../osenv.js')]
  56. var osenv = require('../osenv.js')
  57. t.equal(osenv.shell(), 'bash')
  58. t.end()
  59. })