-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix findCommonParent behaviour when NativeLibrariestPath targets a si…
…ngle .so file (#12395) * Fix findCommonParent behaviour when NativeLibrariestPath targets to single .so file * Add Unit tests for utils * Fix tests * Rename unitTest to assertByExitCode * Add timeout to spawnSync * Add test for unit tests exit code Co-authored-by: Alex Kharchenko <[email protected]>
- Loading branch information
1 parent
b414a7a
commit 5c985ad
Showing
10 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as path from 'path'; | ||
import * as assert from 'assert'; | ||
import {spawnSync} from 'child_process'; | ||
|
||
export function utilsUnitTests() { | ||
describe('Utils unit tests', function () { | ||
describe('findCommonParent', function() { | ||
it('returns containing directory for single file', function() { | ||
const tp = path.join(__dirname, 'UnitTests', 'Utils', 'FindCommonParentForSingleFileReturnsContainingDirectory.js'); | ||
const spawn = spawnSync('node', [tp], {timeout: 2000}); | ||
assert.equal(spawn.status, 0); | ||
}); | ||
|
||
it('returns directory itself for single directory', function() { | ||
const tp = path.join(__dirname, 'UnitTests', 'Utils', 'FindCommonParentForSingleDirectoryReturnsDirectoryItself.js'); | ||
const spawn = spawnSync('node', [tp], {timeout: 2000}); | ||
assert.equal(spawn.status, 0); | ||
}); | ||
|
||
it('returns common parent for multiple values', function() { | ||
const tp = path.join(__dirname, 'UnitTests', 'Utils', 'FindCommonParentForMultipleFilesReturnsCorrectResult.js'); | ||
const spawn = spawnSync('node', [tp], {timeout: 2000}); | ||
assert.equal(spawn.status, 0); | ||
}); | ||
}); | ||
}); | ||
} |
18 changes: 18 additions & 0 deletions
18
Tasks/AppCenterDistributeV3/Tests/UnitTests/TestHelpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as assert from "assert"; | ||
|
||
/** | ||
* Exit code is used to determine whether unit test passed or not. | ||
* When executing code requires vsts-task-lib somewhere it makes exit code = 0 regardless whether exception was thrown. | ||
* This helper allows to follow default NodeJS exit code behaviour when exception is thrown. | ||
*/ | ||
export const assertByExitCode = { | ||
equal: (actual, expected) => wrapAssertWithExitCode(assert.equal, actual, expected), | ||
}; | ||
|
||
function wrapAssertWithExitCode(assert, ...args) { | ||
try { | ||
assert.apply(undefined, args); | ||
} catch (error) { | ||
process.exit(1); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
Tasks/AppCenterDistributeV3/Tests/UnitTests/UnitTestsExitCodeIsKept.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { assertByExitCode } from "./TestHelpers"; | ||
|
||
// Verify that exit code doesn't overwritten | ||
assertByExitCode.equal(true, false); |
14 changes: 14 additions & 0 deletions
14
...istributeV3/Tests/UnitTests/Utils/FindCommonParentForMultipleFilesReturnsCorrectResult.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fs = require('fs'); | ||
|
||
import { findCommonParent } from '../../../utils'; | ||
import { assertByExitCode } from '../TestHelpers'; | ||
|
||
fs.lstatSync = (s: string) => { | ||
const stat = {} as fs.Stats; | ||
stat.isFile = () => s.endsWith('.so'); | ||
stat.isSymbolicLink = () => false; | ||
return stat; | ||
} | ||
const expectedParentPath = "/a/b"; | ||
const actualParentPath = findCommonParent(["/a/b/c/x", "/a/b/c/y", "/a/b/d/z"]); | ||
assertByExitCode.equal(actualParentPath, expectedParentPath); |
14 changes: 14 additions & 0 deletions
14
...ibuteV3/Tests/UnitTests/Utils/FindCommonParentForSingleDirectoryReturnsDirectoryItself.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fs = require('fs'); | ||
|
||
import { findCommonParent } from '../../../utils'; | ||
import { assertByExitCode } from '../TestHelpers'; | ||
|
||
fs.lstatSync = (s: string) => { | ||
const stat = {} as fs.Stats; | ||
stat.isFile = () => s.endsWith('.so'); | ||
stat.isSymbolicLink = () => false; | ||
return stat; | ||
} | ||
const expectedParentPath = "/a/b/c"; | ||
const actualParentPath = findCommonParent(["/a/b/c"]); | ||
assertByExitCode.equal(actualParentPath, expectedParentPath); |
14 changes: 14 additions & 0 deletions
14
...ributeV3/Tests/UnitTests/Utils/FindCommonParentForSingleFileReturnsContainingDirectory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fs = require('fs'); | ||
|
||
import { findCommonParent } from '../../../utils'; | ||
import { assertByExitCode } from '../TestHelpers'; | ||
|
||
fs.lstatSync = (s: string) => { | ||
const stat = {} as fs.Stats; | ||
stat.isFile = () => s.endsWith('.so'); | ||
return stat; | ||
} | ||
const singleSoFilePath = "/a/b/c/symbol.so"; | ||
const expectedParentPath = "/a/b/c"; | ||
const actualParentPath = findCommonParent([singleSoFilePath]); | ||
assertByExitCode.equal(actualParentPath, expectedParentPath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters