File tree Expand file tree Collapse file tree 2 files changed +48
-5
lines changed
packages/npm-packages/ruby-wasm-wasi/test Expand file tree Collapse file tree 2 files changed +48
-5
lines changed Original file line number Diff line number Diff line change @@ -46,4 +46,42 @@ const initRubyVM = async ({ suppressStderr } = { suppressStderr: false }) => {
46
46
return vm ;
47
47
} ;
48
48
49
- module . exports = { initRubyVM } ;
49
+ class RubyVersion {
50
+ constructor ( version ) {
51
+ this . version = version ;
52
+ }
53
+
54
+ toComponents ( ) {
55
+ const parts = this . version . split ( "." ) . map ( ( x ) => parseInt ( x , 10 ) ) ;
56
+ // Fill in missing parts with 0 until we have major, minor, and tiny.
57
+ while ( parts . length < 3 ) {
58
+ parts . push ( 0 ) ;
59
+ }
60
+ return parts ;
61
+ }
62
+
63
+ isGreaterThanOrEqualTo ( other ) {
64
+ const a = this . toComponents ( ) ;
65
+ if ( ! ( other instanceof RubyVersion ) ) {
66
+ other = new RubyVersion ( other ) ;
67
+ }
68
+ const b = other . toComponents ( ) ;
69
+ for ( let i = 0 ; i < 3 ; i ++ ) {
70
+ if ( a [ i ] > b [ i ] ) {
71
+ return true ;
72
+ }
73
+ if ( a [ i ] < b [ i ] ) {
74
+ return false ;
75
+ }
76
+ }
77
+ return true ;
78
+ }
79
+ }
80
+
81
+ const rubyVersion = ( async ( ) => {
82
+ const vm = await initRubyVM ( { suppressStderr : true } ) ;
83
+ const result = vm . eval ( "RUBY_VERSION" ) ;
84
+ return new RubyVersion ( result . toString ( ) ) ;
85
+ } ) ( ) ;
86
+
87
+ module . exports = { initRubyVM, rubyVersion } ;
Original file line number Diff line number Diff line change 1
- const { initRubyVM } = require ( "./init" ) ;
1
+ const { initRubyVM, rubyVersion } = require ( "./init" ) ;
2
2
3
3
describe ( "RubyVM" , ( ) => {
4
4
test ( "empty expression" , async ( ) => {
@@ -106,11 +106,16 @@ describe("RubyVM", () => {
106
106
foo
107
107
` ) ;
108
108
} ;
109
- expect ( throwError )
110
- . toThrowError ( `eval:9:in \`fizz': fizz raised (RuntimeError)
109
+ const expectedBacktrace = ( ( await rubyVersion ) . isGreaterThanOrEqualTo ( "3.4.0" ) )
110
+ ? `eval:9:in 'Object#fizz': fizz raised (RuntimeError)
111
+ eval:6:in 'Object#bar'
112
+ eval:3:in 'Object#foo'
113
+ eval:11:in '<main>'`
114
+ : `eval:9:in \`fizz': fizz raised (RuntimeError)
111
115
eval:6:in \`bar'
112
116
eval:3:in \`foo'
113
- eval:11:in \`<main>'` ) ;
117
+ eval:11:in \`<main>'`
118
+ expect ( throwError ) . toThrowError ( expectedBacktrace ) ;
114
119
} ) ;
115
120
116
121
test ( "exception while formatting exception backtrace" , async ( ) => {
You can’t perform that action at this time.
0 commit comments