mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-28 02:27:41 +00:00
Merge pull request #9238 from keymanapp/chore/developer/unit-test-for-compiler-warnings-as-errors
chore(developer): unit test for compilerWarningsAsErrors 🗜
This commit is contained in:
commit
73f662483f
7 changed files with 126 additions and 1 deletions
|
|
@ -31,7 +31,8 @@ export function declareBuild(program: Command) {
|
|||
.description('Build a source file into a final file')
|
||||
)
|
||||
.option('-d, --debug', 'Include debug information in output')
|
||||
.option('-w, --compiler-warnings-as-errors', 'Causes warnings to fail the build')
|
||||
.option('-w, --compiler-warnings-as-errors', 'Causes warnings to fail the build; overrides project-level warnings-as-errors option')
|
||||
.option('-W, --no-compiler-warnings-as-errors', 'Warnings do not fail the build; overrides project-level warnings-as-errors option')
|
||||
.option('--no-compiler-version', 'Exclude compiler version metadata from output')
|
||||
.option('--no-warn-deprecated-code', 'Turn off warnings for deprecated code styles')
|
||||
.option('--color', 'Force colorization for log messages')
|
||||
|
|
|
|||
1
developer/src/kmc/test/fixtures/.gitignore
vendored
1
developer/src/kmc/test/fixtures/.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
*/*/build
|
||||
relative_paths/*.kmp
|
||||
relative_paths/*.kmx
|
||||
compiler-warnings-as-errors/*.kmx
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<KeymanDeveloperProject>
|
||||
<Options>
|
||||
<BuildPath>$PROJECTPATH</BuildPath>
|
||||
<CompilerWarningsAsErrors>False</CompilerWarningsAsErrors>
|
||||
<WarnDeprecatedCode>False</WarnDeprecatedCode>
|
||||
<CheckFilenameConventions>False</CheckFilenameConventions>
|
||||
<ProjectType>keyboard</ProjectType>
|
||||
</Options>
|
||||
<Files>
|
||||
<File>
|
||||
<ID>keyboard_1</ID>
|
||||
<Filename>keyboard.kmn</Filename>
|
||||
<Filepath>keyboard.kmn</Filepath>
|
||||
<FileVersion>1.0</FileVersion>
|
||||
<FileType>.kmn</FileType>
|
||||
<Details>
|
||||
<Name>keyboard</Name>
|
||||
<Copyright>Copyright (C) Keyman Team</Copyright>
|
||||
</Details>
|
||||
</File>
|
||||
</Files>
|
||||
</KeymanDeveloperProject>
|
||||
23
developer/src/kmc/test/fixtures/compiler-warnings-as-errors/compiler_warnings_as_errors_true.kpj
vendored
Normal file
23
developer/src/kmc/test/fixtures/compiler-warnings-as-errors/compiler_warnings_as_errors_true.kpj
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<KeymanDeveloperProject>
|
||||
<Options>
|
||||
<BuildPath>$PROJECTPATH</BuildPath>
|
||||
<CompilerWarningsAsErrors>True</CompilerWarningsAsErrors>
|
||||
<WarnDeprecatedCode>False</WarnDeprecatedCode>
|
||||
<CheckFilenameConventions>False</CheckFilenameConventions>
|
||||
<ProjectType>keyboard</ProjectType>
|
||||
</Options>
|
||||
<Files>
|
||||
<File>
|
||||
<ID>keyboard_1</ID>
|
||||
<Filename>keyboard.kmn</Filename>
|
||||
<Filepath>keyboard.kmn</Filepath>
|
||||
<FileVersion>1.0</FileVersion>
|
||||
<FileType>.kmn</FileType>
|
||||
<Details>
|
||||
<Name>keyboard</Name>
|
||||
<Copyright>Copyright (C) Keyman Team</Copyright>
|
||||
</Details>
|
||||
</File>
|
||||
</Files>
|
||||
</KeymanDeveloperProject>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<KeymanDeveloperProject>
|
||||
<Options>
|
||||
<BuildPath>$PROJECTPATH</BuildPath>
|
||||
<WarnDeprecatedCode>False</WarnDeprecatedCode>
|
||||
<CheckFilenameConventions>False</CheckFilenameConventions>
|
||||
<ProjectType>keyboard</ProjectType>
|
||||
</Options>
|
||||
<Files>
|
||||
<File>
|
||||
<ID>keyboard_1</ID>
|
||||
<Filename>keyboard.kmn</Filename>
|
||||
<Filepath>keyboard.kmn</Filepath>
|
||||
<FileVersion>1.0</FileVersion>
|
||||
<FileType>.kmn</FileType>
|
||||
<Details>
|
||||
<Name>keyboard</Name>
|
||||
<Copyright>Copyright (C) Keyman Team</Copyright>
|
||||
</Details>
|
||||
</File>
|
||||
</Files>
|
||||
</KeymanDeveloperProject>
|
||||
10
developer/src/kmc/test/fixtures/compiler-warnings-as-errors/keyboard.kmn
vendored
Normal file
10
developer/src/kmc/test/fixtures/compiler-warnings-as-errors/keyboard.kmn
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
store(&NAME) '000 - null keyboard'
|
||||
store(&version) '6.0'
|
||||
|
||||
c The following line generates warn KM0209D: Header statements are deprecated; use instead the equivalent system store
|
||||
LANGUAGE x1, x1
|
||||
|
||||
begin Unicode > use(Main)
|
||||
|
||||
group(Main) using keys
|
||||
|
||||
45
developer/src/kmc/test/test-build.ts
Normal file
45
developer/src/kmc/test/test-build.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';
|
||||
import { assert } from 'chai';
|
||||
import 'mocha';
|
||||
import { BuildProject } from '../src/commands/buildClasses/BuildProject.js';
|
||||
import { makePathToFixture } from './helpers/index.js';
|
||||
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
|
||||
interface CompilerWarningsAsErrorsTruthTable {
|
||||
cli: boolean;
|
||||
kpj: boolean;
|
||||
result: boolean;
|
||||
};
|
||||
|
||||
describe('compilerWarningsAsErrors', function () {
|
||||
beforeEach(() => callbacks.clear());
|
||||
|
||||
// The CLI option should override the project setting
|
||||
|
||||
const truthTable: CompilerWarningsAsErrorsTruthTable[] = [
|
||||
{cli:undefined, kpj:undefined, result:true}, // default setting (false) wins
|
||||
{cli:undefined, kpj:false, result:true}, // kpj setting wins
|
||||
{cli:undefined, kpj:true, result:false}, // kpj setting wins
|
||||
{cli:false, kpj:undefined, result:true}, // cli setting wins
|
||||
{cli:false, kpj:false, result:true}, // cli setting wins
|
||||
{cli:false, kpj:true, result:true}, // cli setting wins
|
||||
{cli:true, kpj:undefined, result:false}, // cli setting wins
|
||||
{cli:true, kpj:false, result:false}, // cli setting wins
|
||||
{cli:true, kpj:true, result:false}, // cli setting wins
|
||||
]
|
||||
|
||||
for(const truth of truthTable) {
|
||||
it(`should ${truth.result?'':'fail to '}build a project when kpj option=${truth.kpj} and cli option=${truth.cli}`, async function() {
|
||||
const builder = new BuildProject();
|
||||
const path = makePathToFixture('compiler-warnings-as-errors',
|
||||
`compiler_warnings_as_errors_${truth.kpj === true ? 'true' : (truth.kpj === false ? 'false' : 'undefined')}.kpj`);
|
||||
const result = await builder.build(path, callbacks, {compilerWarningsAsErrors: truth.cli});
|
||||
if(truth.result) {
|
||||
assert.isTrue(result);
|
||||
} else {
|
||||
assert.isFalse(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue