Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
variety
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
variety
Commits
51a6994a
Commit
51a6994a
authored
Nov 13, 2014
by
Tomas Dvorak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Output valid JSON results
parent
5e9035c1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
16 deletions
+10
-16
OutputFormatTest.java
...c/test/java/com/github/variety/test/OutputFormatTest.java
+9
-13
variety.js
variety.js
+1
-3
No files found.
test/src/test/java/com/github/variety/test/OutputFormatTest.java
View file @
51a6994a
...
@@ -2,7 +2,7 @@ package com.github.variety.test;
...
@@ -2,7 +2,7 @@ package com.github.variety.test;
import
com.github.variety.Variety
;
import
com.github.variety.Variety
;
import
com.github.variety.VarietyAnalysis
;
import
com.github.variety.VarietyAnalysis
;
import
com.mongodb.
DBObjec
t
;
import
com.mongodb.
BasicDBLis
t
;
import
com.mongodb.util.JSON
;
import
com.mongodb.util.JSON
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Assert
;
...
@@ -30,20 +30,16 @@ public class OutputFormatTest {
...
@@ -30,20 +30,16 @@ public class OutputFormatTest {
@Test
@Test
public
void
verifyJsonEntries
()
throws
Exception
{
public
void
verifyJsonEntries
()
throws
Exception
{
final
VarietyAnalysis
analysis
=
variety
.
withFormat
(
Variety
.
FORMAT_JSON
).
runAnalysis
();
final
VarietyAnalysis
analysis
=
variety
.
withQuiet
(
true
)
// do not output any other metadata, only results
.
withFormat
(
Variety
.
FORMAT_JSON
)
.
runAnalysis
();
// TODO: output itself is not valid JSON. It contains mongo shell output (can be removed with --quiet) and variety execution info.
// Verify, that output is parse-able json by transforming stdout to json
// At the end of output, there are printed records from result collection, every record on new line.
final
BasicDBList
parsed
=
(
BasicDBList
)
JSON
.
parse
(
analysis
.
getStdOut
());
// Valid json output is requested in issue https://github.com/variety/variety/issues/23
// Verify, that every object is parse-able json by transforming strings to json stream
// there should be seven different json results
// Results are detected by line starting with character '{'.
Assert
.
assertEquals
(
7
,
parsed
.
size
());
final
Stream
<
DBObject
>
objects
=
Stream
.
of
(
analysis
.
getStdOut
().
split
(
"\n"
))
.
filter
(
line
->
line
.
startsWith
(
"{"
))
.
map
(
str
->
(
DBObject
)
JSON
.
parse
(
str
));
// there should be seven different json results in the stdout
Assert
.
assertEquals
(
7
,
objects
.
count
());
}
}
@Test
@Test
...
...
variety.js
View file @
51a6994a
...
@@ -227,9 +227,7 @@ resultsDB[resultsCollectionName].find({}).forEach(function(key) {
...
@@ -227,9 +227,7 @@ resultsDB[resultsCollectionName].find({}).forEach(function(key) {
var
sortedKeys
=
resultsDB
[
resultsCollectionName
].
find
({}).
sort
({
totalOccurrences
:
-
1
});
var
sortedKeys
=
resultsDB
[
resultsCollectionName
].
find
({}).
sort
({
totalOccurrences
:
-
1
});
if
(
outputFormat
===
'json'
)
{
if
(
outputFormat
===
'json'
)
{
sortedKeys
.
forEach
(
function
(
key
)
{
printjson
(
sortedKeys
.
toArray
());
// valid formatted json output, compressed variant is printjsononeline()
print
(
tojson
(
key
,
''
,
true
));
});
}
else
{
// output nice ascii table with results
}
else
{
// output nice ascii table with results
var
table
=
[[
"key"
,
"types"
,
"occurrences"
,
"percents"
],
[
""
,
""
,
""
,
""
]];
// header + delimiter rows
var
table
=
[[
"key"
,
"types"
,
"occurrences"
,
"percents"
],
[
""
,
""
,
""
,
""
]];
// header + delimiter rows
sortedKeys
.
forEach
(
function
(
key
)
{
sortedKeys
.
forEach
(
function
(
key
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment