Browse Source

Merge branch 'testSuite' of LInE/ivprog into master

Implement testing suite and versioning system
Lucas de Souza 6 years ago
parent
commit
1b5873673f

+ 3 - 2
.gitignore

@@ -1,6 +1,7 @@
 #compiled files
-#/build
-
+/build
+.ima_version.json
+ivprog.tar.gz
 # dependencies
 /node_modules
 

+ 0 - 1
.ima_version.json

@@ -1 +0,0 @@
-{ "version":"2019_03_12 17_04" }

File diff suppressed because it is too large
+ 0 - 59588
build/ivprog.bundle.js


File diff suppressed because it is too large
+ 0 - 1
build/ivprog.bundle.js.map


+ 29 - 0
changeScriptSourcePlugin.js

@@ -0,0 +1,29 @@
+// If your plugin is direct dependent to the html webpack plugin:
+var HtmlWebpackPlugin = require('html-webpack-plugin');
+
+function ChangeScriptSourcePlugin () {}
+
+ChangeScriptSourcePlugin.prototype.apply = function (compiler) {
+  compiler.hooks.compilation.tap('ChangeScriptSourcePlugin', function (compilation) {
+    console.log('The compiler is starting a new compilation...')
+    // Staic Plugin interface |compilation |HOOK NAME | register listener 
+    HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync(
+      'ChangeScriptSourcePlugin', // <-- Set a meaningful name here for stacktraces
+      function (data, cb) {
+        // Manipulate the content
+        const listSize = data.assetTags.scripts.length;
+        for (let i = 0; i < listSize; ++i) {
+          const tag = data.assetTags.scripts[i];
+          var path = tag.attributes.src;
+          // remove build/ from src...
+          data.assetTags.scripts[i].attributes.src = path.substring(path.indexOf("/") + 1);
+        }
+
+        // Tell webpack to move on
+        cb(null, data);
+      }
+    )
+  })
+}
+
+module.exports = ChangeScriptSourcePlugin

+ 4 - 2
js/typeSystem/parsers.js

@@ -40,11 +40,13 @@ export function toBool (str) {
 export function convertBoolToString (bool) {
   const lexer = LanguageService.getCurrentLexer();
   const instance = new lexer(null);
+  let result = null;
   if (bool) {
-    return instance.literalNames[lexer.RK_TRUE];
+    result = instance.literalNames[lexer.RK_TRUE];
   } else {
-    return instance.literalNames[lexer.RK_FALSE];
+    result = instance.literalNames[lexer.RK_FALSE];
   }
+  return result.replace(/'/g,"");
 }
 
 export function convertToString(value, type) {

+ 36 - 10
karma.conf.js

@@ -1,4 +1,3 @@
-const webpackConfig = require('./webpack.config.js');
 process.env.CHROME_BIN = '/snap/bin/chromium';
  
 module.exports = function(config) {
@@ -9,7 +8,7 @@ module.exports = function(config) {
     exclude: [],
     //files/patterns to load in the browser
     files: [
-      {pattern: 'tests/*.spec.js',watched:true,served:true,included:true}
+     'tests/*.spec.js'
       /*parameters*/
           //watched: if autoWatch is true all files that have set watched to true will be watched for changes
           //served: should the files be served by Karma's webserver?
@@ -21,9 +20,9 @@ module.exports = function(config) {
     ],
     
     //executes the tests whenever one of watched files changes
-    autoWatch: true,
+    autoWatch: false,
     //if true, Karma will run tests and then exit browser
-    singleRun:false,
+    singleRun: true,
     //if true, Karma fails on running empty test-suites
     failOnEmptyTestSuite:false,
     //reduce the kind of information passed to the bash
@@ -34,7 +33,7 @@ module.exports = function(config) {
     //list of browsers to launch and capture
     browsers: ['ChromeHeadless'/*,'PhantomJS','Firefox','Edge','ChromeCanary','Opera','IE','Safari'*/],
     //list of reporters to use
-    reporters: ['mocha','kjhtml'/*,'dots','progress','spec'*/],
+    reporters: ['mocha' /*,'kjhtml','dots','progress','spec'*/],
     
     //address that the server will listen on, '0.0.0.0' is default
     listenAddress: '0.0.0.0',
@@ -47,7 +46,7 @@ module.exports = function(config) {
     //how long does Karma wait for a browser to reconnect, 2000 is default
     browserDisconnectTimeout: 5000,
     //how long will Karma wait for a message from a browser before disconnecting from it, 10000 is default
-    browserNoActivityTimeout: 10000,
+    browserNoActivityTimeout: 60000,
     //timeout for capturing a browser, 60000 is default
     captureTimeout: 60000,
  
@@ -68,22 +67,49 @@ module.exports = function(config) {
  
     /*karma-webpack config*/
     //pass your webpack configuration for karma
-    webpack: webpackConfig,
+    webpack: {
+      node: {
+        fs: 'empty',
+      },
+      module: {
+        rules: [
+            {
+              test: /\.js$/,
+              exclude: /(node_modules)/,
+              use: {
+                loader: "babel-loader",
+                options: {
+                  presets: ["@babel/preset-env"]
+                }
+              }
+            },
+            {
+              test: /\.g4$/,
+              exclude: /(node_modules)/,
+              use: {
+                loader:'antlr4-webpack-loader'
+              }
+            }
+        ]
+    },
+    },
     preprocessors: {
       //use webpack to support require() in test-suits .js files
       //use babel-loader from webpack to compile es2015 features in .js files
       //add webpack as preprocessor
-      './tests/*.js': ['webpack']
+      'tests/*.spec.js': ['webpack']
     },
     webpackMiddleware: {
       //turn off webpack bash output when run the tests
       noInfo: true,
-      stats: 'errors-only'
+      stats: {
+        chunks: false
+      }
     },
  
     /*karma-mocha-reporter config*/
     mochaReporter: {
-      output: 'noFailures'  //full, autowatch, minimal
+      output: 'full'  //full, autowatch, minimal
     }
   });
 };

File diff suppressed because it is too large
+ 1209 - 22
package-lock.json


+ 15 - 3
package.json

@@ -4,9 +4,11 @@
   "description": "IMA para o ensino de programação",
   "main": "js/main.js",
   "scripts": {
-    "start": "http-server",
-    "build": "webpack",
-    "watch": "webpack --watch"
+    "start": "http-server ./build",
+    "build": "webpack --mode=development",
+    "watch": "webpack --watch --mode=development",
+    "compile": "webpack --mode=production && tar -zcvf ivprog.tar.gz build/",
+    "test": "./node_modules/karma/bin/karma start"
   },
   "repository": {
     "type": "git",
@@ -28,6 +30,16 @@
     "@babel/preset-env": "^7.3.4",
     "antlr4-webpack-loader": "^0.1.1",
     "babel-loader": "^8.0.5",
+    "clean-webpack-plugin": "^2.0.1",
+    "copy-webpack-plugin": "^5.0.1",
+    "html-webpack-plugin": "^4.0.0-beta.5",
+    "jasmine-core": "^3.3.0",
+    "karma": "^4.0.1",
+    "karma-chrome-launcher": "^2.2.0",
+    "karma-jasmine": "^2.0.1",
+    "karma-mocha-reporter": "^2.2.5",
+    "karma-webpack": "^3.0.5",
+    "puppeteer": "^1.13.0",
     "ts-loader": "^5.2.2",
     "typescript": "^3.1.3",
     "webpack": "^4.29.0",

+ 13 - 17
index.html

@@ -9,17 +9,10 @@
     <meta http-equiv="pragma" content="no-cache">
     <title></title>
     <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
-    <link rel="stylesheet" type="text/css" href="js/semantic/semantic.min.css">
+    <link rel="stylesheet" type="text/css" href="css/semantic.min.css">
     <link rel="stylesheet" type="text/css" href="css/ivprog-visual-1.0.css">
     <link rel="stylesheet" type="text/css" href="css/ivprog-term.css">
     <script src="js/jquery-3.3.1.min.js"></script>
-    <script src="js/iassign-integration-functions.js"></script>
-    <script src="build/ivprog.bundle.js"></script>
-    <script src="js/semantic/semantic.min.js"></script>
-    <script src="js/semantic/semantic-buttons.js"></script>
-
-    <script src="js/jquery-ui.js"></script>
-    <script src="js/Sortable.js"></script>
     
   </head>
   <body>
@@ -109,14 +102,17 @@
     </div>
 
   </div>
-
-    <script>
-      $(document).ready(() => {
-        ivprogCore.LocalizedStrings.updateTagText();
-        ivprogCore.initVisualUI();
-        prepareEnvironment();
-      });
-    </script>
-
   </body>
+  <script src="js/semantic.min.js"></script>
+  <script src="js/semantic-buttons.js"></script>
+  <script src="js/jquery-ui.js"></script>
+  <script src="js/Sortable.js"></script>
+  <script src="js/iassign-integration-functions.js"></script>
+  <script>
+    $(document).ready(() => {
+      ivprogCore.LocalizedStrings.updateTagText();
+      ivprogCore.initVisualUI();
+      prepareEnvironment();
+    });
+  </script>
 </html>

+ 5 - 6
runner.html

@@ -25,6 +25,8 @@
     }
   </style>
   <title></title>
+  <script src="js/jquery-3.3.1.min.js"></script>
+  <script type="text/javascript" src="js/jquery.json-editor.min.js"></script>
 </head>
 <body>
     <div style="padding-top: 50px;content: ''"></div>
@@ -67,12 +69,9 @@
   
 </body>
 
-<script src="js/jquery-3.3.1.min.js"></script>
-
-<script type="text/javascript" src="js/jquery.json-editor.min.js"></script>
-<script type="text/javascript" src="build/ivprog.bundle.js"></script>
-
 <script>
-  ivprogCore.runner();
+  ( function () {
+    ivprogCore.runner();
+  })();
 </script>
 </html>

+ 1 - 1
tests/test22.spec.js

@@ -8,7 +8,7 @@ describe('An assignment to a variable', function () {
   const input = `programa {
 
     funcao inicio() {
-      inteiro a
+      logico a
       a = 5.5
     }
   }`;

+ 1 - 1
tests/test38.spec.js

@@ -22,7 +22,7 @@ describe('The write function', function () {
     const exec = new IVProgProcessor(parser.parseTree());
     exec.registerOutput(output);
     exec.interpretAST().then(sto => {
-      expect(output.list).toEqual(['8.01']);
+      expect(output.list).toEqual([8.01]);
       done();
     }).catch( err => done(err));
   });

+ 1 - 1
tests/test40.spec.js

@@ -30,7 +30,7 @@ describe('The LanguageService', function () {
     const exec = new IVProgProcessor(parser.parseTree());
     exec.registerOutput(output);
     exec.interpretAST().then(sto => {
-      expect(output.list).toEqual(['8.01']);
+      expect(output.list).toEqual([8.01]);
       LanguageService.setLang('pt');
       done();
     }).catch( err => done(err));

+ 2 - 2
tests/test45.spec.js

@@ -11,8 +11,8 @@ describe('The semantic analyser', function () {
       a = aNumber()
     }
 
-    funcao inteiro aNumber () {
-      retorne 3
+    funcao logico aNumber () {
+      retorne verdadeiro
     }
   }`;
 

+ 1 - 1
tests/test51.spec.js

@@ -8,7 +8,7 @@ describe('A invalid relational operation inside an if', function () {
 
     funcao inicio() {
       inteiro a = 5
-      se ( a * 2.3 > 8) {
+      se ( a * 2.3 > "um texto") {
         a = 8
       } senao {
         a = -1

+ 1 - 1
tests/test57.spec.js

@@ -25,7 +25,7 @@ describe('Is_Real function ', function () {
     const exec = new IVProgProcessor(sem.analyseTree());
     exec.registerOutput(out);
     exec.interpretAST().then(_ => {
-      expect(out.list).toEqual([true]);
+      expect(out.list).toEqual(["verdadeiro"]);
       done();
     }).catch(err => done(err));
   });

+ 1 - 1
tests/test66.spec.js

@@ -29,7 +29,7 @@ describe('Non initialized matrix', function () {
             mat[i][j] = j
           } senao se (j == 0) {
             mat[i][j] = i
-          } senao se (char_at(str1, i-1) == char_at(str2, j-1)) {
+          } senao se (texto_na_posicao(str1, i-1) == texto_na_posicao(str2, j-1)) {
             mat[i][j] = mat[i-1][j-1]
           } senao {
             mat[i][j] = 1 + Matematica.minimo({mat[i][j-1], mat[i-1][j], mat[i-1][j-1]})

+ 2 - 21
updateVersionPlugin.js

@@ -1,28 +1,9 @@
 var fs = require('fs');
 var path = require('path');
-
-function processDate () {
-  var date = new Date();
-  var day = date.getUTCDate();
-  day = day > 9 ? day : '0' + day;
-  var month = date.getMonth() + 1;
-  month = month > 9 ? month : '0' + month;
-  var minutes = date.getMinutes();
-  minutes = minutes > 9 ? minutes : '0' + minutes;
-  var hour = date.getHours();
-  hour = hour > 9 ? hour : '0' + hour;
-  return {
-    year: date.getFullYear(),
-    month: month,
-    day: day,
-    hour: hour,
-    minutes: minutes
-  }
-}
+var versionStringFun = require('./versionFileHelper');
 
 function writeVersionFile () {
-  var versionInfo = processDate();
-  var versionString = `${versionInfo.year}_${versionInfo.month}_${versionInfo.day} ${versionInfo.hour}_${versionInfo.minutes}`;
+  var versionString = versionStringFun();
   var fileData = `{ "version":"${versionString}" }`;
   var filePath = path.join(__dirname, '.ima_version.json');
   fs.writeFileSync(filePath, fileData);

+ 25 - 0
versionFileHelper.js

@@ -0,0 +1,25 @@
+function processDate () {
+  var date = new Date();
+  var day = date.getUTCDate();
+  day = day > 9 ? day : '0' + day;
+  var month = date.getMonth() + 1;
+  month = month > 9 ? month : '0' + month;
+  var minutes = date.getMinutes();
+  minutes = minutes > 9 ? minutes : '0' + minutes;
+  var hour = date.getHours();
+  hour = hour > 9 ? hour : '0' + hour;
+  return {
+    year: date.getFullYear(),
+    month: month,
+    day: day,
+    hour: hour,
+    minutes: minutes
+  }
+}
+
+function formatVersionString () {
+  var versionInfo = processDate();
+  return `${versionInfo.year}_${versionInfo.month}_${versionInfo.day} ${versionInfo.hour}_${versionInfo.minutes}`;
+}
+
+module.exports = formatVersionString;

+ 43 - 9
webpack.config.js

@@ -1,13 +1,15 @@
 var path = require('path');
-var webpack = require('webpack');
+var HtmlWebpackPlugin = require('html-webpack-plugin');
 var UpdateVersionPlugin = require('./updateVersionPlugin');
+//var ChangeScriptSourcePlugin = require('./changeScriptSourcePlugin');
+var CopyPlugin = require('copy-webpack-plugin');
+var CleanWebpackPlugin = require('clean-webpack-plugin');
 
 module.exports = {
-    entry: './js/main.js',
-    mode: 'development',
+    entry: path.resolve(__dirname, 'js/main.js'),
     output: {
-        path: path.resolve(__dirname, 'build'),
-        filename: 'ivprog.bundle.js',
+        path: path.resolve(__dirname, 'build',"js"),
+        filename: '[name].[contenthash].js',
         library: 'ivprogCore',
         libraryTarget: 'umd'
     },
@@ -38,14 +40,46 @@ module.exports = {
     stats: {
         colors: true
     },
-    plugins: [new UpdateVersionPlugin()],
-    /*optimization: {
+    plugins: [
+      new CleanWebpackPlugin({
+        cleanOnceBeforeBuildPatterns:[path.resolve(__dirname, 'build/**/*')],
+        watch: true
+      }),
+      new UpdateVersionPlugin(),
+      new HtmlWebpackPlugin({
+        template: 'templates/index.html',
+        filename: path.resolve(__dirname, 'build', 'index.html')
+      }),
+      new HtmlWebpackPlugin({
+        template: 'templates/runner.html',
+        filename: path.resolve(__dirname, 'build', 'runner.html')
+      }),
+      /*new ChangeScriptSourcePlugin(),*/
+      new CopyPlugin([
+        {from:"js/semantic/", to:path.resolve(__dirname, 'build/css')},
+        {from:"css/ivprog-visual-1.0.css", to:path.resolve(__dirname, 'build/css')},
+        {from:"css/ivprog-term.css", to:path.resolve(__dirname, 'build/css')},
+        {from:'js/jquery-3.3.1.min.js', to:path.resolve(__dirname, 'build/js')},
+        {from:'js/semantic/semantic.min.js', to:path.resolve(__dirname, 'build/js')},
+        {from:'js/semantic/semantic-buttons.js', to:path.resolve(__dirname, 'build/js')},
+        {from:'js/jquery-ui.js', to:path.resolve(__dirname, 'build/js')},
+        {from:'js/Sortable.js', to:path.resolve(__dirname, 'build/js')},
+        {from:'js/iassign-integration-functions.js', to:path.resolve(__dirname, 'build/js')},
+        /*{from:'index.html', to:path.resolve(__dirname, 'build')},
+        {from:'runner.html', to:path.resolve(__dirname, 'build')},*/
+      ])
+    ],
+    optimization: {
         splitChunks: {
             chunks: 'all'
         }
-    },*/
+    },
     devtool: 'source-map',
     watchOptions: {
-        ignored: path.resolve(__dirname, '.ima_version.json')
+        ignored: [
+          path.resolve(__dirname, '.ima_version.json'),
+          path.resolve(__dirname, 'index.html'),
+          path.resolve(__dirname, 'runner.html')
+        ]
     }
 };